Skip to content

Commit

Permalink
Feat/update cypress tests (#2084)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
andrewleith and jzbahrai authored Jan 24, 2024
1 parent 463becb commit 1af9f27
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
33 changes: 32 additions & 1 deletion tests_cypress/config.js
Original file line number Diff line number Diff line change
@@ -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: ['[email protected]'],
NonTeam: ['[email protected]'],
Simulated: ['[email protected]', '[email protected]', '[email protected]'],
SimulatedPhone: ['+16132532222', '+16132532223', '+16132532224']
},

}

let STAGING = {
CONFIG_NAME: "STAGING",
Hostnames: {
Expand Down Expand Up @@ -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;
14 changes: 7 additions & 7 deletions tests_cypress/cypress/Notify/NotifyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
}
});
}
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions tests_cypress/cypress/e2e/api/all.cy.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import './email_notifications.cy';
import './file_attach.cy';
import './sre_tools.cy';

0 comments on commit 1af9f27

Please sign in to comment.