Skip to content

Commit

Permalink
feat: Migrate integration test
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea De Rinaldis <andrea-deri@users.noreply.github.com>
  • Loading branch information
cap-ang and andrea-deri committed May 3, 2023
1 parent 0e71e69 commit 1a2370b
Show file tree
Hide file tree
Showing 26 changed files with 1,636 additions and 15 deletions.
85 changes: 70 additions & 15 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ parameters:
- buildNumber
- skip
default: skip
- name: TEST
displayName: Run tests
type: boolean
default: false
- name: "FORCE_REPLACE_DOCKER_IMAGE"
displayName: "Force the existing docker image to be replaced"
type: boolean
default: False
values:
- False
- True
- name: INTEGRATION_TEST
displayName: Run integration tests
type: boolean
default: true

variables:
imageRepository: '$(IMAGE_REPOSITORY_NAME)'
Expand All @@ -38,24 +38,38 @@ variables:
NODO_HOST: "https://api.dev.platform.pagopa.it/nodo/nodo-per-pa/v1/"
STAGE: "d"
RESOURCE_GROUP: 'pagopa-d-weu-gps-gpd-rg'
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY_SERVICE_CONN)
dockerNamespace: $(DEV_CONTAINER_NAMESPACE)
DOCKER_REGISTRY_SERVICE_CONNECTION: $(DEV_CONTAINER_REGISTRY_SERVICE_CONN)
DOCKER_NAMESPACE: $(DEV_CONTAINER_NAMESPACE)
POOL_IMAGE_TEST: "pagopa-dev-loadtest-linux"
API_CONFIG_SUBSCRIPTION_KEY: $(DEV_API_CONFIG_SUBSCRIPTION_KEY)
GPD_SUBSCRIPTION_KEY: $(DEV_GPD_SUBSCRIPTION_KEY)
PAYMENTS_REST_SUBSCRIPTION_KEY: $(DEV_PAYMENTS_REST_SUBSCRIPTION_KEY)
PAYMENTS_SOAP_SUBSCRIPTION_KEY: $(DEV_PAYMENTS_SOAP_SUBSCRIPTION_KEY)
REPORTING_SUBSCRIPTION_KEY: $(DEV_REPORTING_SUBSCRIPTION_KEY)
REPORTING_BATCH_CONNECTION_STRING: $(DEV_REPORTING_BATCH_CONNECTION_STRING)
${{ if eq(parameters['ENV'], 'uat') }}:
AZURE_SUBSCRIPTION: $(UAT_AZURE_SUBSCRIPTION)
APP_NAME: $(UAT_WEB_APP_NAME)
NODO_HOST: "https://api.uat.platform.pagopa.it/nodo/nodo-per-pa/v1/"
STAGE: "u"
RESOURCE_GROUP: 'pagopa-u-weu-gps-gpd-rg'
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY_SERVICE_CONN)
dockerNamespace: $(UAT_CONTAINER_NAMESPACE)
DOCKER_REGISTRY_SERVICE_CONNECTION: $(UAT_CONTAINER_REGISTRY_SERVICE_CONN)
DOCKER_NAMESPACE: $(UAT_CONTAINER_NAMESPACE)
POOL_IMAGE_TEST: "pagopa-uat-loadtest-linux"
API_CONFIG_SUBSCRIPTION_KEY: $(UAT_API_CONFIG_SUBSCRIPTION_KEY)
GPD_SUBSCRIPTION_KEY: $(UAT_GPD_SUBSCRIPTION_KEY)
PAYMENTS_REST_SUBSCRIPTION_KEY: $(UAT_PAYMENTS_REST_SUBSCRIPTION_KEY)
PAYMENTS_SOAP_SUBSCRIPTION_KEY: $(UAT_PAYMENTS_SOAP_SUBSCRIPTION_KEY)
REPORTING_SUBSCRIPTION_KEY: $(UAT_REPORTING_SUBSCRIPTION_KEY)
REPORTING_BATCH_CONNECTION_STRING: $(UAT_REPORTING_BATCH_CONNECTION_STRING)
${{ if eq(parameters['ENV'], 'prod') }}:
AZURE_SUBSCRIPTION: $(PROD_AZURE_SUBSCRIPTION)
APP_NAME: $(PROD_WEB_APP_NAME)
NODO_HOST: "https://api.platform.pagopa.it/nodo/nodo-per-pa/v1/"
STAGE: "p"
RESOURCE_GROUP: 'pagopa-p-weu-gps-gpd-rg'
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY_SERVICE_CONN)
dockerNamespace: $(PROD_CONTAINER_NAMESPACE)
DOCKER_REGISTRY_SERVICE_CONNECTION: $(PROD_CONTAINER_REGISTRY_SERVICE_CONN)
DOCKER_NAMESPACE: $(PROD_CONTAINER_NAMESPACE)

