From a057427cd39ac980972b07703783a7e221127c31 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 4 Oct 2019 09:18:42 +1000 Subject: [PATCH] feat: add missing HAL docs for various relations and correct test that should have identified their absence --- lib/pact_broker/doc/views/can-i-deploy.markdown | 14 ++++++++++++++ .../views/index/pacticipant-version-tag.markdown | 8 ++++++++ lib/pact_broker/doc/views/matrix.markdown | 7 +++++++ lib/pact_broker/doc/views/metrics.markdown | 5 +++++ spec/lib/pact_broker/doc/coverage_spec.rb | 10 ++++++++-- 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 lib/pact_broker/doc/views/can-i-deploy.markdown create mode 100644 lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown create mode 100644 lib/pact_broker/doc/views/matrix.markdown create mode 100644 lib/pact_broker/doc/views/metrics.markdown diff --git a/lib/pact_broker/doc/views/can-i-deploy.markdown b/lib/pact_broker/doc/views/can-i-deploy.markdown new file mode 100644 index 000000000..87be6b93c --- /dev/null +++ b/lib/pact_broker/doc/views/can-i-deploy.markdown @@ -0,0 +1,14 @@ +# Can I Deploy + +Allowed methods: `GET` + +A simplified resource that accepts the same parameters as the basic usage of the `can-i-deploy` CLI command. + +**Parameters**: + +* _pacticipant_: The name of the pacticipant (application) you want to deploy (required). +* _version_: The version of the pacticipant (application) you want to deploy (required). +* _to_: The tag used to identify the environment into which you wish to deploy the application (eg. `test` or `prod`). This assumes you have already tagged the currently deployed versions of each of the integrated applications with the same tag. To be specific, the logic checks if the application version you have specified is compatible with the latest versions _for the specified tag_ of all the other applications it is integrated with. This parameter is optional - if not specified, it checks for compatiblity with the latest version of all the integrated applications. + + +If you have an environment that you identify with the tag `prod`, and each time you deployed an application to the prod environment you tagged the relevant application version in the Pact Broker with the tag `prod`, then calling `/can-i-deploy?pacticipant=Foo&version=734137278d&to=prod` will check that version 734137278d of Foo has a successful verification result with each of the integrated application versions that are currently in prod. That is, it is safe to deploy. diff --git a/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown b/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown new file mode 100644 index 000000000..1910ec052 --- /dev/null +++ b/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown @@ -0,0 +1,8 @@ +# Pacticipant version tag + +Allowed methods: `GET`, `PUT`, `DELETE` +Path: `/pacticipants/{pacticipant}/versions/{version}/tags/{tag}` + +To create a tag, send an empty request with the URL specified above and `Content-Type` of `application/json`. + +Tags must be applied before pacts or verification results are published to ensure that the webhook fires with the correct metadata. diff --git a/lib/pact_broker/doc/views/matrix.markdown b/lib/pact_broker/doc/views/matrix.markdown new file mode 100644 index 000000000..fc503ad4e --- /dev/null +++ b/lib/pact_broker/doc/views/matrix.markdown @@ -0,0 +1,7 @@ +# Matrix + +Allowed methods: `GET` + +This resource returns the "cartesian join" of every pact publication and every verification results publication, and is used to determine whether or not an application is safe to deploy. + +If you need to use this API, consider calling the `/can-i-deploy` resource instead. diff --git a/lib/pact_broker/doc/views/metrics.markdown b/lib/pact_broker/doc/views/metrics.markdown new file mode 100644 index 000000000..2839676ce --- /dev/null +++ b/lib/pact_broker/doc/views/metrics.markdown @@ -0,0 +1,5 @@ +# Metrics + +Allowed methods: `GET` + +Returns counts for the Pact Broker resources. diff --git a/spec/lib/pact_broker/doc/coverage_spec.rb b/spec/lib/pact_broker/doc/coverage_spec.rb index f6c17038d..feaddba84 100644 --- a/spec/lib/pact_broker/doc/coverage_spec.rb +++ b/spec/lib/pact_broker/doc/coverage_spec.rb @@ -15,15 +15,21 @@ let(:index_response) { get "/", {}, { 'HTTP_ACCEPT' => 'application/hal+json' } } let(:index_body) { JSON.parse(index_response.body) } + let(:docs_missing_string) { "No documentation exists"} + + it "returns a known message when the documentation doesn't exist" do + get "/docs/does-not-exist?context=index", {}, { 'HTTP_ACCEPT' => 'text/html' } + expect(last_response.body).to include docs_missing_string + end it "has a document for each relation" do - relations_that_should_have_docs = index_body['_links'].keys - ['self', 'curies'] + relations_that_should_have_docs = index_body['_links'].keys - ['self', 'curies', 'beta:provider-pacts-for-verification'] relations_without_docs = {} relations_that_should_have_docs.each do | relation | path = "/docs/#{relation.split(":", 2).last}?context=index" get path, {}, { 'HTTP_ACCEPT' => 'text/html' } - if last_response.status != 200 + if last_response.body.include?(docs_missing_string) relations_without_docs[relation] = last_response.status end end