From 0a50672ab6c9e6c4f70ae8ca0df994f67d9e3607 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Mon, 9 Jan 2023 08:58:32 +1000 Subject: [PATCH] Fix for cypress randomstrings --- test/cypress/integration/api/Settings.spec.js | 7 ++++--- test/cypress/integration/api/Users.spec.js | 9 +++++---- test/cypress/support/commands.js | 11 +++++++++++ test/cypress/support/functions.js | 11 ----------- 4 files changed, 20 insertions(+), 18 deletions(-) delete mode 100644 test/cypress/support/functions.js diff --git a/test/cypress/integration/api/Settings.spec.js b/test/cypress/integration/api/Settings.spec.js index f04655ea..5b9d636f 100644 --- a/test/cypress/integration/api/Settings.spec.js +++ b/test/cypress/integration/api/Settings.spec.js @@ -1,15 +1,16 @@ /// -const fns = require('../support/functions'); - describe('Settings endpoints', () => { let token; - let settingName = 'cypressSetting_' + fns.generateRandomString(12); + let settingName; before(() => { cy.getToken().then((tok) => { token = tok; }); + cy.randomString(12).then((str) => { + settingName = 'cypressSetting_' + str; + }); }); it('Should be able to create new setting', function() { diff --git a/test/cypress/integration/api/Users.spec.js b/test/cypress/integration/api/Users.spec.js index 78e6a878..ade53df2 100644 --- a/test/cypress/integration/api/Users.spec.js +++ b/test/cypress/integration/api/Users.spec.js @@ -1,16 +1,17 @@ /// -const fns = require('../support/functions'); - describe('Users endpoints', () => { let token; - let uniqueEmail = 'jc_' + fns.generateRandomString(10) + '@example.com'; - let myUserID = 0; + let uniqueEmail; + let myUserID = 0; before(() => { cy.getToken().then((tok) => { token = tok; }); + cy.randomString(10).then((str) => { + uniqueEmail = 'jc_' + str + '@example.com'; + }); }); it('Should be able to get yourself', function() { diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 54b336e0..d376d716 100644 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -11,6 +11,17 @@ import 'cypress-wait-until'; +Cypress.Commands.add('randomString', (length) => { + var result = ''; + var characters = 'ABCDEFGHIJK LMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + var charactersLength = characters.length; + for (var i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; + // cy.wrap(result); +}); + /** * Check the swagger schema: * diff --git a/test/cypress/support/functions.js b/test/cypress/support/functions.js deleted file mode 100644 index 48bdc158..00000000 --- a/test/cypress/support/functions.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - generateRandomString: function (length) { - var result = ''; - var characters = 'ABCDEFGHIJK LMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - var charactersLength = characters.length; - for (var i = 0; i < length; i++) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; - }, -};