Skip to content

Commit

Permalink
User creation test (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
poflankov committed Sep 16, 2021
1 parent 4cebe0a commit b2258dd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cypress/integration/users/create-users.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
Pane,
including,
} from '../../../interactors';

describe('Creating user', () => {
const lastName = 'Test123' + Number(new Date()).toString();

before(() => {
cy.login('diku_admin', 'admin');
cy.getToken('diku_admin', 'admin');
});

beforeEach(() => {
cy.getUserGroups({ limit: 1 });
});

afterEach(() => {
cy.getUsers({ query: `personal.lastName="${lastName}"` })
.then(() => {
Cypress.env('users').forEach(user => {
cy.deleteUser(user.id);
});
});
});

it('should be possible by filling the "Create user" form and submitting it', function () {
const userGroupOption = Cypress.env('userGroups')[0].group + ' (' + Cypress.env('userGroups')[0].desc + ')';

cy.visit('/users/create');
cy.createUser(lastName, userGroupOption, 'test@folio.org');
cy.expect(Pane(including(lastName)).is({ visible: true, index: 2 }));
});
});
19 changes: 19 additions & 0 deletions cypress/support/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,22 @@ Cypress.Commands.add('getUserServicePoints', (userId) => {
Cypress.env('userServicePoints', body.servicePointsUsers);
});
});

Cypress.Commands.add('getUserGroups', (searchParams) => {
cy
.okapiRequest({
path: 'groups',
searchParams,
})
.then(({ body }) => {
Cypress.env('userGroups', body.usergroups);
});
});

Cypress.Commands.add('deleteUser', (userId) => {
cy
.okapiRequest({
method: 'DELETE',
path: `bl-users/by-id/${userId}`,
});
});
1 change: 1 addition & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import './checkin';
import './checkout';
import './eholdings';
import './inventory';
import './users';

bigtestGlobals.defaultInteractorTimeout = 10000;
10 changes: 10 additions & 0 deletions cypress/support/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Button, Select, TextField } from '../../interactors';

Cypress.Commands.add('createUser', (userLastName, patronGroup, email) => {
cy.do([
TextField({ id: 'adduser_lastname' }).fillIn(userLastName),
Select({ id: 'adduser_group' }).choose(patronGroup),
TextField({ id: 'adduser_email' }).fillIn(email),
Button({ id: 'clickable-save' }).click(),
]);
});

0 comments on commit b2258dd

Please sign in to comment.