${{ if eq(variables['Build.SourceBranchName'], 'merge') }}:
SOURCE_BRANCH: "main" # force to main branch
Expand Down Expand Up @@ -136,8 +150,8 @@ stages:

- template: templates/docker-release/template.yaml@pagopaCommons
parameters:
CONTAINER_REGISTRY_SERVICE_CONN: $(dockerRegistryServiceConnection)
CONTAINER_REGISTRY_FQDN: $(dockerNamespace)
CONTAINER_REGISTRY_SERVICE_CONN: $(DOCKER_REGISTRY_SERVICE_CONNECTION)
CONTAINER_REGISTRY_FQDN: $(DOCKER_NAMESPACE)
DOCKER_IMAGE_NAME: $(imageRepository)
DOCKER_IMAGE_TAG: $(current_version)
FORCE_REPLACE_DOCKER_IMAGE: ${{ parameters.FORCE_REPLACE_DOCKER_IMAGE }}
Expand All @@ -159,7 +173,7 @@ stages:
inputs:
azureSubscription: $(AZURE_SUBSCRIPTION)
appName: "${{variables.APP_NAME}}-fn-gpd-analysis"
imageName: "${{variables.dockerNamespace}}/${{ variables.imageRepository }}:latest"
imageName: "${{variables.DOCKER_NAMESPACE}}/${{ variables.imageRepository }}:latest"
slotName: production
resourceGroupName: $(RESOURCE_GROUP)
- task: AzureFunctionAppContainer@1
Expand All @@ -168,7 +182,7 @@ stages:
inputs:
azureSubscription: $(AZURE_SUBSCRIPTION)
appName: "${{variables.APP_NAME}}-fn-gpd-analysis"
imageName: "${{variables.dockerNamespace}}/${{ variables.imageRepository }}:latest"
imageName: "${{variables.DOCKER_NAMESPACE}}/${{ variables.imageRepository }}:latest"
deployToSlotOrASE: true
slotName: staging
resourceGroupName: $(RESOURCE_GROUP)
Expand Down Expand Up @@ -205,4 +219,45 @@ stages:
ResourceGroupName: $(RESOURCE_GROUP)
SourceSlot: staging
SwapWithProduction: true
Slot: production
Slot: production

# Run Tests
- stage: Integration_Test
dependsOn:
- Deploy
condition: and(and(succeeded(), eq('${{ parameters.INTEGRATION_TEST }}', 'true')), ne('${{ parameters.ENV }}', 'prod'))
jobs:
- job: integration_tests
pool:
name: $(POOL_IMAGE_TEST)
displayName: "Prepare and run integration tests"
timeoutInMinutes: 0
steps:
- checkout: self
persistCredentials: true

- script: |
git checkout $(SOURCE_BRANCH)
git pull
- task: Docker@2
displayName: "Docker login"
inputs:
containerRegistry: "$(DOCKER_REGISTRY_SERVICE_CONNECTION)"
command: "login"

