strapi/test/helpers/auth.js
Alexandre Bodin 07e7cfc0bd Make lint stricter and fix the errors
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-11-02 19:41:42 +01:00

60 lines
1006 B
JavaScript

'use strict';
const { createRequest } = require('./request');
const auth = {
email: 'admin@strapi.io',
firstname: 'admin',
lastname: 'admin',
password: 'Password123',
};
const rq = createRequest();
const register = async () => {
await rq({
url: '/admin/register-admin',
method: 'POST',
body: auth,
}).catch(err => {
console.error(err);
if (err.message === 'You cannot register a new super admin') return;
throw err;
});
};
const login = async () => {
const { body } = await rq({
url: '/admin/login',
method: 'POST',
body: {
email: auth.email,
password: auth.password,
},
});
return body.data;
};
module.exports = {
async registerAndLogin() {
// register
await register();
// login
const res = await login();
return res && res.token;
},
async login() {
const res = await login();
return res && res.token;
},
async getUser() {
const res = await login();
return res.user;
},
};