From 1af9f276ed889a0ed5bb4e99c7e3cec2d3b8735e Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 24 Jan 2024 14:50:55 -0400 Subject: [PATCH] Feat/update cypress tests (#2084) * chore(cypress config): add a production config in case we need to test against prod * chore: include SRE methods in 'all' test suite * fix(cypress config read): read the credentials in differently due to config refactor --------- Co-authored-by: Jumana B --- tests_cypress/config.js | 33 ++++++++++++++++++++++- tests_cypress/cypress/Notify/NotifyAPI.js | 14 +++++----- tests_cypress/cypress/e2e/api/all.cy.js | 1 + 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/tests_cypress/config.js b/tests_cypress/config.js index 5cd94f0e18..5ea2ae52d8 100644 --- a/tests_cypress/config.js +++ b/tests_cypress/config.js @@ -1,3 +1,33 @@ +let PRODUCTION = { + CONFIG_NAME: "PRODUCTION", + Hostnames: { + API: 'https://api.notification.canada.ca', + Admin: 'https://notification.canada.ca', + DDAPI: 'https://api.document.notification.canada.ca', + }, + Services: { + Notify: 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553', + Cypress: '5c8a0501-2aa8-433a-ba51-cefb8063ab93' + }, + Templates: { + 'FILE_ATTACH_TEMPLATE_ID': 'ee6e4f6e-df3c-49b5-82de-eca5122ce965', + 'SIMPLE_EMAIL_TEMPLATE_ID': 'bcc5ff84-4f20-4714-ac8e-7c5bd91c49a6', + 'VARIABLES_EMAIL_TEMPLATE_ID': '0f10fca7-a5e8-4c03-bc96-610072f236eb', + 'SMOKE_TEST_EMAIL': 'be04f866-2302-4b76-8efd-2dec1e853c7d', + 'SMOKE_TEST_EMAIL_BULK': '6978ecf0-8049-47ca-b5af-f010796e8805', + 'SMOKE_TEST_EMAIL_ATTACH': 'ee6e4f6e-df3c-49b5-82de-eca5122ce965', + 'SMOKE_TEST_EMAIL_LINK': '8bac2ff9-32e6-4e19-bf80-4218ce4789fd', + 'SMOKE_TEST_SMS': 'f718f471-d940-44f6-9841-93f61da9b4f7' + }, + Users: { + Team: ['andrew.leith+2@cds-snc.ca'], + NonTeam: ['person@example.com'], + Simulated: ['simulate-delivered-2@notification.canada.ca', 'simulate-delivered-3@notification.canada.ca', 'success@simulator.amazonses.com'], + SimulatedPhone: ['+16132532222', '+16132532223', '+16132532224'] + }, + +} + let STAGING = { CONFIG_NAME: "STAGING", Hostnames: { @@ -69,9 +99,10 @@ let LOCAL = { const config = { STAGING, LOCAL, + PRODUCTION }; // choose which config to use here -const ConfigToUse = config.STAGING; +const ConfigToUse = config.LOCAL; module.exports = ConfigToUse; diff --git a/tests_cypress/cypress/Notify/NotifyAPI.js b/tests_cypress/cypress/Notify/NotifyAPI.js index 02ec5afbe5..400dd1b96b 100644 --- a/tests_cypress/cypress/Notify/NotifyAPI.js +++ b/tests_cypress/cypress/Notify/NotifyAPI.js @@ -26,8 +26,7 @@ const Utilities = { }; const Admin = { SendOneOff: ({to, template_id}) => { - - var token = Utilities.CreateJWT(Cypress.env('ADMIN_USERNAME'), Cypress.env('ADMIN_SECRET')); + var token = Utilities.CreateJWT(Cypress.env('ADMIN_USERNAME'), Cypress.env(config.CONFIG_NAME).ADMIN_SECRET); return cy.request({ url: `/service/${config.Services.Cypress}/send-notification`, method: 'POST', @@ -37,7 +36,7 @@ const Admin = { body: { 'to': to, 'template_id': template_id, - 'created_by': Cypress.env('NOTIFY_USER_ID'), + 'created_by': Cypress.env(config.CONFIG_NAME).NOTIFY_USER_ID, } }); } @@ -117,7 +116,7 @@ const API = { }); }, CreateAPIKey: ({ service_id, key_type, name }) => { - var token = Utilities.CreateJWT(Cypress.env('ADMIN_USERNAME'), Cypress.env('ADMIN_SECRET')); + var token = Utilities.CreateJWT(Cypress.env('ADMIN_USERNAME'), Cypress.env(config.CONFIG_NAME).ADMIN_SECRET); return cy.request({ url: `/service/${service_id}/api-key`, method: 'POST', @@ -127,12 +126,13 @@ const API = { body: { key_type: key_type, name: name, - created_by: Cypress.env('NOTIFY_USER_ID'), + created_by: Cypress.env(config.CONFIG_NAME).NOTIFY_USER_ID, } }); }, RevokeAPIKey: ({ token, type, url, source, failOnStatusCode = true }) => { - var jwt_token = Utilities.CreateJWT(Cypress.env('SRE_USERNAME'), Cypress.env('SRE_SECRET')); + + var jwt_token = Utilities.CreateJWT(Cypress.env('SRE_USERNAME'), Cypress.env(config.CONFIG_NAME).SRE_SECRET); cy.request({ url: `/sre-tools/api-key-revoke`, method: 'POST', @@ -148,7 +148,7 @@ const API = { }); }, RevokeAPIKeyWithAdminAuth: ({ token, type, url, source, failOnStatusCode = true }) => { - var jwt_token = Utilities.CreateJWT(Cypress.env('ADMIN_USERNAME'), Cypress.env('ADMIN_SECRET')); + var jwt_token = Utilities.CreateJWT(Cypress.env('ADMIN_USERNAME'),Cypress.env(config.CONFIG_NAME).ADMIN_SECRET); return cy.request({ url: `/sre-tools/api-key-revoke`, method: 'POST', diff --git a/tests_cypress/cypress/e2e/api/all.cy.js b/tests_cypress/cypress/e2e/api/all.cy.js index 3a52c1c0d7..48c595e245 100644 --- a/tests_cypress/cypress/e2e/api/all.cy.js +++ b/tests_cypress/cypress/e2e/api/all.cy.js @@ -1,2 +1,3 @@ import './email_notifications.cy'; import './file_attach.cy'; +import './sre_tools.cy'; \ No newline at end of file