50 lines
1.4 KiB
JavaScript
Raw Normal View History

const frontLoadingDelay = Cypress.config('frontLoadingDelay');
const registerData = {
2018-11-27 14:13:07 +01:00
username: 'admin',
email: 'admin@strapi.io',
password: 'pcw123',
confirmPassword: 'pcw123',
};
let jwt;
let userId;
const frontEndUrl = Cypress.config('baseUrl');
describe('Test register page', () => {
after(() => {
if (userId) {
cy.deleteUser(userId, jwt);
}
2018-11-27 14:13:07 +01:00
});
it('Visits /admin and should be redirected to register page', () => {
2018-11-27 14:13:07 +01:00
cy.visit('/admin').wait(frontLoadingDelay);
// Check if the user is being redirected to /register
2018-11-27 14:13:07 +01:00
cy.url().should('include', '/users-permissions/auth/register');
});
it('Should redirect to /register when trying to hit /login', () => {
2018-11-27 14:13:07 +01:00
cy.visit('/admin/plugins/users-permissions/auth/login').wait(frontLoadingDelay);
2018-11-27 14:13:07 +01:00
cy.url().should('include', '/users-permissions/auth/register');
});
it('Should register the admin user', () => {
Object.keys(registerData).map(key => {
2018-11-27 14:13:07 +01:00
return cy.get(`#${key}`).type(registerData[key]);
});
// Submit form
cy.submitForm()
.window()
.should(win => {
const userInfo = JSON.parse(win.sessionStorage.getItem('userInfo'));
2018-11-27 14:13:07 +01:00
jwt = JSON.parse(win.sessionStorage.getItem('jwtToken'));
userId = userInfo._id || userInfo.id;
expect(win.sessionStorage.getItem('jwtToken')).to.be.ok;
});
2018-11-27 14:13:07 +01:00
cy.url().should('equal', `${frontEndUrl}/admin/`);
});
2018-11-27 14:13:07 +01:00
});