From 68c4f0ff57932b3780542c061ad39c5b1257b159 Mon Sep 17 00:00:00 2001 From: andrea-putzu <106688558+andrea-putzu@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:18:01 +0100 Subject: [PATCH] [SELC-5980] Postman collection for integration test (#604) --- .github/workflows/call_integration_test.yml | 94 ++++++--------- .gitignore | 2 + package-lock.json | 111 ++++++++++++++++++ package.json | 5 + test/convert.js | 75 ++++++++++++ ...lfcare-Integration.postman_collection.json | 51 ++++++++ 6 files changed, 283 insertions(+), 55 deletions(-) create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 test/convert.js diff --git a/.github/workflows/call_integration_test.yml b/.github/workflows/call_integration_test.yml index 58b2e66df..1bcdcf8f2 100644 --- a/.github/workflows/call_integration_test.yml +++ b/.github/workflows/call_integration_test.yml @@ -9,61 +9,45 @@ on: required: true description: add '-pnpg' if workflow is related to pnpg -variables: - postmanEnvFile: integration_environment - - # ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/uat') }}: - # # selfHostedAgentPool: $(UAT_AGENT_POOL) - +jobs: + test: + environment: ${{ inputs.environment }}-ci + name: 'Run Postman collection on ${{ inputs.environment }}' + runs-on: ubuntu-20.04 + # pool: + # name: $(selfHostedAgentPool) + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + name: Checkout + - name: 'Download postman environment' + env: + INTEGRATION_ENVIRONMENT: ${{ secrets.INTEGRATION_ENVIRONMENT }} + run: 'echo "$INTEGRATION_ENVIRONMENT" | base64 --decode > Selfcare-Integration.postman_environment.json' + shell: bash + - name: 'List file' + run: 'ls -la' + shell: bash + - name: 'Cat file' + run: 'cat Selfcare-Integration.postman_environment.json' + shell: bash + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af + with: + node-version: '16.x' - # ${{ else }}: - # # selfHostedAgentPool: $(DEV_AGENT_POOL) - # postmanEnvFile: integration_environment.json + - name: Install newman + shell: bash + run: npm install -g newman + + - name: Run newman + shell: bash + run: newman run ./test/newman/Selfcare-Integration.postman_collection.json -e Selfcare-Integration.postman_environment.json --reporters cli,json --reporter-json-export ./test/test-result.json -stages: - - stage: stage_postman_test - environment: ${{ inputs.environment }}-ci - displayName: 'Test_e2e_on_${{ variables.environment }}' - dependsOn: [ stage_deploy ] - condition: and(succeeded(),or(eq(variables.environment, 'DEV'), eq(variables.environment, 'UAT'))) - jobs: - - job: 'Run_Postman_collection_on_${{ variables.environment }}' - displayName: 'Run Postman collection on ${{ variables.environment }}' - # pool: - # name: $(selfHostedAgentPool) - steps: - - task: NodeTool@0 - inputs: - versionSpec: '16.x' - - task: Npm@1 - displayName: Install newman - inputs: - command: custom - customCommand: install -g newman - - task: DownloadSecureFile@1 - displayName: 'download postman environment' - name: postman_env - inputs: - secureFile: $(postmanEnvFile) - - task: CmdLine@2 - displayName: Run newman - continueOnError: true # Useful to avoid the skipping of result publishing task - inputs: - script: newman run selfcare-onboarding/test/newman/Selfcare-Integration.postman_collection.json -e $(postman_env.secureFilePath) --reporters cli,junit --reporter-junit-export result/test-result.xml - - task: PublishTestResults@2 - inputs: - testResultsFormat: 'JUnit' - testResultsFiles: '**/test-*.xml' - searchFolder: '$(System.DefaultWorkingDirectory)/result/' - testRunTitle: 'Publish Newman Test Results' - # - task: 'Bash@3' - # displayName: 'Send message on Slack' - # condition: in(variables['Agent.JobStatus'], 'SucceededWithIssues', 'Failed') - # inputs: - # targetType: 'inline' - # script: > - # curl -X POST \ - # -H "Content-type: application/json" \ - # --data '{"text": "*Attention: There is an error in pipeline $(System.DefinitionName) in step _postman test_!*\nCheck the logs for more details $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) to view the build results."}' \ - # $(SLACK_WEBHOOK_URL) + - name: Send newman report + shell: bash + run: node ./test/convert.js + + - name: 'Send message on Slack' + shell: bash + run: > + curl -X POST ${{ secrets.SLACK_WEBHOOK_URL }} -H 'Content-type: application/json' -d @test/stats.json diff --git a/.gitignore b/.gitignore index 9f7eaa856..b05f7c001 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ override.tf override.tf.json *_override.tf *_override.tf.json + +**/node_modules/* diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..bad13e996 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,111 @@ +{ + "name": "selfcare-onboarding", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "axios": "^1.7.7" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..510089328 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "axios": "^1.7.7" + } +} diff --git a/test/convert.js b/test/convert.js new file mode 100644 index 000000000..1f385fe2f --- /dev/null +++ b/test/convert.js @@ -0,0 +1,75 @@ +var fs = require('fs'); + +fs.readFile('test/test-result.json', 'utf8', function (err, data) { + if (err) throw err; // we'll not consider error handling for now + var obj = JSON.parse(data); + + let json = JSON.stringify(convert(obj["run"]["stats"], process.argv[2])); + fs.writeFile("test/stats.json", json, 'utf8', (err) => { + if (err) { + console.error('Error writing to file', err); + } else { + console.log('Data written to file'); + } + }); +}); + + +function convert(payload) { + var block = + { + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*:white_check_mark: GitHub Actions*" + } + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Iterations*:\ntotal: "+payload["iterations"]["total"]+" pending: "+payload["iterations"]["pending"]+" failed: "+payload["iterations"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*Items*:\ntotal: "+payload["items"]["total"]+" pending: "+payload["items"]["pending"]+" failed: "+payload["items"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*Scripts*:\ntotal: "+payload["scripts"]["total"]+" pending: "+payload["scripts"]["pending"]+" failed: "+payload["scripts"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*Prerequests*:\ntotal: "+payload["prerequests"]["total"]+" pending: "+payload["prerequests"]["pending"]+" failed: "+payload["prerequests"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*Requests*:\ntotal: "+payload["requests"]["total"]+" pending: "+payload["requests"]["pending"]+" failed: "+payload["requests"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*Tests*:\ntotal: "+payload["tests"]["total"]+" pending: "+payload["tests"]["pending"]+" failed: "+payload["tests"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*Assertions*:\ntotal: "+payload["assertions"]["total"]+" pending: "+payload["assertions"]["pending"]+" failed: "+payload["assertions"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*TestScripts*:\ntotal: "+payload["testScripts"]["total"]+" pending: "+payload["testScripts"]["pending"]+" failed: "+payload["testScripts"]["failed"] + }, + { + "type": "mrkdwn", + "text": "*PrerequestScripts*:\ntotal: "+payload["prerequestScripts"]["total"]+" pending: "+payload["prerequestScripts"]["pending"]+" failed: "+payload["prerequestScripts"]["failed"] + }, + ] + } + ] + } + + return block +} + diff --git a/test/newman/Selfcare-Integration.postman_collection.json b/test/newman/Selfcare-Integration.postman_collection.json index eb19d3487..0b3fc9aac 100644 --- a/test/newman/Selfcare-Integration.postman_collection.json +++ b/test/newman/Selfcare-Integration.postman_collection.json @@ -9,6 +9,57 @@ { "name": "External", "item": [ + { + "name": "getUserGroup", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"getInstitutionUsersByProduct ok\", function () {", + "var jsonData = pm.response.json();", + "pm.response.to.have.status(200);", + "//pm.expect(jsonData.message).to.contain('Entity created');", + "});" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Ocp-Apim-Subscription-Key", + "value": "{{apimKeyPN}}", + "type": "text" + } + ], + "url": { + "raw": "{{apiBaseUrl}}/external/v2/user-groups?userId={{userId}}&institutions={{institutionId}}", + "host": [ + "{{apiBaseUrl}}" + ], + "path": [ + "external", + "v2", + "user-groups" + ], + "query": [ + { + "key": "userId", + "value": "{{userId}}" + }, + { + "key": "institutions", + "value": "{{institutionId}}" + } + ] + } + }, + "response": [] + }, { "name": "getInstitutionUsersByProduct", "event": [