- task: Bash@3
displayName: "Run Integration Tests"
inputs:
targetType: "inline"
script: |
cd ./integration-test/ && \
sh run_integration_test.sh ${{ parameters.ENV }}
env:
API_CONFIG_SUBSCRIPTION_KEY: $(API_CONFIG_SUBSCRIPTION_KEY)
GPD_SUBSCRIPTION_KEY: $(GPD_SUBSCRIPTION_KEY)
PAYMENTS_REST_SUBSCRIPTION_KEY: $(PAYMENTS_REST_SUBSCRIPTION_KEY)
PAYMENTS_SOAP_SUBSCRIPTION_KEY: $(PAYMENTS_SOAP_SUBSCRIPTION_KEY)
REPORTING_SUBSCRIPTION_KEY: $(REPORTING_SUBSCRIPTION_KEY)
REPORTING_BATCH_CONNECTION_STRING: $(REPORTING_BATCH_CONNECTION_STRING)
CONTAINER_REGISTRY: $(DOCKER_NAMESPACE)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target/

# Log file
*.log
**/yarn.lock

# BlueJ files
*.ctxt
Expand Down
37 changes: 37 additions & 0 deletions integration-test/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Integration Tests
👀 Integration tests are in `integration-test/src/` folder. See there for more information.

## How run in local environment

To run the integration test from local environment, simply execute this commands:
```
export API_CONFIG_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \
export GPD_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \
export PAYMENTS_REST_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \
export PAYMENTS_SOAP_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \
export REPORTING_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \
export REPORTING_BATCH_CONNECTION_STRING=##QUEUE_CONNECTION_STRING## \
yarn install && \
yarn test:${{ parameters.ENV }}
```

## How run on Docker 🐳

To run the integration tests on docker, you can run from this directory the script:


``` shell
sh ./run_integration_test.sh <local|dev|uat|prod> <api-subscription-key> <apiconfig_subkey> <gpd_subkey> <gps_spontaneouspayments_subkey> <gps_donations_subkey> <payments_subkey>
```


