strapi/test/helpers/auth.js

45 lines
783 B
JavaScript
Raw Normal View History

const { createRequest } = require('./request');
2018-07-19 14:46:03 +02:00
const auth = {
username: 'admin',
email: 'admin@strapi.io',
2019-03-08 17:54:45 +01:00
password: 'pcw123',
2018-07-19 14:46:03 +02:00
};
const rq = createRequest();
2019-03-08 17:54:45 +01:00
2019-05-06 15:33:25 +02:00
const register = async () => {
await rq({
url: '/admin/auth/local/register',
method: 'POST',
body: auth,
}).catch(err => {
if (err.error.message.includes("You can't register a new admin")) return;
throw err;
});
};
const login = async () => {
const { body } = await rq({
url: '/admin/auth/local',
method: 'POST',
body: {
identifier: auth.email,
password: auth.password,
},
});
return body;
};
2018-07-19 14:46:03 +02:00
module.exports = {
2019-05-06 15:33:25 +02:00
async registerAndLogin() {
// register
await register();
2019-03-09 01:06:39 +01:00
2019-05-06 15:33:25 +02:00
// login
const { jwt } = await login();
return jwt;
2019-03-08 17:54:45 +01:00
},
2018-07-19 14:46:03 +02:00
};