Repository navigation
Expand file tree
/
Copy pathpm.test.js
More file actions
163 lines (138 loc) · 4.2 KB
/
Copy pathpm.test.js
File metadata and controls
163 lines (138 loc) · 4.2 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { PM } from './pm.js'
test('status code is 200', () => {
let pm = new PM();
pm.response.actualStatusValue = 200;
pm.test('status code is 200', function() {
pm.response.to.have.status(200);
})
});
test('status code is NOT 200', () => {
let pm = new PM();
pm.response.actualStatusValue = 404;
expect(() => {
pm.test('status code is 200', function() {
pm.response.to.have.status(200);
});
}).toThrow();
});
test('should return a user ID', () => {
let pm = new PM();
let jsonData = {
id: 1,
username: 'bob',
password: 'testpassword',
avatar: 'testavatar'
};
pm.test('should return a user ID', function() {
pm.expect(jsonData).to.have.property('id');
pm.expect(jsonData.id).not.to.be.empty;
});
});
test('should understand types', ()=> {
let pm = new PM();;
let jsonData = {
username: 'Bob',
score: 12345
};
pm.test('should be a number', ()=> {
pm.expect(jsonData.score).to.be.type('number');
pm.expect(jsonData.username).to.be.type('string');
});
});
test('should understand when types dont match', ()=> {
let pm = new PM();
let jsonData = {
username: 'Bob',
score: '12345' // a string
};
expect(()=>{
pm.test('should be a number', ()=> {
pm.expect(jsonData.score).to.be.type('number');
});
}).toThrow();
});
test('cant compare types when undefined', ()=> {
let pm = new PM();
let jsonData = undefined;
expect(()=>{
pm.test('should be a number', ()=> {
pm.expect(jsonData).to.be.type('number');
});
}).toThrow();
});
test('failed to return anything results in error', ()=> {
let pm = new PM();
expect(() => {
pm.test('should not have a value', ()=> {
pm.expect(undefined).to.have.property('id');
});
}).toThrow();
});
test('failed to return anything results in error', ()=> {
let pm = new PM();
let jsonData = {};
expect(() => {
pm.test('should not have a value', ()=> {
pm.expect(jsonData).to.have.property('id');
});
}).toThrow();
});
test('should return the username', ()=> {
let pm = new PM();
pm.environment.set("testUser", "testdood");
let jsonData = { username: "testdood"};
pm.test('should return username', ()=> {
pm.expect(jsonData).to.have.property('username');
pm.expect(jsonData.username).to.equal(pm.environment.get('testUser'));
})
});
test('failed to return username', ()=>{
let pm = new PM();
pm.environment.set('testUser', 'otherdood');
let jsonData = { username: 'testdood'};
expect(()=> {
pm.test('should fail', ()=> {
pm.expect(jsonData.username).to.equal(pm.environment.get('testUser'));
})
}).toThrow();
});
test('id is not same as username', ()=> {
let pm = new PM();
let jsonData = { username: "username", id: "somethingElse"};
pm.test('id not same as username', ()=> {
pm.expect('a').to.not.equal('b');
});
});
test('id is same as username', ()=> {
let pm = new PM();
let jsonData = { username: "a", id: "a"};
expect(()=> {
pm.test('id should not be same as username', ()=> {
pm.expect(jsonData.username).to.not.equal(jsonData.id);
});
}).toThrow();
});
test('id is not same as password', ()=>{
let pm = new PM();
let jsonData = { id: 'a', password: 'b' };
pm.test('id should not be same as password', ()=> {
pm.expect(jsonData.password).to.not.equal(jsonData.id);
});
});
test('id is same as password', ()=>{
let pm = new PM();
let jsonData = { id: 'a', password: 'a' };
expect(()=>{
pm.test('id should not be same as password', ()=> {
pm.expect(jsonData.password).to.not.equal(jsonData.id);
});
}).toThrow();
});
test('user id and session should not be same', ()=> {
let pm = new PM();
pm.environment.set("userId", "userId");
let jsonData = { session: "sessionId"};
pm.test('user ID and session should not be the same', ()=> {
pm.expect(jsonData.session).to.not.be.equal(pm.environment.get('userId'));
})
});