Skip to content

Commit

Permalink
Merge pull request #5 from pagopa/PPANTT-197-e-bollo-2-0-integration-…
Browse files Browse the repository at this point in the history
…test-mdb-gps

[PPANTT-197] feat: Add integration test
  • Loading branch information
pasqualespica authored Dec 10, 2024
2 parents d71d9a0 + 538a237 commit 9ddfb0f
Show file tree
Hide file tree
Showing 29 changed files with 280 additions and 258 deletions.
43 changes: 36 additions & 7 deletions .github/workflows/ci_code_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,41 @@ jobs:
with:
tool_name: junit

smoke_test:
smoke-test:
name: Smoke Test
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
uses: ./.github/workflows/ci_integration_test.yml
with:
environment: 'local'
notify: false
secrets: inherit
runs-on: ubuntu-latest
environment:
name: dev
steps:
- name: Checkout
id: checkout
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707

- name: Login
id: login
# from https://github.com/Azure/login/commits/master
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
with:
client-id: ${{ secrets.CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}

- name: Run Service on Docker
shell: bash
id: run_service_docker
run: |
cd ./docker
chmod +x ./run_docker.sh
./run_docker.sh local
- name: Run Integration Tests
shell: bash
id: run_integration_test
run: |
export CUCUMBER_PUBLISH_TOKEN=${{ secrets.CUCUMBER_PUBLISH_TOKEN }}
export SUBKEY=${{ secrets.SUBKEY }}
cd ./integration-test
chmod +x ./run_integration_test.sh
./run_integration_test.sh local
77 changes: 10 additions & 67 deletions .github/workflows/ci_integration_test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
name: Integration Tests

on:
# schedule:
# - cron: '00 08 * * 1-5'

workflow_call:
inputs:
environment:
required: true
type: string
description: Select the Environment
canary:
description: 'run the tests on canary version'
required: false
type: boolean
default: false
notify:
description: 'notify result with slack message'
required: false
type: boolean
default: true

schedule:
- cron: "00 08 * * *"

workflow_dispatch:
inputs:
Expand All @@ -29,16 +11,15 @@ on:
type: choice
description: Select the Environment
options:
- local
- dev
- uat
canary:
description: 'run the tests on canary version'
description: "run the tests on canary version"
required: false
type: boolean
default: false
notify:
description: 'notify result with slack message'
description: "notify result with slack message"
required: false
type: boolean
default: false
Expand All @@ -48,9 +29,7 @@ permissions:
contents: read
deployments: write


jobs:

integration_test:
name: Test ${{(github.event.inputs == null && 'dev') || inputs.environment }}
runs-on: ubuntu-latest
Expand All @@ -59,40 +38,6 @@ jobs:
id: checkout
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707

- name: setup
id: setup
run: |
echo "CLIENT_ID=${{secrets.DEV_CLIENT_ID}}" >> $GITHUB_ENV
echo "TENANT_ID=${{secrets.DEV_TENANT_ID}}" >> $GITHUB_ENV
echo "SUBSCRIPTION_ID=${{secrets.DEV_SUBSCRIPTION_ID}}" >> $GITHUB_ENV
echo "SUBKEY=${{secrets.DEV_SUBKEY}}" >> $GITHUB_ENV
if [[ ${{ inputs.environment }} == "uat" ]]; then
echo "CLIENT_ID=${{secrets.UAT_CLIENT_ID}}" >> $GITHUB_ENV
echo "TENANT_ID=${{secrets.UAT_TENANT_ID}}" >> $GITHUB_ENV
echo "SUBSCRIPTION_ID=${{secrets.UAT_SUBSCRIPTION_ID}}" >> $GITHUB_ENV
echo "SUBKEY=${{secrets.UAT_SUBKEY}}" >> $GITHUB_ENV
fi
- name: Login
id: login
# from https://github.com/Azure/login/commits/master
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
with:
client-id: ${{ env.CLIENT_ID }}
tenant-id: ${{ env.TENANT_ID }}
subscription-id: ${{ env.SUBSCRIPTION_ID }}


- name: Run Service on Docker
shell: bash
id: run_service_docker
run: |
cd ./docker
chmod +x ./run_docker.sh
./run_docker.sh ${{ inputs.environment }}

- name: Run Integration Tests
shell: bash
run: |
Expand All @@ -105,21 +50,19 @@ jobs:
./run_integration_test.sh ${{( github.event.inputs == null && 'dev') || inputs.environment }}
notify:
needs: [ integration_test ]
needs: [integration_test]
runs-on: ubuntu-latest
name: Notify
if: ${{ always() && inputs.notify == 'true' }}
if: ${{ always() && (inputs == null || inputs.notify == 'true') }}
steps:
- name: Report Status
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v2
with:
status: ${{ needs.integration_test.result }}
token: ${{ secrets.GITHUB_TOKEN }}
notify_when: 'failure,skipped'
notification_title: 'Integration Tests Result'
message_format: '{emoji} <{run_url}|{workflow}> {status_message} in <{repo_url}|{repo}> in ${{ inputs.environment }}'
footer: 'Linked to <{workflow_url}| workflow file>'
notify_when: "failure,skipped"
notification_title: "Integration Tests Result"
message_format: "{emoji} <{run_url}|{workflow}> {status_message} in <{repo_url}|{repo}> in ${{ inputs.environment }}"
footer: "Linked to <{workflow_url}| workflow file>"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_TEST }}


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ hs_err_pid*
# Helm
/helm/charts/*
**/.terraform/

