diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 2d66871cbe..2b157c58d9 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -29,14 +29,17 @@ const serverRestartDelay = Cypress.config('serverRestartDelay'); Cypress.Commands.add('createUser', () => { const user = { - username: 'soup', - email: 'hi@strapi.io', - password: 'coucou123', + username: 'admin', + email: 'admin@strapi.io', + password: 'pcw123', }; - return cy.request({ url: `${backendUrl}/users-permissions/init`, method: 'GET' }) + return cy + .request({ url: `${backendUrl}/users-permissions/init`, method: 'GET' }) .then(response => { - const { body: { hasAdmin } } = response; + const { + body: { hasAdmin }, + } = response; if (!hasAdmin) { // Create one @@ -47,44 +50,44 @@ Cypress.Commands.add('createUser', () => { Cypress.Commands.add('checkModalOpening', () => { return cy.get('.modal').invoke('show'); -}) +}); Cypress.Commands.add('deleteUser', (id, jwt) => { cy.request({ url: `${backendUrl}/users/${id}`, method: 'DELETE', headers: { - Authorization: `Bearer ${jwt}` - } + Authorization: `Bearer ${jwt}`, + }, }); }); Cypress.Commands.add('createProductAndTagApis', (jwt = null) => { - return cy - .fixture('api/tag.json') - .then(body => { - return cy.request({ + return cy.fixture('api/tag.json').then(body => { + return cy + .request({ url: `${backendUrl}/content-type-builder/models`, method: 'POST', headers: { - Authorization: `Bearer ${jwt}` + Authorization: `Bearer ${jwt}`, }, body, }) .wait(serverRestartDelay) .fixture('api/product.json') .then(body => { - return cy.request({ - url: `${backendUrl}/content-type-builder/models`, - method: 'POST', - headers: { - Authorization: `Bearer ${jwt}` - }, - body, - }) - .wait(serverRestartDelay); + return cy + .request({ + url: `${backendUrl}/content-type-builder/models`, + method: 'POST', + headers: { + Authorization: `Bearer ${jwt}`, + }, + body, + }) + .wait(serverRestartDelay); }); - }); + }); }); Cypress.Commands.add('createCTMApis', (jwt = null) => { @@ -114,8 +117,7 @@ Cypress.Commands.add('deleteAllModelData', (model, jwt, source = null) => { headers: { Authorization: `Bearer ${jwt}`, }, - }) - .then(data => { + }).then(data => { const entriesToDelete = data.body.reduce((acc, curr) => { return acc.concat(curr.id); }, []); @@ -134,51 +136,51 @@ Cypress.Commands.add('deleteAllModelData', (model, jwt, source = null) => { }); Cypress.Commands.add('deleteApi', (model, jwt) => { - return cy.request({ - url: `${backendUrl}/content-type-builder/models/${model}`, - method: 'DELETE', - headers: { - Authorization: `Bearer ${jwt}` - }, - }) - .wait(serverRestartDelay); + return cy + .request({ + url: `${backendUrl}/content-type-builder/models/${model}`, + method: 'DELETE', + headers: { + Authorization: `Bearer ${jwt}`, + }, + }) + .wait(serverRestartDelay); }); Cypress.Commands.add('login', () => { - cy.createUser() - return cy.request({ - url: `${backendUrl}/auth/local`, - method: 'POST', - body: { - identifier: 'soup', - password: 'coucou123', - }, - }) - .then(response => { - window.localStorage.setItem('jwtToken', stringify(response.body.jwt)); - window.localStorage.setItem('userInfo', stringify(response.body.user)); + cy.createUser(); + return cy + .request({ + url: `${backendUrl}/auth/local`, + method: 'POST', + body: { + identifier: 'admin', + password: 'pcw123', + }, + }) + .then(response => { + window.localStorage.setItem('jwtToken', stringify(response.body.jwt)); + window.localStorage.setItem('userInfo', stringify(response.body.user)); - return response.body; - }) + return response.body; + }); }); Cypress.Commands.add('seedData', (model, jwt, source = null) => { - return cy - .fixture(`seeds/${model}.json`) - .then(seed => { - seed.forEach(body => { - cy.request({ - method: 'POST', - url: `${backendUrl}/content-manager/explorer/${model}?source='content-manager`, - headers: { - Authorization: `Bearer ${jwt}`, - }, - body, - }); + return cy.fixture(`seeds/${model}.json`).then(seed => { + seed.forEach(body => { + cy.request({ + method: 'POST', + url: `${backendUrl}/content-manager/explorer/${model}?source='content-manager`, + headers: { + Authorization: `Bearer ${jwt}`, + }, + body, }); }); + }); }); Cypress.Commands.add('submitForm', () => { return cy.get('form').submit(); -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index 4ce2f22a90..ace28a0afb 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,13 @@ { "private": true, "version": "3.0.0-alpha.14.5", - "dependencies": { - "cypress": "^3.1.2" - }, + "dependencies": {}, "devDependencies": { "assert": "~1.3.0", "axios": "^0.18.0", "babel-eslint": "^6.1.2", "chalk": "^2.4.1", + "cypress": "^3.1.2", "eslint": "^4.19.1", "eslint-plugin-babel": "^4.0.0", "eslint-plugin-react": "^7.7.0", diff --git a/packages/strapi-plugin-users-permissions/cypress/integration/login_specs.js b/packages/strapi-plugin-users-permissions/cypress/integration/login_specs.js index 1fbe0e39b9..d03fd946f4 100644 --- a/packages/strapi-plugin-users-permissions/cypress/integration/login_specs.js +++ b/packages/strapi-plugin-users-permissions/cypress/integration/login_specs.js @@ -1,7 +1,7 @@ const frontLoadingDelay = Cypress.config('frontLoadingDelay'); const userData = { - identifier: 'soup', - password: 'coucou123', + identifier: 'admin', + password: 'pcw123', }; describe('Test login', () => { @@ -19,19 +19,13 @@ describe('Test login', () => { cy.deleteUser(userId, jwt); } }); - it('Should login the user', () => { - cy.visit('/admin/users-permissions/auth/login') - .wait(frontLoadingDelay); + cy.visit('/admin/users-permissions/auth/login').wait(frontLoadingDelay); - Object - .keys(userData) - .map(key => { - return cy - .get(`#${key}`) - .type(userData[key]); - }); + Object.keys(userData).map(key => { + return cy.get(`#${key}`).type(userData[key]); + }); cy.submitForm() .window() @@ -42,8 +36,7 @@ describe('Test login', () => { userId = userInfo._id || userInfo.id; expect(win.localStorage.getItem('jwtToken')).to.be.ok; }); - - cy.url() - .should('equal', `${Cypress.config('baseUrl')}/admin/`); + + cy.url().should('equal', `${Cypress.config('baseUrl')}/admin/`); }); -}); \ No newline at end of file +}); diff --git a/packages/strapi-plugin-users-permissions/cypress/integration/register_specs.js b/packages/strapi-plugin-users-permissions/cypress/integration/register_specs.js index 969381af9b..5f07c9fae4 100644 --- a/packages/strapi-plugin-users-permissions/cypress/integration/register_specs.js +++ b/packages/strapi-plugin-users-permissions/cypress/integration/register_specs.js @@ -1,9 +1,9 @@ const frontLoadingDelay = Cypress.config('frontLoadingDelay'); const registerData = { - username: 'soup', - email: 'hi@strapi.io', - password: 'coucou123', - confirmPassword: 'coucou123', + username: 'admin', + email: 'admin@strapi.io', + password: 'pcw123', + confirmPassword: 'pcw123', }; let jwt; let userId; @@ -14,30 +14,24 @@ describe('Test register page', () => { if (userId) { cy.deleteUser(userId, jwt); } - }) - + }); + it('Visits /admin and should be redirected to register page', () => { - cy.visit('/admin') - .wait(frontLoadingDelay); + cy.visit('/admin').wait(frontLoadingDelay); // Check if the user is being redirected to /register - cy.url() - .should('include', '/users-permissions/auth/register'); + cy.url().should('include', '/users-permissions/auth/register'); }); it('Should redirect to /register when trying to hit /login', () => { - cy.visit('/admin/plugins/users-permissions/auth/login') - .wait(frontLoadingDelay); + cy.visit('/admin/plugins/users-permissions/auth/login').wait(frontLoadingDelay); - cy.url() - .should('include', '/users-permissions/auth/register'); + cy.url().should('include', '/users-permissions/auth/register'); }); it('Should register the admin user', () => { Object.keys(registerData).map(key => { - return cy - .get(`#${key}`) - .type(registerData[key]); + return cy.get(`#${key}`).type(registerData[key]); }); // Submit form @@ -45,12 +39,11 @@ describe('Test register page', () => { .window() .should(win => { const userInfo = JSON.parse(win.sessionStorage.getItem('userInfo')); - + jwt = JSON.parse(win.sessionStorage.getItem('jwtToken')); userId = userInfo._id || userInfo.id; expect(win.sessionStorage.getItem('jwtToken')).to.be.ok; }); - cy.url() - .should('equal', `${frontEndUrl}/admin/`); + cy.url().should('equal', `${frontEndUrl}/admin/`); }); -}); \ No newline at end of file +}); diff --git a/test/start.js b/test/start.js index ef1acc65e9..cd3a0493b6 100644 --- a/test/start.js +++ b/test/start.js @@ -103,7 +103,7 @@ const main = async () => { const cypressTest = () => { return cypress - .run({ spec: './packages/**/cypress/integration/*' }); + .run({ spec: './packages/**/cypress/integration/*', browser: 'chrome' }); } const testProcess = async (database) => {