-
Notifications
You must be signed in to change notification settings - Fork 39
/
e2e.user.js
51 lines (46 loc) · 1.63 KB
/
e2e.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// API mock for user.service.js
userServiceMock.$inject = ['MockData', '$httpBackend'];
function userServiceMock (MockData, $httpBackend) {
$httpBackend.whenGET('api/user/loginstatus').respond(loginStatusHandler);
$httpBackend.whenPOST('api/user/login').respond(loginHandler);
$httpBackend.whenPOST('api/user/logout').respond(logoutHandler);
$httpBackend.whenGET('api/user/products').respond(productsHandler);
function loginStatusHandler () {
const code = MockData.loginStatus ? 0 : 1;
const result = MockData.loginStatus ? {user: MockData.userInfo} : null;
return [200, {code, message: null, result}];
}
function loginHandler (method, url, data) {
const req = JSON.parse(data);
if (req.email === 'error@error.com') {
return [200, {
code: 1,
message: 'LOGIN_WRONG_EMAIL_PASSWORD_PAIR',
result: null
}];
} else if (req.email === 'lock@lock.com') {
return [200, {
code: 1,
message: 'LOGIN_USER_IN_LOCK',
result: null
}];
}
MockData.loginStatus = true;
return [200, {
code: 0, message: null,
result: {
user: MockData.userInfo
}
}];
}
function logoutHandler () {
MockData.loginStatus = false;
return [200, {code: 0, message: null, result: null}];
}
function productsHandler () {
return [200, {code: 0, message: null, result: {
summary: MockData.userProducts
}}];
}
}
export default userServiceMock;