New test to understand better route & request. changed login function without tested it.
This commit is contained in:
parent
099f346faa
commit
f852ffce0b
7
cypress/fixtures/errors/registrerExistingUser.json
Normal file
7
cypress/fixtures/errors/registrerExistingUser.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"status": "error",
|
||||||
|
"data": [],
|
||||||
|
"errors": [
|
||||||
|
"Stub: This email is already registered, please choose another one."
|
||||||
|
]
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
/// <reference types="Cypress" />
|
/// <reference types="Cypress" />
|
||||||
// import userMutoid from '../../fixtures/userMutoid';
|
// import userMutoid from '../../fixtures/userMutoid';
|
||||||
var Mutoid;
|
|
||||||
|
|
||||||
describe('As a visitor, I am able to log in', function () {
|
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 () {
|
describe('As a visitor, I can only register 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;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(', go to the login webpage.', function () {
|
beforeEach(', go to the login webpage.', function () {
|
||||||
cy.visit("/online");
|
cy.visit("/online");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check that the Create Account tab is accessible', function () {
|
it('Check that the "Create Account" tab is accessible', function () {
|
||||||
// Assert
|
// Assert
|
||||||
cy.get('.menu-reg').first().find('a[href$="action=register"]')
|
cy.get('.menu-reg').first().find('a[href$="action=register"]').should('be.visible');
|
||||||
.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.
|
// Act : Visiter le formulaire pour s'inscrire.
|
||||||
cy.get('.menu-reg').find('a[href$="action=register"]').click();
|
cy.get('.menu-reg').find('a[href$="action=register"]').click();
|
||||||
// Assert
|
// Assert
|
||||||
cy.url().should('include', '?action=register');
|
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') // L'onglet "Create accout" possède la classe "active".
|
||||||
cy.get('.menu-reg').find('a[href$="action=register"]').should('have.class', 'active')
|
cy.get('input#register-email').should('be.visible'); // Les formulaires existent et sont visible
|
||||||
// Les formulaires existent et sont visible
|
cy.get('input#register-password').should('be.visible');
|
||||||
cy.get('input#register-email')
|
cy.get('#register-form').find(":submit"); // Le bouton "Create Account" existe.
|
||||||
.should('be.visible');
|
|
||||||
cy.get('input#register-password')
|
|
||||||
.should('be.visible');
|
|
||||||
// Le bouton "Create Account" existe.
|
|
||||||
cy.get('#register-form').find(":submit");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Allow to land directly on the Register page', function () {
|
it('Allow to land directly on the Register page', function () {
|
||||||
@ -82,11 +67,16 @@ 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 () {
|
it('Prevent to create an account with an already existing account', function () {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
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();
|
cy.get('.menu-reg').first().find('a[href$="action=register"]').click();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
cy.get('input#register-email').type(Mutoid.email);
|
cy.get('input#register-email').type(mutoid.email);
|
||||||
cy.get('input#register-password').type(Mutoid.password);
|
cy.get('input#register-password').type(mutoid.password);
|
||||||
cy.get('#register-form').find(":submit").click();
|
cy.get('#register-form').find(":submit").click();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
@ -95,17 +85,36 @@ describe('As a visitor, I can only create an account the right way.', function (
|
|||||||
cy.get('div#register-error')
|
cy.get('div#register-error')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('contain', 'This email is already registered, please choose another one.')
|
.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 () {
|
before(function () {
|
||||||
cy.fixture("users.json").as("users").then((users) => {
|
cy.fixture("users.json").as("users").then((users) => {
|
||||||
Mutoid = users["Mutoid"];
|
mutoid = users["Mutoid"];
|
||||||
expect(Mutoid.email).to.exist;
|
expect(mutoid.email).to.exist;
|
||||||
expect(Mutoid.password).to.exist;
|
expect(mutoid.password).to.exist;
|
||||||
expect(Mutoid.type).eq("user");
|
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");
|
cy.visit("/online");
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
it('Prevent to log in with empty credentials', function () {
|
it('Prevent to log in with empty credentials', function () {
|
||||||
// Act
|
// Act
|
||||||
cy.get('form#login-form').find(':submit').click();
|
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
|
// Act
|
||||||
cy.get("#login-email").type(Mutoid.email);
|
cy.get("#login-email").type(mutoid.email);
|
||||||
cy.get('form#login-form').find(':submit').click();
|
cy.get('form#login-form').find(':submit').click();
|
||||||
// Assert
|
// Assert
|
||||||
cy.url().should('include', '?action=login'); // Pas de redirection
|
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 () {
|
it('Prevent to log in with just the password', function () {
|
||||||
// Act
|
// Act
|
||||||
cy.get("#login-password").type(Mutoid.password)
|
cy.get("#login-password").type(mutoid.password)
|
||||||
cy.get('form#login-form').find(':submit').click();
|
cy.get('form#login-form').find(':submit').click();
|
||||||
// Assert
|
// Assert
|
||||||
cy.url().should('include', '?action=login'); // Pas de redirection
|
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');
|
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
|
// Act
|
||||||
cy.get("#login-email").type(Mutoid.email)
|
cy.get("#login-email").type(mutoid.email)
|
||||||
cy.get("#login-password").type(Mutoid.email)
|
cy.get("#login-password").type(mutoid.email)
|
||||||
cy.get('form#login-form').find(':submit').click();
|
cy.get('form#login-form').find(':submit').click();
|
||||||
// Assert
|
// Assert
|
||||||
cy.url().should('include', '?action=login'); // Pas de redirection
|
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 () {
|
it('Logs Mutoid in.', function () {
|
||||||
// Act
|
// Act
|
||||||
cy.get("#login-email").type(Mutoid.email)
|
cy.get("#login-email").type(mutoid.email)
|
||||||
cy.get("#login-password").type(Mutoid.password)
|
cy.get("#login-password").type(mutoid.password)
|
||||||
cy.get("#login-form").find(":submit").click()
|
cy.get("#login-form").find(":submit").click()
|
||||||
// Assert
|
// Assert
|
||||||
cy.url().should('contain', '/online/#/reader/category/all/')
|
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 () {
|
it('Logs Mutoid in via API', function () {
|
||||||
// act
|
// act
|
||||||
cy.login(Mutoid);
|
cy.login(mutoid);
|
||||||
cy.visit("/online");
|
cy.visit("/online");
|
||||||
// assert
|
// assert
|
||||||
cy.getCookie('session').should('exist');
|
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 () {
|
it('Logs Mutoid out.', function () {
|
||||||
// Arrange
|
// Arrange
|
||||||
cy.login(Mutoid)
|
cy.login(mutoid)
|
||||||
cy.visit('/online');
|
cy.visit('/online');
|
||||||
// act
|
// act
|
||||||
cy.get("div#user").find("a.user__settings").click();
|
cy.get("div#user").find("a.user__settings").click();
|
||||||
|
@ -3,11 +3,7 @@ Cypress.Commands.add('login', function (user) {
|
|||||||
cy.request({
|
cy.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: "/online/api/auth?t=" + new Date().getTime(),
|
url: "/online/api/auth?t=" + new Date().getTime(),
|
||||||
body: {
|
body: user
|
||||||
"email": user.email,
|
|
||||||
"password": user.password,
|
|
||||||
"remember": false
|
|
||||||
}
|
|
||||||
}).as("response")
|
}).as("response")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user