Cover oauth with e2e tests and fix some old and newly introduced bugs

This commit is contained in:
SleepWalker
2019-12-26 14:18:58 +02:00
parent 8e95fd835e
commit d9fc503f9e
21 changed files with 538 additions and 169 deletions

View File

@@ -31,40 +31,52 @@ const accountsMap = {
default2: account1,
};
Cypress.Commands.add('login', async ({ account }) => {
let credentials;
Cypress.Commands.add('login', async ({ accounts }) => {
const accountsData = await Promise.all(
accounts.map(async account => {
let credentials;
if (account) {
credentials = accountsMap[account];
if (account) {
credentials = accountsMap[account];
if (!credentials) {
throw new Error(`Unknown account name: ${account}`);
}
}
if (!credentials) {
throw new Error(`Unknown account name: ${account}`);
}
}
const resp = await fetch('/api/authentication/login', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: `login=${credentials.login}&password=${credentials.password}&rememberMe=1`,
}).then(resp => resp.json());
const resp = await fetch('/api/authentication/login', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: `${new URLSearchParams({
login: credentials.login,
password: credentials.password,
rememberMe: '1',
})}`,
}).then(rawResp => rawResp.json());
const state = createState([
{
id: credentials.id,
username: credentials.username,
email: credentials.email,
token: resp.access_token,
refreshToken: resp.refresh_token,
},
]);
return {
id: credentials.id,
username: credentials.username,
email: credentials.email,
token: resp.access_token,
refreshToken: resp.refresh_token,
};
}),
);
const state = createState(accountsData);
localStorage.setItem('redux-storage', JSON.stringify(state));
return state;
return { accounts: accountsData };
});
Cypress.Commands.add('getByTestId', (id, options) =>
cy.get(`[data-testid=${id}]`, options),
);
function createState(accounts) {
return {
accounts: {