mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Upgrade cypress to the latest version and configure it to support ts
This commit is contained in:
93
tests-e2e/cypress/support/commands.js
Normal file
93
tests-e2e/cypress/support/commands.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import { account1, account2 } from '../fixtures/accounts';
|
||||
|
||||
// ***********************************************
|
||||
// This example commands.js shows you how to
|
||||
// create various custom commands and overwrite
|
||||
// existing commands.
|
||||
//
|
||||
// For more comprehensive examples of custom
|
||||
// commands please read more here:
|
||||
// https://on.cypress.io/custom-commands
|
||||
// ***********************************************
|
||||
//
|
||||
//
|
||||
// -- This is a parent command --
|
||||
// Cypress.Commands.add("login", (email, password) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is a child command --
|
||||
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is a dual command --
|
||||
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
||||
//
|
||||
//
|
||||
// -- This is will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
||||
|
||||
const accountsMap = {
|
||||
default: account2,
|
||||
default2: account1,
|
||||
};
|
||||
|
||||
Cypress.Commands.add('login', async ({ account }) => {
|
||||
let credentials;
|
||||
|
||||
if (account) {
|
||||
credentials = accountsMap[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 state = createState([
|
||||
{
|
||||
id: credentials.id,
|
||||
username: credentials.username,
|
||||
email: credentials.email,
|
||||
token: resp.access_token,
|
||||
refreshToken: resp.refresh_token,
|
||||
},
|
||||
]);
|
||||
|
||||
localStorage.setItem('redux-storage', JSON.stringify(state));
|
||||
|
||||
return state;
|
||||
});
|
||||
|
||||
function createState(accounts) {
|
||||
return {
|
||||
accounts: {
|
||||
available: accounts,
|
||||
active: accounts[0].id,
|
||||
},
|
||||
user: {
|
||||
id: 102,
|
||||
uuid: 'e49cafdc-6e0c-442d-b608-dacdb864ee34',
|
||||
username: 'test',
|
||||
token: '',
|
||||
email: 'admin@udf.su',
|
||||
maskedEmail: '',
|
||||
avatar: '',
|
||||
lang: 'en',
|
||||
isActive: true,
|
||||
isOtpEnabled: true,
|
||||
shouldAcceptRules: false,
|
||||
passwordChangedAt: 1478961317,
|
||||
hasMojangUsernameCollision: true,
|
||||
isGuest: false,
|
||||
registeredAt: 1478961317,
|
||||
elyProfileLink: 'http://ely.by/u102',
|
||||
},
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user