Skip to content

Commit 4a07bf6

Browse files
committed
Added users cypress tests
1 parent 5be46b4 commit 4a07bf6

File tree

3 files changed

+56
-60
lines changed

3 files changed

+56
-60
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('Users endpoints', () => {
4+
let token;
5+
6+
before(() => {
7+
cy.getToken().then((tok) => {
8+
token = tok;
9+
});
10+
});
11+
12+
it('Should be able to get yourself', function() {
13+
cy.task('backendApiGet', {
14+
token: token,
15+
path: '/api/users/me'
16+
}).then((data) => {
17+
cy.validateSwaggerSchema('get', 200, '/users/{userID}', data);
18+
expect(data).to.have.property('id');
19+
expect(data.id).to.be.greaterThan(0);
20+
});
21+
});
22+
23+
it('Should be able to get all users', function() {
24+
cy.task('backendApiGet', {
25+
token: token,
26+
path: '/api/users'
27+
}).then((data) => {
28+
cy.validateSwaggerSchema('get', 200, '/users', data);
29+
expect(typeof data).to.be.equal('array');
30+
expect(data.length).to.be.greaterThan(0);
31+
});
32+
});
33+
34+
it('Should be able to update yourself', function() {
35+
cy.task('backendApiPut', {
36+
token: token,
37+
path: '/api/users/me',
38+
data: {
39+
name: 'changed name'
40+
}
41+
}).then((data) => {
42+
cy.validateSwaggerSchema('put', 200, '/users/{userID}', data);
43+
expect(data).to.have.property('id');
44+
expect(data.id).to.be.greaterThan(0);
45+
expect(data.name).to.be.equal('changed name');
46+
});
47+
});
48+
49+
});

test/cypress/support/commands.js

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,67 +28,14 @@ Cypress.Commands.add('validateSwaggerSchema', (method, path, data) => {
2828
});
2929

3030
Cypress.Commands.add('getToken', () => {
31-
cy.task('backendApiGet', {
32-
path: '/api/',
33-
}).then((data) => {
34-
// Check the swagger schema:
35-
cy.task('validateSwaggerSchema', {
36-
endpoint: '/',
37-
method: 'get',
38-
statusCode: 200,
39-
responseSchema: data,
40-
verbose: true,
41-
}).should('equal', null);
42-
43-
if (!data.result.setup) {
44-
cy.log('Setup = false');
45-
// create a new user
46-
cy.createInitialUser().then(() => {
47-
return cy.getToken();
48-
});
49-
} else {
50-
cy.log('Setup = true');
51-
// login with existing user
52-
cy.task('backendApiPost', {
53-
path: '/api/tokens',
54-
data: {
55-
type: 'password',
56-
identity: '[email protected]',
57-
secret: 'changeme'
58-
}
59-
}).then(res => {
60-
cy.wrap(res.result.token);
61-
});
62-
}
63-
});
64-
});
65-
66-
Cypress.Commands.add('createInitialUser', () => {
67-
return cy.task('backendApiPost', {
68-
path: '/api/users',
31+
// login with existing user
32+
cy.task('backendApiPost', {
33+
path: '/api/tokens',
6934
data: {
70-
name: 'Jamie Curnow',
71-
nickname: 'James',
72-
73-
roles: [],
74-
is_disabled: false,
75-
auth: {
76-
type: 'password',
77-
secret: 'changeme'
78-
}
35+
identity: "[email protected]",
36+
secret: "changeme"
7937
}
80-
}).then((data) => {
81-
// Check the swagger schema:
82-
cy.task('validateSwaggerSchema', {
83-
endpoint: '/users',
84-
method: 'post',
85-
statusCode: 201,
86-
responseSchema: data,
87-
verbose: true
88-
}).should('equal', null);
89-
90-
expect(data.result).to.have.property('id');
91-
expect(data.result.id).to.be.greaterThan(0);
92-
cy.wrap(data.result);
38+
}).then(res => {
39+
cy.wrap(res.result.token);
9340
});
9441
});

0 commit comments

Comments
 (0)