From f852ffce0bcf8fe2b0a3ab2e0429b8c1b2cd25f3 Mon Sep 17 00:00:00 2001 From: Thoscellen Date: Thu, 22 Aug 2019 14:28:29 +0200 Subject: [PATCH] New test to understand better route & request. changed login function without tested it. --- .../errors/registrerExistingUser.json | 7 ++ cypress/integration/login_spec.js | 106 ++++++++++-------- cypress/support/commands.js | 6 +- 3 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 cypress/fixtures/errors/registrerExistingUser.json diff --git a/cypress/fixtures/errors/registrerExistingUser.json b/cypress/fixtures/errors/registrerExistingUser.json new file mode 100644 index 0000000..4435066 --- /dev/null +++ b/cypress/fixtures/errors/registrerExistingUser.json @@ -0,0 +1,7 @@ +{ + "status": "error", + "data": [], + "errors": [ + "Stub: This email is already registered, please choose another one." + ] +} \ No newline at end of file diff --git a/cypress/integration/login_spec.js b/cypress/integration/login_spec.js index 4223e43..7f7b158 100644 --- a/cypress/integration/login_spec.js +++ b/cypress/integration/login_spec.js @@ -1,6 +1,5 @@ /// // import userMutoid from '../../fixtures/userMutoid'; -var Mutoid; describe('As a visitor, I am able to log in', function () { @@ -20,40 +19,26 @@ describe('As a visitor, I am able to log in', function () { }); -describe('As a visitor, I can only create an account the right way.', function () { - - before(function () { - cy.fixture("userMutoid.json").as("Mutoid").then(() => { - expect(this.Mutoid.email).to.exist; - expect(this.Mutoid.password).to.exist; - Mutoid = this.Mutoid; - }); - }); +describe('As a visitor, I can only register the right way.', function () { beforeEach(', go to the login webpage.', function () { cy.visit("/online"); }); - it('Check that the Create Account tab is accessible', function () { + it('Check that the "Create Account" tab is accessible', function () { // Assert - cy.get('.menu-reg').first().find('a[href$="action=register"]') - .should('be.visible'); + cy.get('.menu-reg').first().find('a[href$="action=register"]').should('be.visible'); }); - it('Check that the Create Account tab shows a form to fill when active', function () { + it('Check that the "Create Account" tab shows a form to fill when active', function () { // Act : Visiter le formulaire pour s'inscrire. cy.get('.menu-reg').find('a[href$="action=register"]').click(); // Assert cy.url().should('include', '?action=register'); - // L'onglet "Create accout" possède la classe "active". - cy.get('.menu-reg').find('a[href$="action=register"]').should('have.class', 'active') - // Les formulaires existent et sont visible - cy.get('input#register-email') - .should('be.visible'); - cy.get('input#register-password') - .should('be.visible'); - // Le bouton "Create Account" existe. - cy.get('#register-form').find(":submit"); + cy.get('.menu-reg').find('a[href$="action=register"]').should('have.class', 'active') // L'onglet "Create accout" possède la classe "active". + cy.get('input#register-email').should('be.visible'); // Les formulaires existent et sont visible + cy.get('input#register-password').should('be.visible'); + cy.get('#register-form').find(":submit"); // Le bouton "Create Account" existe. }); it('Allow to land directly on the Register page', function () { @@ -82,30 +67,54 @@ describe('As a visitor, I can only create an account the right way.', function ( it('Prevent to create an account with an already existing account', function () { // Arrange - cy.get('.menu-reg').first().find('a[href$="action=register"]').click(); + cy.fixture("users.json").as("users").then((users) => { + let mutoid = users["Mutoid"]; + expect(mutoid.email).to.exist; + expect(mutoid.password).to.exist; + expect(mutoid.type).eq("user"); + cy.get('.menu-reg').first().find('a[href$="action=register"]').click(); - // Act - cy.get('input#register-email').type(Mutoid.email); - cy.get('input#register-password').type(Mutoid.password); - cy.get('#register-form').find(":submit").click(); + // Act + cy.get('input#register-email').type(mutoid.email); + cy.get('input#register-password').type(mutoid.password); + cy.get('#register-form').find(":submit").click(); - // Assert - cy.get('input#register-email').should('have.class', 'input_error'); - cy.get('input#register-password').should('have.class', 'input_error'); - cy.get('div#register-error') - .should('be.visible') - .and('contain', 'This email is already registered, please choose another one.') + // Assert + cy.get('input#register-email').should('have.class', 'input_error'); + cy.get('input#register-password').should('have.class', 'input_error'); + cy.get('div#register-error') + .should('be.visible') + .and('contain', 'This email is already registered, please choose another one.') + }); }) + + it.only('Check that it explain correclty to the user when he try to create an already exxisting account', function () { + cy.server(); + cy.fixture("users.json").as("users").then((users) => { + let mutoid = users["Mutoid"]; + + cy.route("online/api/user", "fx:/errors/registerExistingUser.json"); + cy.request({ + method:'POST', + url:"online/api/user", + body:mutoid, + failOnStatusCode:false, + qs:"t=" + new Date().getTime(), + }); + + }); + }) + }); -describe.only("As a user, I can only log in and out the right way", function () { +describe("As a user, I can only log in and out the right way", function () { before(function () { cy.fixture("users.json").as("users").then((users) => { - Mutoid = users["Mutoid"]; - expect(Mutoid.email).to.exist; - expect(Mutoid.password).to.exist; - expect(Mutoid.type).eq("user"); + mutoid = users["Mutoid"]; + expect(mutoid.email).to.exist; + expect(mutoid.password).to.exist; + expect(mutoid.type).eq("user"); }); }) @@ -113,7 +122,6 @@ describe.only("As a user, I can only log in and out the right way", function () cy.visit("/online"); }) - it('Prevent to log in with empty credentials', function () { // Act cy.get('form#login-form').find(':submit').click(); @@ -132,7 +140,7 @@ describe.only("As a user, I can only log in and out the right way", function () // Act - cy.get("#login-email").type(Mutoid.email); + cy.get("#login-email").type(mutoid.email); cy.get('form#login-form').find(':submit').click(); // Assert cy.url().should('include', '?action=login'); // Pas de redirection @@ -146,7 +154,7 @@ describe.only("As a user, I can only log in and out the right way", function () it('Prevent to log in with just the password', function () { // Act - cy.get("#login-password").type(Mutoid.password) + cy.get("#login-password").type(mutoid.password) cy.get('form#login-form').find(':submit').click(); // Assert cy.url().should('include', '?action=login'); // Pas de redirection @@ -158,10 +166,10 @@ describe.only("As a user, I can only log in and out the right way", function () cy.get('input#login-password').should('have.class', 'input_error'); }) - it('Prevent to log in Mutoid with an invalid password', function () { + it('Prevent to log in mutoid with an invalid password', function () { // Act - cy.get("#login-email").type(Mutoid.email) - cy.get("#login-password").type(Mutoid.email) + cy.get("#login-email").type(mutoid.email) + cy.get("#login-password").type(mutoid.email) cy.get('form#login-form').find(':submit').click(); // Assert cy.url().should('include', '?action=login'); // Pas de redirection @@ -175,8 +183,8 @@ describe.only("As a user, I can only log in and out the right way", function () it('Logs Mutoid in.', function () { // Act - cy.get("#login-email").type(Mutoid.email) - cy.get("#login-password").type(Mutoid.password) + cy.get("#login-email").type(mutoid.email) + cy.get("#login-password").type(mutoid.password) cy.get("#login-form").find(":submit").click() // Assert cy.url().should('contain', '/online/#/reader/category/all/') @@ -186,7 +194,7 @@ describe.only("As a user, I can only log in and out the right way", function () it('Logs Mutoid in via API', function () { // act - cy.login(Mutoid); + cy.login(mutoid); cy.visit("/online"); // assert cy.getCookie('session').should('exist'); @@ -194,7 +202,7 @@ describe.only("As a user, I can only log in and out the right way", function () it('Logs Mutoid out.', function () { // Arrange - cy.login(Mutoid) + cy.login(mutoid) cy.visit('/online'); // act cy.get("div#user").find("a.user__settings").click(); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index db77e01..2ccec05 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -3,11 +3,7 @@ Cypress.Commands.add('login', function (user) { cy.request({ method: 'POST', url: "/online/api/auth?t=" + new Date().getTime(), - body: { - "email": user.email, - "password": user.password, - "remember": false - } + body: user }).as("response") });