Skip to content

Commit 02c5ed0

Browse files
committed
TEST: user card feature
1 parent 3587782 commit 02c5ed0

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

test/userInfo_test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import expect from 'expect';
2+
3+
import { LoginService } from '../services/LoginService';
4+
import { Credentials } from '../models/auth/Credentials';
5+
import { UserInfoService } from '../services/UserInfoService';
6+
7+
Feature('User info card');
8+
9+
const loginService = new LoginService();
10+
const userInfoService = new UserInfoService();
11+
12+
const validUser: Credentials = {
13+
username: 'valid.user@example.com',
14+
password: 'validPassword',
15+
};
16+
17+
BeforeSuite(async () => {
18+
const { token } = await loginService.getToken(validUser);
19+
userInfoService.token = token;
20+
});
21+
22+
Scenario('/userInfo should return user card', async () => {
23+
await userInfoService.requestGetUserInfo();
24+
25+
expect(userInfoService.response.status).toBe(200);
26+
expect(userInfoService.response.data).not.toBeUndefined();
27+
expect(userInfoService.response.data.id).toBe(1234);
28+
expect(userInfoService.response.data.first_name).toEqual('User');
29+
expect(userInfoService.response.data.last_name).toEqual('Valid');
30+
expect(userInfoService.response.data.email).toEqual('valid.user@example.com');
31+
});
32+
33+
Scenario('/userInfo unauthorized should return error', async () => {
34+
const unauthorizedUserInfoService = new UserInfoService();
35+
unauthorizedUserInfoService.token = 'unauthorized';
36+
37+
try {
38+
await unauthorizedUserInfoService.requestGetUserInfo();
39+
} catch (e) {
40+
const { response } = e;
41+
42+
expect(response.status).toBe(401);
43+
expect(response.data.error).toEqual('Not valid authorization token');
44+
}
45+
});

0 commit comments

Comments
 (0)