-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
107 lines (91 loc) · 2.6 KB
/
index.test.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
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
const request = require('supertest');
const app = require('./index');
const root = "http://localhost:5000";
const fetch = require("node-fetch");
const assignmentsRoot = root+'/assignment';
const exampleAssignment = {
taskId: "1111",
assignmentId: "0",
workerId: "A1",
assignmentResult: {}
};
const postAssignments = function (newAssignment) {
console.log(assignmentsRoot);
console.log(newAssignment);
return fetch(assignmentsRoot, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(newAssignment)
});
};
const getAssignments = function(){
return fetch(assignmentsRoot, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
};
describe('Test POST Assignment', () => {
test('Post correct assignment', async () => {
return postAssignments(exampleAssignment)
/*.post('/assignment')
.send({
taskId: exampleAssignment.taskId,
workerId: exampleAssignment.workerId,
assignmentResult: exampleAssignment.assignmentResult
})*/
.then(response => {
console.log("res:" + response);
expect(response.status).toBe(200);
});
});
});
describe('Test DELETE Assignment', () => {
test('DELETE correct assignment', async () => {
return request(app)
.delete('/assignment/1')
.then(response => {
expect(response.statusCode).toBe(200);
});
});
});
describe('Test UPDATE Assignment', () => {
test('UPDATE correct assignment', async () => {
return request(app)
.put('/assignment/'+ exampleAssignment.assignmentId)
.send({
taskId: "Panciotto",
workerId: "Lagnotto",
assignmentResult: {}
})
.then(response => {
expect(response.statusCode).toBe(200);
});
});
test('UPDATE incorrect assignment', async () => {
return request(app)
.put('/assignment/5')
.then(response => {
expect(response.statusCode).toBe(404);
});
});
});
describe('Test GET Assignments', () => {
test('GET correct assignment', async () => {
return getAssignments()
/*return request(app)
.get('/assignment')*/
.then ((response) => {
expect(response.status).toBe(200);
var data = response.json();
return data;
}).then ((data) =>{
expect(data[0].assignmentId).toBe("2");
});
});
});