# Integration tests
*.lock
4 changes: 2 additions & 2 deletions .identity/00_data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ data "azurerm_key_vault_secret" "key_vault_cucumber_token" {
}

data "azurerm_key_vault_secret" "key_vault_integration_test_subkey" {
name = "integration-test-subkey"
key_vault_id = data.azurerm_key_vault.key_vault.id
name = "apikey-gps-mbd-integration-test"
key_vault_id = data.azurerm_key_vault.domain_key_vault.id
}

data "azurerm_user_assigned_identity" "workload_identity_clientid" {
Expand Down
2 changes: 1 addition & 1 deletion .terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.6
1.8.3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ To run the **Junit** tests:
From `./integration-test/src`

1. `yarn install`
2. `yarn test`
2. `yarn test:<env>`

#### Performance testing

Expand Down
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: pagopa-afm-calculator
description: Microservice that handles calculation for pagoPA Advanced Fees Management
name: pagopa-gps-mbd-service
description: Microservice that handles payment option generation for MBD
type: application
version: 0.3.0
appVersion: 1.0.2
Expand Down
1 change: 1 addition & 0 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ microservice-chart:
APP_LOGGING_LEVEL: "INFO"
DEFAULT_LOGGING_LEVEL: "INFO"
CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}'
OTEL_SERVICE_NAME: "pagopa-gps-mbd-service"
MBD_PAYMENT_OPTION_DESCRIPTION: "Pagamento marca da bollo digitale"
MBD_PAYMENT_OPTION_DUE_DATE_DELTA: "20"
MBD_PAYMENT_OPTION_DUE_DATE_TIME_UNIT: "Minutes"
Expand Down
1 change: 1 addition & 0 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ microservice-chart:
APP_LOGGING_LEVEL: "INFO"
DEFAULT_LOGGING_LEVEL: "INFO"
CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}'
OTEL_SERVICE_NAME: "pagopa-gps-mbd-service"
MBD_PAYMENT_OPTION_DESCRIPTION: "Pagamento marca da bollo digitale"
MBD_PAYMENT_OPTION_DUE_DATE_DELTA: "20"
MBD_PAYMENT_OPTION_DUE_DATE_TIME_UNIT: "Minutes"
Expand Down
1 change: 1 addition & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ microservice-chart:
APP_LOGGING_LEVEL: "INFO"
DEFAULT_LOGGING_LEVEL: "INFO"
CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}'
OTEL_SERVICE_NAME: "pagopa-gps-mbd-service"
MBD_PAYMENT_OPTION_DESCRIPTION: "Pagamento marca da bollo digitale"
MBD_PAYMENT_OPTION_DUE_DATE_DELTA: "20"
MBD_PAYMENT_OPTION_DUE_DATE_TIME_UNIT: "Minutes"
Expand Down
7 changes: 1 addition & 6 deletions integration-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ To run the integration tests on docker, you can run from this directory the scri
``` shell
sh ./run_integration_test.sh <local|dev|uat|prod> <sub-key>
```

ℹ️ _Note_: for **PagoPa ACR** is **required** the login `az acr login -n <acr-name>`

If you use dev, uat or prod **you test the images on Azure ACR**

---
💻 If you want to test your local branch,

``` shell
sh ./run_integration_test.sh local SUBSCRIPTION-KEY
sh ./run_integration_test.sh local SUBKEY
```

4 changes: 3 additions & 1 deletion integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
APP_HOST=https://host
GPS_MBD_HOST=https://api.dev.platform.pagopa.it/pagopa-gps-mbd-service/v1
MBD_PO_DESCRIPTION="Pagamento marca da bollo digitale"
MBD_TRANSFER_REMITTANCE_INFORMATION="Pagamento marca da bollo digitale"
4 changes: 3 additions & 1 deletion integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
APP_HOST=http://localhost:8080
GPS_MBD_HOST=http://localhost:8080
MBD_PO_DESCRIPTION="Pagamento marca da bollo digitale"
MBD_TRANSFER_REMITTANCE_INFORMATION="Pagamento marca da bollo digitale"
1 change: 0 additions & 1 deletion integration-test/src/config/.env.prod

This file was deleted.

4 changes: 3 additions & 1 deletion integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
APP_HOST=https://host
GPS_MBD_HOST=https://api.uat.platform.pagopa.it/pagopa-gps-mbd-service/v1
MBD_PO_DESCRIPTION="Pagamento marca da bollo digitale"
MBD_TRANSFER_REMITTANCE_INFORMATION="Pagamento marca da bollo digitale"
16 changes: 0 additions & 16 deletions integration-test/src/features/example.feature