ℹ️ _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 <api-subscription-key> <apiconfig_subkey> <gpd_subkey> <gps_spontaneouspayments_subkey> <gps_donations_subkey> <payments_subkey>
```

25 changes: 25 additions & 0 deletions integration-test/run_integration_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# example: sh ./run_integration_test.sh <smoke|integration> <local|dev|uat|prod>
environment=$1
containerName="node-container"

docker stop node-container || true
docker rm node-container || true

# please see https://github.com/andrea-deri/prebuilt-img-yarn-base for yarn-testing-base image content
docker pull ${CONTAINER_REGISTRY}/yarn-testing-base:latest
docker run -dit --name ${containerName} ${CONTAINER_REGISTRY}/yarn-testing-base:latest

# run integration tests with yarn
docker cp -a ./src/. ${containerName}:/test
docker exec -i ${containerName} /bin/bash -c " \
cd ./test
export API_CONFIG_SUBSCRIPTION_KEY=${API_CONFIG_SUBSCRIPTION_KEY} \
export GPD_SUBSCRIPTION_KEY=${GPD_SUBSCRIPTION_KEY} \
export PAYMENTS_REST_SUBSCRIPTION_KEY=${PAYMENTS_REST_SUBSCRIPTION_KEY} \
export PAYMENTS_SOAP_SUBSCRIPTION_KEY=${PAYMENTS_SOAP_SUBSCRIPTION_KEY} \
export REPORTING_SUBSCRIPTION_KEY=${REPORTING_SUBSCRIPTION_KEY} \
export REPORTING_BATCH_CONNECTION_STRING=${REPORTING_BATCH_CONNECTION_STRING}
yarn test:${environment}"

# clean up container
docker stop ${containerName} && docker rm ${containerName}
17 changes: 17 additions & 0 deletions integration-test/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Integration Test with Cucumber

## Technology Stack

- [cucumber js](https://github.com/cucumber/cucumber-js)
- NodeJS v14.17.6

## How to start

- install dependencies: `yarn install`
- run tests: `yarn test:ENV` in `src` folder

### Note
Before run the test, set a variable `SUBCRIPTION_KEY` in your environment.

You can configure the endpoints with `./config/env.ENV` file.

17 changes: 17 additions & 0 deletions integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Host addresses
host_header=api.dev.platform.pagopa.it
api_config_host=https://api.dev.platform.pagopa.it/apiconfig/auth/api/v1
gpd_host=https://api.dev.platform.pagopa.it/gpd/api/v1
reporting_analysis_host=https://api.dev.platform.pagopa.it/gpd-reporting/api/v1
payments_soap_host=https://api.dev.platform.pagopa.it/gpd-payments/api/v1
payments_rest_host=https://api.dev.platform.pagopa.it/gpd/payments-receipts-service/v1
nodo_host=https://api.dev.platform.pagopa.it/nodo

# Data and setting configuration
creditor_institution_id=77777777777
broker_id=15376371009
station_id=15376371009_01
psp_id=60000000001
channel_id=60000000001_01
reporting_batch_wait_execution_sec=120
include_debug_logs=true
17 changes: 17 additions & 0 deletions integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Host addresses
host_header=api.dev.platform.pagopa.it
api_config_host=https://api.dev.platform.pagopa.it/apiconfig/auth/api/v1
gpd_host=https://localhost:8080/gpd/api/v1 # TODO to be changed, only a placeholder
reporting_analysis_host=https://localhost:8080/gpd-reporting/api/v1 # TODO to be changed, only a placeholder
payments_soap_host=https://api.dev.platform.pagopa.it/gpd-payments/api/v1
payments_rest_host=https://api.dev.platform.pagopa.it/gpd-payment-receipts/api/v1
nodo_host=https://api.dev.platform.pagopa.it/nodo

# Data and setting configuration
creditor_institution_id=77777777777
broker_id=15376371009
station_id=15376371009_01
psp_id=60000000001
channel_id=60000000001_01
reporting_batch_wait_execution_sec=120
include_debug_logs=true
17 changes: 17 additions & 0 deletions integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Host addresses
host_header=api.uat.platform.pagopa.it
api_config_host=https://api.uat.platform.pagopa.it/apiconfig/auth/api/v1
gpd_host=https://api.uat.platform.pagopa.it/gpd/api/v1
reporting_analysis_host=https://api.uat.platform.pagopa.it/gpd-reporting/api/v1
payments_soap_host=https://api.uat.platform.pagopa.it/gpd-payments/api/v1
payments_rest_host=https://api.uat.platform.pagopa.it/gpd-payment-receipts/api/v1
nodo_host=https://api.uat.platform.pagopa.it/nodo

# Data and setting configuration
creditor_institution_id=77777777777
broker_id=15376371009
station_id=15376371009_01
psp_id=60000000001
channel_id=60000000001_01
reporting_batch_wait_execution_sec=120
include_debug_logs=true
23 changes: 23 additions & 0 deletions integration-test/src/features/01_reporting_full.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: All about flow report retrieving workflow - Complete flow

Background:
Given GPD service running
* APIConfig service running
* GPD Payments service running
* reporting analysis service running
* a paid debt position
* a report flow sent to Node

Scenario: Reporting - Complete Happy path
When the reporting batch analyzes the reporting flows for the organization
And the client waits its execution
Then the client asks the flow list for the organization
* the client receives status code 200
* the client receives a non-empty list of flows
And the client asks the detail for one of the report flows
* the client receives status code 200
* the client receives the flow XML content
And the client asks the detail for the analyzed debt positions
* the client receives status code 200
* the client receives the payment options with status "REPORTED"

19 changes: 19 additions & 0 deletions integration-test/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "pagopa-gpd-payments",
"license": "MIT",
"version": "1.0.0",
"scripts": {
"test": "dotenv -e ./config/.env.local yarn cucumber",
"test:dev": "dotenv -e ./config/.env.dev yarn cucumber",
"test:uat": "dotenv -e ./config/.env.uat yarn cucumber",
"cucumber": "npx cucumber-js -r step_definitions --format=summary"
},
"dependencies": {
"@azure/storage-queue": "^12.12.0",
"@cucumber/cucumber": "^8.4.0",
"axios": "^0.27.2",
"dotenv": "^16.0.3",
"dotenv-cli": "^3.2.0",
"npx": "^10.2.2"
}
}
Loading

0 comments on commit 1a2370b

Please sign in to comment.