Skip to content

Commit

Permalink
Reworked headlessCreateUser command in Cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Jan 21, 2025
1 parent 5d69c7e commit 071c68a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ context('Basic markdown pipeline', () => {
let assetID = null;

before(() => {
cy.headlessLogout();
cy.visit('/');
cy.get('.cvat-login-form-wrapper').should('exist').and('be.visible');

for (const user of Object.values(additionalUsers)) {
cy.headlessCreateUser(user);
cy.headlessLogout();
}

cy.login();
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/e2e/actions_users/issue_1810_login_logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ context('When clicking on the Logout button, get the user session closed.', () =

before(() => {
cy.headlessLogout();
cy.visit('auth/login');
cy.visit('/');
});

describe(`Testing issue "${issueId}"`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ context('Review pipeline feature', () => {

before(() => {
cy.headlessLogout();

cy.visit('auth/login');
cy.get('.cvat-login-form-wrapper').should('exist').and('be.visible');
cy.visit('/');

// register additional users
cy.headlessLogout();
for (const user of Object.values(additionalUsers)) {
cy.headlessCreateUser(user);
cy.headlessLogout();
}

// create main task
Expand Down
45 changes: 24 additions & 21 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,29 +344,32 @@ Cypress.Commands.add('headlessDeleteTask', (taskID) => {
});
});

Cypress.Commands.add('headlessCreateUser', (userSpec) => (
cy.request({
method: 'POST',
url: '/api/auth/register',
body: {
confirmations: [],
password1: userSpec.password,
password2: userSpec.password,
email: userSpec.email,
first_name: userSpec.firstName,
last_name: userSpec.lastName,
username: userSpec.username,
},
headers: {
'Content-type': 'application/json',
},
}).then((response) => {
expect(response.status).to.eq(201);
Cypress.Commands.add('headlessCreateUser', (userSpec) => {
cy.intercept('POST', '/api/auth/register**', (req) => {
req.continue((res) => {
delete res.headers['set-cookie'];
});
}).as('registerRequest');

cy.window().then(async ($win) => {
await $win.cvat.server.register(
userSpec.username,
userSpec.firstName,
userSpec.lastName,
userSpec.email,
userSpec.password,
[],
);
return cy.wrap();
});

cy.wait('@registerRequest').then((interception) => {
const { response } = interception;
expect(response.statusCode).to.eq(201);
expect(response.body.username).to.eq(userSpec.username);
expect(response.body.email).to.eq(userSpec.email);
return cy.wrap();
})
));
});
});

Cypress.Commands.add('headlessLogout', () => {
cy.clearCookies();
Expand Down

0 comments on commit 071c68a

Please sign in to comment.