This file was deleted.

38 changes: 38 additions & 0 deletions integration-test/src/features/gps_mbd_service.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: All about MBD payment option build request handled by pagopa-gps-mbd-service

Scenario: successful build payment option request
When an http POST request is sent to gps-mbd-service with valid request body
Then the statusCode is 200
And the response body has the expected values

Scenario: fail build payment option request for null amount
When an http POST request is sent to gps-mbd-service with invalid 'amount' request body
Then the statusCode is 400

Scenario: fail build payment option request for null debtor name
When an http POST request is sent to gps-mbd-service with invalid 'debtorName' request body
Then the statusCode is 400

Scenario: fail build payment option request for null debtor surname
When an http POST request is sent to gps-mbd-service with invalid 'debtorSurname' request body
Then the statusCode is 400

Scenario: fail build payment option request for null debtor fiscal code
When an http POST request is sent to gps-mbd-service with invalid 'debtorFiscalCode' request body
Then the statusCode is 400

Scenario: fail build payment option request for null debtor email
When an http POST request is sent to gps-mbd-service with invalid 'debtorEmail' request body
Then the statusCode is 400

Scenario: fail build payment option request for empty CI fiscal code
When an http POST request is sent to gps-mbd-service with invalid 'ciFiscalCode' request body
Then the statusCode is 400

Scenario: fail build payment option request for empty debtor residence province
When an http POST request is sent to gps-mbd-service with invalid 'debtorProvince' request body
Then the statusCode is 400

Scenario: fail build payment option request for document hash too short
When an http POST request is sent to gps-mbd-service with invalid 'documentHash' request body
Then the statusCode is 400
2 changes: 1 addition & 1 deletion integration-test/src/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "your-project-name", // TODO: set your name
"name": "pagopa-gps-mbd-service",
"license": "MIT",
"version": "1.0.0",
"scripts": {
Expand Down
59 changes: 59 additions & 0 deletions integration-test/src/step_definitions/gps-mbs-service_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { After, When, Then } = require('@cucumber/cucumber')
const assert = require("assert");
const { post } = require("./support/common");
const { buildRequestBody } = require("./support/util");

const gpsMbdServiceHost = process.env.GPS_MBD_HOST;
const poDescription = process.env.MBD_PO_DESCRIPTION;
const transferRemittanceInformation = process.env.MBD_TRANSFER_REMITTANCE_INFORMATION;

let body = null;
let responseToCheck = null;

After(async function () {
body = null;
responseToCheck = null;
});

When('an http POST request is sent to gps-mbd-service with valid request body', async () => {
body = buildRequestBody(16, "00000000000", "PR", "1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB");
responseToCheck = await post(gpsMbdServiceHost + "/mbd/paymentOption", body);
});

Then('the statusCode is {int}', function (statusCode) {
assert.strictEqual(responseToCheck.status, statusCode);
});

Then('the response body has the expected values', function () {
assert.strictEqual(responseToCheck.data.paymentOption.length, 1);
assert.strictEqual(responseToCheck.data.paymentOption[0].amount, body.properties.amount);
assert.strictEqual(responseToCheck.data.paymentOption[0].description, poDescription);
assert.notStrictEqual(responseToCheck.data.paymentOption[0].dueDate, undefined);
assert.notStrictEqual(responseToCheck.data.paymentOption[0].retentionDate, undefined);
assert.strictEqual(responseToCheck.data.paymentOption[0].isPartialPayment, false);
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer.length, 1);
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].organizationFiscalCode, body.properties.ciFiscalCode);
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].idTransfer, "1");
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].amount, body.properties.amount);
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].remittanceInformation, transferRemittanceInformation);
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].stamp.hashDocument, body.properties.documentHash);
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].stamp.stampType, "st");
assert.strictEqual(responseToCheck.data.paymentOption[0].transfer[0].stamp.provincialResidence, body.properties.debtorProvince);
});

When('an http POST request is sent to gps-mbd-service with invalid {string} request body', async (invalidParam) => {
body = buildRequestBody(16, "00000000000", "PR", "1trA5qyjSZNwiwtGG46dyjRpL16TFgGCFvnfFzQrFHbB");

switch (invalidParam) {
case "amount": body.properties.amount = null; break;
case "debtorName": body.properties.debtorName = ""; break;
case "debtorSurname": body.properties.debtorSurname = ""; break;
case "debtorEmail": body.properties.debtorEmail = ""; break;
case "debtorFiscalCode": body.properties.debtorFiscalCode = ""; break;
case "ciFiscalCode": body.properties.ciFiscalCode = ""; break;
case "debtorProvince": body.properties.debtorProvince = ""; break;
case "documentHash": body.properties.documentHash = "tooShortHash"; break;
}

responseToCheck = await post(gpsMbdServiceHost + "/mbd/paymentOption", body);
})
Loading

0 comments on commit 9ddfb0f

Please sign in to comment.