diff --git a/cypress/integration/api_spec.js b/cypress/integration/api_spec.js new file mode 100644 index 0000000..e69de29 diff --git a/cypress/integration/login_spec.js b/cypress/integration/login_spec.js index 7f7b158..94016f2 100644 --- a/cypress/integration/login_spec.js +++ b/cypress/integration/login_spec.js @@ -1,9 +1,8 @@ /// -// import userMutoid from '../../fixtures/userMutoid'; describe('As a visitor, I am able to log in', function () { - beforeEach(function () { + beforeEach('Go to the login webpage.', function () { cy.visit("/online"); }) @@ -16,12 +15,11 @@ describe('As a visitor, I am able to log in', function () { // Asset cy.get('.menu-reg').first().find('a[href$="action=login"]').should('have.class', 'active'); }) - }); describe('As a visitor, I can only register the right way.', function () { - beforeEach(', go to the login webpage.', function () { + beforeEach('go to the login webpage.', function () { cy.visit("/online"); }); @@ -53,14 +51,12 @@ describe('As a visitor, I can only register the right way.', function () { cy.get('.menu-reg').first().find('a[href$="action=register"]').click(); cy.get('input#register-email').should('have.not.class', 'input_error'); cy.get('input#register-password').should('have.not.class', 'input_error'); - // Act cy.get('#register-form').find(":submit").click(); // Assert cy.get('div#register-error') // Message d'erreur .should('have.class', 'register__error') .and('be.not.visible'); - cy.get('input#register-email').should('have.class', 'input_error'); // Champs surlignés cy.get('input#register-password').should('have.class', 'input_error'); }) @@ -85,21 +81,25 @@ describe('As a visitor, I can only register the right way.', function () { cy.get('div#register-error') .should('be.visible') .and('contain', 'This email is already registered, please choose another one.') + //We should find a way to get the response body and assert it is well displayed instead of this string. }); }) - it.only('Check that it explain correclty to the user when he try to create an already exxisting account', function () { + it.only('Check that it explain correclty to the user when he try to create an already existing 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.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(), + method: 'POST', + url: "online/api/user", + body: mutoid, + failOnStatusCode: false, + qs: { "t": new Date().getTime() } + }).then((response) => { + cy.expect(response.body.status).to.be.eq('error'); + cy.expect(response.body.errors[0]).to.be.eq('This email is already registered, please choose another one.'); }); }); @@ -109,12 +109,14 @@ describe('As a visitor, I can only register the right way.', function () { describe("As a user, I can only log in and out the right way", function () { + var mutoid; + 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"); + //expect(mutoid.email).to.exist; + //expect(mutoid.password).to.exist; + //expect(mutoid.type).eq("user"); }); }) @@ -137,8 +139,6 @@ describe("As a user, I can only log in and out the right way", function () { }) it('Prevent to log in with just the email', function () { - - // Act cy.get("#login-email").type(mutoid.email); cy.get('form#login-form').find(':submit').click(); @@ -192,7 +192,7 @@ describe("As a user, I can only log in and out the right way", function () { cy.logout(); }); - it('Logs Mutoid in via API', function () { + it.skip('Logs Mutoid in via API', function () { // act cy.login(mutoid); cy.visit("/online"); @@ -213,5 +213,4 @@ describe("As a user, I can only log in and out the right way", function () { .should('have.class', 'active'); cy.getCookie('session').should('not.exist'); }) - }) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 2ccec05..6b08d46 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -1,39 +1,41 @@ Cypress.Commands.add('login', function (user) { - if(user === undefined) throw new Error("Login via API failed because the user credential was not given."); + if (user === undefined) throw new Error("Login via API failed because the user credential was not given."); cy.request({ method: 'POST', - url: "/online/api/auth?t=" + new Date().getTime(), - body: user + url: "/online/api/auth", + body: user, + qs: { "t": new Date().getTime() } }).as("response") }); Cypress.Commands.add('logout', function () { - cy.request({ - method: 'GET', - url: "/online/logout", - }); - -}) - -Cypress.Commands.add('addFeed', function (arrayOfFeed) { - arrayOfFeed.forEach(element => { + if (cy.getCookie("session") != null) { cy.request({ - method: 'POST', - url: "/online/api/feed?t=" + new Date().getTime(), - body: { - "category": element.category, - "feed": element.feed - } - }).then((response) => { - if (response.status == 200) { - // collect data : - // id : number like 3911929 - // category : number or 0 if not defined - } - }) - }); + method: 'GET', + url: "/online/logout", + qs: { "t": new Date().getTime() } + }).as("response"); + } }) -Cypress.Commands.add('removeFeed', function () { - +Cypress.Commands.add('addFeed', function (aFeed) { + cy.request({ + method: 'POST', + url: "/online/api/feed", + body: { + "category": aFeed.category, + "feed": aFeed.feed + }, + qs: { "t": new Date().getTime() } + }).then((response) => { + if (response.status == 200) { + // collect data : + // id : number like 3911929 + // category : number or 0 if not defined + } + }) +}) + +Cypress.Commands.add('removeFeed', function (aFeedId) { + }) \ No newline at end of file