Add e2e seed and test event creation

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-10-12 13:16:36 +02:00
parent 6afde20b96
commit 5e75daa732
16 changed files with 237 additions and 30 deletions

View File

@@ -1,14 +1,6 @@
// https://docs.cypress.io/api/introduction/api.html
import { onBeforeLoad } from './browser-language';
beforeEach(() => {
cy.restoreLocalStorage();
});
afterEach(() => {
cy.saveLocalStorage();
});
describe('Homepage', () => {
it('Checks the footer', () => {
cy.visit('/', { onBeforeLoad });

View File

@@ -0,0 +1,44 @@
import { onBeforeLoad } from './browser-language';
beforeEach(() => {
cy.clearLocalStorage();
cy.checkoutSession();
});
afterEach(() => {
cy.dropSession();
});
describe('Events', () => {
it('Shows my current events', () => {
const EVENT = { title: 'My first event'};
cy.loginUser();
cy.visit('/events/me', { onBeforeLoad });
cy.contains('.message.is-danger', 'No events found');
cy.contains('.navbar-item', 'Create').click();
cy.url().should('include', 'create');
cy.get('.field').first().find('input').type(EVENT.title);
cy.get('.field').eq(1).find('input').type('my tag, holo{enter}');
cy.get('.field').eq(2).find('.datepicker .dropdown-trigger').click();
cy.get('.field').eq(3).find('.pagination-list .control').first().find('.select select').select('September');
cy.get('.field').eq(3).find('.pagination-list .control').last().find('.select select').select('2021');
cy.wait(1000);
cy.get('.field').eq(3).contains('.datepicker-cell', '15').click();
cy.contains('.button.is-primary', 'Create my event').click();
cy.url().should('include', '/events/');
cy.contains('.title', EVENT.title);
cy.contains('.title-and-informations span small', 'You\'re the only one going to this event');
cy.contains('.date-and-privacy', 'On Wednesday, September 15, 2021 from');
cy.contains('.visibility .tag', 'Public event');
cy.contains('.navbar-item', 'My events').click();
cy.contains('.title', EVENT.title);
cy.contains('.content.column', 'You\'re organizing this event');
cy.contains('.title-wrapper .date-component .datetime-container .month', 'Sep');
cy.contains('.title-wrapper .date-component .datetime-container .day', '15');
});
});

View File

@@ -1,11 +1,7 @@
import { onBeforeLoad } from './browser-language';
beforeEach(() => {
cy.restoreLocalStorage();
});
afterEach(() => {
cy.saveLocalStorage();
cy.clearLocalStorage();
});
describe('Login', () => {
@@ -42,4 +38,46 @@ describe('Login', () => {
cy.contains('.message.is-danger', 'User with email not found');
});
it('Tries to login with valid credentials', () => {
cy.visit('/login', { onBeforeLoad });
cy.get('input[type=email]').type('user@email.com');
cy.get('input[type=password]').type('some password');
cy.get('form').submit();
cy.contains('.navbar-link', 'test_user');
cy.contains('article.message.is-info', 'Welcome back I\'m a test user');
cy.contains('.navbar-item.has-dropdown', 'test_user').click();
cy.get('.navbar-item').last().contains('Log out').click();
});
it('Tries to login with valid credentials but unconfirmed account', () => {
cy.visit('/login', { onBeforeLoad });
cy.get('input[type=email]').type('unconfirmed@email.com');
cy.get('input[type=password]').type('some password');
cy.get('form').submit();
cy.contains('.message.is-danger', 'User with email not found');
});
it('Tries to login with valid credentials, confirmed account but no profile', () => {
cy.visit('/login', { onBeforeLoad });
cy.get('input[type=email]').type('confirmed@email.com');
cy.get('input[type=password]').type('some password');
cy.get('form').submit();
cy.contains('.message', 'To achieve your registration, please create a first identity profile.');
cy.get('form .field').first().contains('label', 'Username').parent().find('input').type('test_user');
cy.get('form .field').eq(2).contains('label', 'Displayed name').parent().find('input').type('Duplicate');
cy.get('form .field').eq(3).contains('label', 'Description').parent().find('textarea').type('This shouln\'t work because it\' using a dupublicated username');
cy.get('.control.has-text-centered').contains('button', 'Create my profile').click();
cy.contains('.help.is-danger', 'Username is already taken');
cy.get('form .field input').first(0).clear().type('test_user_2');
cy.get('form .field input').eq(1).type('Not');
cy.get('form .field textarea').clear().type('This will now work');
cy.get('form').submit();
cy.wait(1000);
cy.contains('.navbar-link', 'test_user_2');
cy.contains('article.message.is-info', 'Welcome back DuplicateNot');
});
});

View File

@@ -1,12 +1,10 @@
import { onBeforeLoad } from './browser-language';
beforeEach(() => {
cy.restoreLocalStorage();
cy.checkoutSession();
});
afterEach(() => {
cy.saveLocalStorage();
cy.dropSession();
});
@@ -34,7 +32,7 @@ describe('Registration', () => {
it('Tests that registration works', () => {
cy.visit('/register/user', { onBeforeLoad });
cy.get('input[type=email]').type('user@email.com');
cy.get('input[type=email]').type('user2register@email.com');
cy.get('input[type=password]').type('userPassword');
cy.get('form').contains('button.button.is-primary', 'Register').click();
@@ -45,7 +43,7 @@ describe('Registration', () => {
cy.get('form .field').eq(3).contains('label', 'Description').parent().find('textarea').type('This is a test account');
cy.get('.control.has-text-centered').contains('button', 'Create my profile').click();
cy.contains('article.message.is-success', 'Your account is nearly ready, tester').contains('A validation email was sent to user@email.com');
cy.contains('article.message.is-success', 'Your account is nearly ready, tester').contains('A validation email was sent to user2register@email.com');
cy.visit('/sent_emails');

View File

@@ -24,6 +24,14 @@
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
const AUTH_ACCESS_TOKEN = 'auth-access-token';
const AUTH_REFRESH_TOKEN = 'auth-refresh-token';
const AUTH_USER_ID = 'auth-user-id';
const AUTH_USER_EMAIL = 'auth-user-email';
const AUTH_USER_ACTOR_ID = 'auth-user-actor-id';
const AUTH_USER_ROLE = 'auth-user-role';
let LOCAL_STORAGE_MEMORY = {};
Cypress.Commands.add("saveLocalStorage", () => {
@@ -38,6 +46,54 @@ Cypress.Commands.add("restoreLocalStorage", () => {
});
});
Cypress.Commands.add("clearLocalStorage", () => {
Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
localStorage.removeItem(key);
});
});
Cypress.Commands.add("loginUser", () => {
const loginMutation = `
mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
accessToken,
refreshToken,
user {
id,
email,
role
}
},
}`;
const body = JSON.stringify({
operationName: 'Login',
query: loginMutation,
variables: { email: 'user@email.com', password: 'some password' }
});
cy.request({
url: 'http://localhost:4000/api',
body: body,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
}).then((res) => {
console.log(res);
const obj = res.body.data.login;
console.log(obj);
localStorage.setItem(AUTH_USER_ID, `${obj.user.id}`);
localStorage.setItem(AUTH_USER_EMAIL, obj.user.email);
localStorage.setItem(AUTH_USER_ROLE, obj.user.role);
localStorage.setItem(AUTH_USER_ACTOR_ID, `${obj.id}`);
localStorage.setItem(AUTH_ACCESS_TOKEN, obj.accessToken);
localStorage.setItem(AUTH_REFRESH_TOKEN, obj.refreshToken);
});
});
Cypress.Commands.add('checkoutSession', async () => {
const response = await fetch('/sandbox', {
cache: 'no-store',