mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Fix PR feedback
This commit is contained in:
parent
0aa7796a82
commit
685c39f0cf
@ -29,14 +29,17 @@ const serverRestartDelay = Cypress.config('serverRestartDelay');
|
||||
|
||||
Cypress.Commands.add('createUser', () => {
|
||||
const user = {
|
||||
username: 'soup',
|
||||
email: 'hi@strapi.io',
|
||||
password: 'coucou123',
|
||||
username: 'admin',
|
||||
email: 'admin@strapi.io',
|
||||
password: 'pcw123',
|
||||
};
|
||||
|
||||
return cy.request({ url: `${backendUrl}/users-permissions/init`, method: 'GET' })
|
||||
return cy
|
||||
.request({ url: `${backendUrl}/users-permissions/init`, method: 'GET' })
|
||||
.then(response => {
|
||||
const { body: { hasAdmin } } = response;
|
||||
const {
|
||||
body: { hasAdmin },
|
||||
} = response;
|
||||
|
||||
if (!hasAdmin) {
|
||||
// Create one
|
||||
@ -47,44 +50,44 @@ Cypress.Commands.add('createUser', () => {
|
||||
|
||||
Cypress.Commands.add('checkModalOpening', () => {
|
||||
return cy.get('.modal').invoke('show');
|
||||
})
|
||||
});
|
||||
|
||||
Cypress.Commands.add('deleteUser', (id, jwt) => {
|
||||
cy.request({
|
||||
url: `${backendUrl}/users/${id}`,
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`
|
||||
}
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('createProductAndTagApis', (jwt = null) => {
|
||||
return cy
|
||||
.fixture('api/tag.json')
|
||||
.then(body => {
|
||||
return cy.request({
|
||||
return cy.fixture('api/tag.json').then(body => {
|
||||
return cy
|
||||
.request({
|
||||
url: `${backendUrl}/content-type-builder/models`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body,
|
||||
})
|
||||
.wait(serverRestartDelay)
|
||||
.fixture('api/product.json')
|
||||
.then(body => {
|
||||
return cy.request({
|
||||
url: `${backendUrl}/content-type-builder/models`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`
|
||||
},
|
||||
body,
|
||||
})
|
||||
.wait(serverRestartDelay);
|
||||
return cy
|
||||
.request({
|
||||
url: `${backendUrl}/content-type-builder/models`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body,
|
||||
})
|
||||
.wait(serverRestartDelay);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('createCTMApis', (jwt = null) => {
|
||||
@ -114,8 +117,7 @@ Cypress.Commands.add('deleteAllModelData', (model, jwt, source = null) => {
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
})
|
||||
.then(data => {
|
||||
}).then(data => {
|
||||
const entriesToDelete = data.body.reduce((acc, curr) => {
|
||||
return acc.concat(curr.id);
|
||||
}, []);
|
||||
@ -134,51 +136,51 @@ Cypress.Commands.add('deleteAllModelData', (model, jwt, source = null) => {
|
||||
});
|
||||
|
||||
Cypress.Commands.add('deleteApi', (model, jwt) => {
|
||||
return cy.request({
|
||||
url: `${backendUrl}/content-type-builder/models/${model}`,
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`
|
||||
},
|
||||
})
|
||||
.wait(serverRestartDelay);
|
||||
return cy
|
||||
.request({
|
||||
url: `${backendUrl}/content-type-builder/models/${model}`,
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
})
|
||||
.wait(serverRestartDelay);
|
||||
});
|
||||
|
||||
Cypress.Commands.add('login', () => {
|
||||
cy.createUser()
|
||||
return cy.request({
|
||||
url: `${backendUrl}/auth/local`,
|
||||
method: 'POST',
|
||||
body: {
|
||||
identifier: 'soup',
|
||||
password: 'coucou123',
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
window.localStorage.setItem('jwtToken', stringify(response.body.jwt));
|
||||
window.localStorage.setItem('userInfo', stringify(response.body.user));
|
||||
cy.createUser();
|
||||
return cy
|
||||
.request({
|
||||
url: `${backendUrl}/auth/local`,
|
||||
method: 'POST',
|
||||
body: {
|
||||
identifier: 'admin',
|
||||
password: 'pcw123',
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
window.localStorage.setItem('jwtToken', stringify(response.body.jwt));
|
||||
window.localStorage.setItem('userInfo', stringify(response.body.user));
|
||||
|
||||
return response.body;
|
||||
})
|
||||
return response.body;
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('seedData', (model, jwt, source = null) => {
|
||||
return cy
|
||||
.fixture(`seeds/${model}.json`)
|
||||
.then(seed => {
|
||||
seed.forEach(body => {
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `${backendUrl}/content-manager/explorer/${model}?source='content-manager`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body,
|
||||
});
|
||||
return cy.fixture(`seeds/${model}.json`).then(seed => {
|
||||
seed.forEach(body => {
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `${backendUrl}/content-manager/explorer/${model}?source='content-manager`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('submitForm', () => {
|
||||
return cy.get('form').submit();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
{
|
||||
"private": true,
|
||||
"version": "3.0.0-alpha.14.5",
|
||||
"dependencies": {
|
||||
"cypress": "^3.1.2"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"assert": "~1.3.0",
|
||||
"axios": "^0.18.0",
|
||||
"babel-eslint": "^6.1.2",
|
||||
"chalk": "^2.4.1",
|
||||
"cypress": "^3.1.2",
|
||||
"eslint": "^4.19.1",
|
||||
"eslint-plugin-babel": "^4.0.0",
|
||||
"eslint-plugin-react": "^7.7.0",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
const frontLoadingDelay = Cypress.config('frontLoadingDelay');
|
||||
const userData = {
|
||||
identifier: 'soup',
|
||||
password: 'coucou123',
|
||||
identifier: 'admin',
|
||||
password: 'pcw123',
|
||||
};
|
||||
|
||||
describe('Test login', () => {
|
||||
@ -19,19 +19,13 @@ describe('Test login', () => {
|
||||
cy.deleteUser(userId, jwt);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
it('Should login the user', () => {
|
||||
cy.visit('/admin/users-permissions/auth/login')
|
||||
.wait(frontLoadingDelay);
|
||||
cy.visit('/admin/users-permissions/auth/login').wait(frontLoadingDelay);
|
||||
|
||||
Object
|
||||
.keys(userData)
|
||||
.map(key => {
|
||||
return cy
|
||||
.get(`#${key}`)
|
||||
.type(userData[key]);
|
||||
});
|
||||
Object.keys(userData).map(key => {
|
||||
return cy.get(`#${key}`).type(userData[key]);
|
||||
});
|
||||
|
||||
cy.submitForm()
|
||||
.window()
|
||||
@ -42,8 +36,7 @@ describe('Test login', () => {
|
||||
userId = userInfo._id || userInfo.id;
|
||||
expect(win.localStorage.getItem('jwtToken')).to.be.ok;
|
||||
});
|
||||
|
||||
cy.url()
|
||||
.should('equal', `${Cypress.config('baseUrl')}/admin/`);
|
||||
|
||||
cy.url().should('equal', `${Cypress.config('baseUrl')}/admin/`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
const frontLoadingDelay = Cypress.config('frontLoadingDelay');
|
||||
const registerData = {
|
||||
username: 'soup',
|
||||
email: 'hi@strapi.io',
|
||||
password: 'coucou123',
|
||||
confirmPassword: 'coucou123',
|
||||
username: 'admin',
|
||||
email: 'admin@strapi.io',
|
||||
password: 'pcw123',
|
||||
confirmPassword: 'pcw123',
|
||||
};
|
||||
let jwt;
|
||||
let userId;
|
||||
@ -14,30 +14,24 @@ describe('Test register page', () => {
|
||||
if (userId) {
|
||||
cy.deleteUser(userId, jwt);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
it('Visits /admin and should be redirected to register page', () => {
|
||||
cy.visit('/admin')
|
||||
.wait(frontLoadingDelay);
|
||||
cy.visit('/admin').wait(frontLoadingDelay);
|
||||
|
||||
// Check if the user is being redirected to /register
|
||||
cy.url()
|
||||
.should('include', '/users-permissions/auth/register');
|
||||
cy.url().should('include', '/users-permissions/auth/register');
|
||||
});
|
||||
|
||||
it('Should redirect to /register when trying to hit /login', () => {
|
||||
cy.visit('/admin/plugins/users-permissions/auth/login')
|
||||
.wait(frontLoadingDelay);
|
||||
cy.visit('/admin/plugins/users-permissions/auth/login').wait(frontLoadingDelay);
|
||||
|
||||
cy.url()
|
||||
.should('include', '/users-permissions/auth/register');
|
||||
cy.url().should('include', '/users-permissions/auth/register');
|
||||
});
|
||||
|
||||
it('Should register the admin user', () => {
|
||||
Object.keys(registerData).map(key => {
|
||||
return cy
|
||||
.get(`#${key}`)
|
||||
.type(registerData[key]);
|
||||
return cy.get(`#${key}`).type(registerData[key]);
|
||||
});
|
||||
|
||||
// Submit form
|
||||
@ -45,12 +39,11 @@ describe('Test register page', () => {
|
||||
.window()
|
||||
.should(win => {
|
||||
const userInfo = JSON.parse(win.sessionStorage.getItem('userInfo'));
|
||||
|
||||
|
||||
jwt = JSON.parse(win.sessionStorage.getItem('jwtToken'));
|
||||
userId = userInfo._id || userInfo.id;
|
||||
expect(win.sessionStorage.getItem('jwtToken')).to.be.ok;
|
||||
});
|
||||
cy.url()
|
||||
.should('equal', `${frontEndUrl}/admin/`);
|
||||
cy.url().should('equal', `${frontEndUrl}/admin/`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -103,7 +103,7 @@ const main = async () => {
|
||||
|
||||
const cypressTest = () => {
|
||||
return cypress
|
||||
.run({ spec: './packages/**/cypress/integration/*' });
|
||||
.run({ spec: './packages/**/cypress/integration/*', browser: 'chrome' });
|
||||
}
|
||||
|
||||
const testProcess = async (database) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user