Skip to content

Commit

Permalink
Rework Cypress test "Register user, change password, login with new p…
Browse files Browse the repository at this point in the history
…assword". (#2933)

* Rework Cypress test "case 2".

* Add command to deleting a registered users.

* Tests adaptation.

* Update cypress command

* Test adaptation

* Apply comments.
  • Loading branch information
dvkruchinin committed Mar 12, 2021
1 parent ca97507 commit 86eef84
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

import { projectName } from '../../../support/const_project';

const randomString = (isPassword) => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
for (let i = 0; i <= 8; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return isPassword ? `${result}${Math.floor(Math.random() * 10)}` : result;
};

context('Base actions on the project', () => {
const labelName = `Base label for ${projectName}`;
const taskName = {
Expand Down Expand Up @@ -45,11 +36,11 @@ context('Base actions on the project', () => {
const newLabelName2 = `Second label ${projectName}`;
const newLabelName3 = `Third label ${projectName}`;
const newLabelName4 = `Fourth label ${projectName}`;
const firstName = `${randomString()}`;
const lastName = `${randomString()}`;
const userName = `${randomString()}`;
const firstName = 'Seconduser fm';
const lastName = 'Seconduser lm';
const userName = 'Seconduser';
const emailAddr = `${userName}@local.local`;
const password = `${randomString(true)}`;
const password = 'GDrb41RguF!';
let projectID = '';

function getProjectID(projectName) {
Expand All @@ -65,6 +56,10 @@ context('Base actions on the project', () => {
cy.openProject(projectName);
});

after(() => {
cy.deletingRegisteredUsers([userName]);
});

describe(`Testing "Base actions on the project"`, () => {
it('Add some labels to project.', () => {
cy.addNewLabel(newLabelName1);
Expand Down Expand Up @@ -125,7 +120,7 @@ context('Base actions on the project', () => {
cy.userRegistration(firstName, lastName, userName, emailAddr, password);
cy.goToProjectsList();
// tries to create project
const failProjectName = `${randomString()}`;
const failProjectName = 'failProject';
cy.createProjects(failProjectName, labelName, attrName, textDefaultValue, null, 'fail');
cy.closeNotification('.cvat-notification-notice-create-project-failed');
cy.goToProjectsList();
Expand Down Expand Up @@ -159,6 +154,7 @@ context('Base actions on the project', () => {
cy.goToTaskList();
cy.contains('strong', taskName.firstTask).should('not.exist');
cy.contains('strong', taskName.secondTask).should('not.exist');
cy.logout();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ context('Rename a task.', () => {
});

after(() => {
cy.deletingRegisteredUsers([secondUserName]);
cy.login();
cy.deleteTask(newNaskName);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ context('Review pipeline feature', () => {
after(() => {
cy.goToTaskList();
cy.deleteTask(taskName);
cy.logout();
cy.deletingRegisteredUsers([secondUserName, thirdUserName]);
});

describe(`Testing "${labelName}"`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

/// <reference types="cypress" />

const randomString = (isPassword) => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
for (let i = 0; i <= 8; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return isPassword ? `${result}${Math.floor(Math.random() * 10)}` : result;
};

context('Register user, change password, login with new password', () => {
const caseId = '2';
const firstName = `${randomString()}`;
const lastName = `${randomString()}`;
const userName = `${randomString()}`;
const firstName = 'SecuserfmCaseTwo';
const lastName = 'SecuserlmCaseTwo';
const userName = 'SecuserCase2';
const emailAddr = `${userName}@local.local`;
const password = `${randomString(true)}`;
const newPassword = `${randomString(true)}`;
const password = 'GDrb41RguF!';
const incorrectCurrentPassword = 'gDrb41RguF!';
const newPassword = 'bYdOk8#eEd';
const secondNewPassword = 'ndTh48@yVY';

function changePassword(userName, password, newPassword) {
cy.get('.cvat-right-header')
Expand All @@ -41,6 +34,12 @@ context('Register user, change password, login with new password', () => {
cy.url().should('include', '/auth/register');
});

after(() => {
cy.get('.cvat-modal-change-password').find('[aria-label="Close"]').click();
cy.logout(userName);
cy.deletingRegisteredUsers([userName]);
});

describe(`Testing "Case ${caseId}"`, () => {
it('Register user, change password', () => {
cy.userRegistration(firstName, lastName, userName, emailAddr, password);
Expand All @@ -55,7 +54,7 @@ context('Register user, change password, login with new password', () => {
cy.login(userName, newPassword);
});
it('Change password with incorrect current password', () => {
changePassword(userName, `${randomString(true)}`, newPassword);
changePassword(userName, incorrectCurrentPassword, secondNewPassword);
cy.get('.cvat-notification-notice-change-password-failed').should('exist');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ context('Multiple users. Assign task, job.', () => {
});

after(() => {
cy.deletingRegisteredUsers([secondUserName, thirdUserName]);
cy.login();
cy.deleteTask(taskName);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -16,6 +16,11 @@ context('Issue 1599 (Chinese alphabet).', () => {
cy.url().should('include', '/auth/register');
});

after(() => {
cy.logout(userName);
cy.deletingRegisteredUsers([userName]);
});

describe('User registration using the Chinese alphabet.', () => {
it('Filling in the placeholder "First name"', () => {
cy.get('[placeholder="First name"]').type(firstName).should('not.have.class', 'has-error');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -16,6 +16,11 @@ context('Issue 1599 (Polish alphabet).', () => {
cy.url().should('include', '/auth/register');
});

after(() => {
cy.logout(userName);
cy.deletingRegisteredUsers([userName]);
});

describe('User registration using the Polish alphabet.', () => {
it('Filling in the placeholder "First name"', () => {
cy.get('[placeholder="First name"]').type(firstName).should('not.have.class', 'has-error');
Expand Down
37 changes: 37 additions & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@ Cypress.Commands.add('userRegistration', (firstName, lastName, userName, emailAd
}
});

Cypress.Commands.add('deletingRegisteredUsers', (accountToDelete) => {
cy.request({
method: 'POST',
url: '/api/v1/auth/login',
body: {
username: Cypress.env('user'),
email: Cypress.env('email'),
password: Cypress.env('password'),
},
}).then((responce) => {
const authKey = responce['body']['key'];
cy.request({
url: '/api/v1/users?page_size=all',
headers: {
Authorization: `Token ${authKey}`,
},
}).then((responce) => {
const responceResult = responce['body']['results'];
for (const user of responceResult) {
const userId = user['id'];
const userName = user['username'];
for (const account of accountToDelete) {
if (userName === account) {
cy.request({
method: 'DELETE',
url: `/api/v1/users/${userId}`,
headers: {
Authorization: `Token ${authKey}`,
},
});
}
}
}
});
});
});

Cypress.Commands.add(
'createAnnotationTask',
(
Expand Down

0 comments on commit 86eef84

Please sign in to comment.