-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacceptence.spec.ts
116 lines (94 loc) · 2.49 KB
/
acceptence.spec.ts
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
import supertest from 'supertest';
import { execSync } from 'child_process';
import * as uuid from 'uuid';
const HOST = process.env.ACCEPTENCE_SERVER || 'http://localhost:2737';
jest.setTimeout(60000);
/**
* Start the docker network with the container we have built.
*
* This will allow us to test the container in issolation with
* the postgres database.
*/
beforeAll(async () => {
execSync('docker-compose -f docker-compose.acceptence.yml up -d');
// Wait for server to be up
while (true) {
try {
const response = await supertest(HOST).get('/');
if (response.status === 200) {
break;
}
} catch (e) {}
await new Promise((resolve) => {
return setTimeout(resolve, 200);
});
}
});
afterAll(() => {
try {
execSync('docker-compose -f docker-compose.acceptence.yml down');
} catch (_) {}
});
describe('acceptence', () => {
it('responds', async () => {
const response = await supertest(HOST).get('/');
expect(response.status).toBe(200);
});
it('allows votes to be made', async () => {
const postId = uuid.v1();
await supertest(HOST).put(`/v1/grades/${postId}`).send({
user: 'test',
grade: -1
});
const response = await supertest(HOST).get(`/v1/grades/${postId}`).query({
user: 'test'
});
expect(response.body).toEqual({
grade: -1,
user: -1
});
});
it('sums votes', async () => {
const postId = uuid.v1();
await supertest(HOST).put(`/v1/grades/${postId}`).send({
user: 'test',
grade: 1
});
await supertest(HOST).put(`/v1/grades/${postId}`).send({
user: 'fsdfasdf',
grade: 1
});
await supertest(HOST).put(`/v1/grades/${postId}`).send({
user: 'werweir',
grade: 1
});
await supertest(HOST).put(`/v1/grades/${postId}`).send({
user: 'sdlfksdf',
grade: -1
});
const response = await supertest(HOST).get(`/v1/grades/${postId}`).query({
user: 'test'
});
expect(response.body).toEqual({
grade: 2,
user: 1
});
const response2 = await supertest(HOST).get(`/v1/grades/${postId}`).query({
user: 'sdlfksdf'
});
expect(response2.body).toEqual({
grade: 2,
user: -1
});
});
it('allows queries for posts without votes', async () => {
const postId = uuid.v1();
const response = await supertest(HOST).get(`/v1/grades/${postId}`).query({
user: 'sdfgdf'
});
expect(response.body).toEqual({
user: 0,
grade: 0
});
});
});