From bd180c2dd92351c9e4c6196d4d641deb25dd3b07 Mon Sep 17 00:00:00 2001 From: D Chua Date: Thu, 6 Jun 2024 11:59:08 +0100 Subject: [PATCH 1/2] Add GitHub Action workflow for verifying pact tests This workflow will also be called by gds-api-adapters as part of it's CI build to test that pacts are valid against this app. --- .github/workflows/ci.yml | 6 +++ .github/workflows/pact-verify.yml | 71 +++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .github/workflows/pact-verify.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41815820..73055ec4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,3 +64,9 @@ jobs: RAILS_ENV: test TEST_DATABASE_URL: ${{ steps.setup-postgres.outputs.db-url }} run: bundle exec rake spec + + pact-tests: + name: Run Pact tests + uses: ./.github/workflows/pact-verify.yml + with: + ref: ${{ github.ref }} diff --git a/.github/workflows/pact-verify.yml b/.github/workflows/pact-verify.yml new file mode 100644 index 00000000..8b838ccb --- /dev/null +++ b/.github/workflows/pact-verify.yml @@ -0,0 +1,71 @@ +# Pact verify workflow +# +# This workflow asserts that Pact contract tests are valid against this +# codebase. It is trigged when changes are made to this project and it +# is explicitly called by GDS API Adapters when changes are made there. + +name: Run Pact tests + +on: + workflow_call: + inputs: + # The commit / tag of this repo to test against + ref: + required: false + type: string + default: main + # A GitHub Action artifact which contains the pact definition files + # Support API calls this action to test new pacts against this + # workflow + pact_artifact: + required: false + type: string + # When using an artifact this is the file path to the pact that is verified + # against + pact_artifact_file_to_verify: + required: false + type: string + default: gds_api_adapters-support_api.json + # Which version of the pacts to use from the Pact Broker service + # This option will be ignored if pact_artifact is set + pact_consumer_version: + required: false + type: string + default: branch-main + +jobs: + pact_verify: + name: Verify pact tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:13 + ports: ["5432:5432"] + env: + POSTGRES_HOST_AUTH_METHOD: trust + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + env: + TEST_DATABASE_URL: postgresql://postgres@localhost/test-db + RAILS_ENV: test + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: alphagov/support-api + ref: ${{ inputs.ref }} + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - run: bundle exec rails db:setup + - if: inputs.pact_artifact == '' + run: bundle exec rake pact:verify + env: + PACT_CONSUMER_VERSION: ${{ inputs.pact_consumer_version }} + - if: inputs.pact_artifact != '' + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.pact_artifact }} + path: tmp/pacts + - if: inputs.pact_artifact != '' + run: bundle exec rake pact:verify:at[tmp/pacts/${{ inputs.pact_artifact_file_to_verify }} From 1f64ed1d2cc5630dd8007268451ff500b10dc02e Mon Sep 17 00:00:00 2001 From: D Chua Date: Thu, 6 Jun 2024 16:33:10 +0100 Subject: [PATCH 2/2] Fix provider Pact test The parameters are already valid so we only need to stub the response from the Zendesk API call. --- spec/service_consumers/pact_helper.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spec/service_consumers/pact_helper.rb b/spec/service_consumers/pact_helper.rb index d8f574c1..66386097 100644 --- a/spec/service_consumers/pact_helper.rb +++ b/spec/service_consumers/pact_helper.rb @@ -33,13 +33,7 @@ def url_encode(str) Pact.provider_states_for "GDS API Adapters" do provider_state "the parameters are valid" do set_up do - params = { - subject: "Feedback for app", - tags: %w[app_name], - user_agent: "Safari", - description: "There is something wrong with this page.", - } - SupportTicket.new(params) + stub_request(:post, "https://govuk.zendesk.com/api/v2/tickets").to_return(status: 210, body: { "status" => "success" }.to_json, headers: { "Content-Type" => "application/json" }) end end