This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
api.test.js
56 lines (50 loc) · 1.43 KB
/
api.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
require('dotenv').config();
const request = require('supertest');
const app = require('express')();
app.use('/rides', require('./routes/rides'));
describe('API endpoints', () => {
const ENDPOINTS = [
'/rides/example',
'/rides/locations_and_times',
'/rides/count',
'/rides/count/per_month',
'/rides/count/per_year',
'/rides/count/per_hour',
'/rides/count/from/g5/to/g5',
'/rides/count/g5',
'/rides/count/g5/per_month',
'/rides/count/g5/per_day',
'/rides/count/g5/per_day_of_year',
'/rides/count/g5/per_year',
'/rides/count/g5/per_month/memberships',
'/rides/count/g5/per_week/memberships',
]
ENDPOINTS.forEach( endpoint => {
test(endpoint, (done) => {
request(app).get(endpoint).then((res) => {
expect(res.statusCode).toBe(200);
done();
});
});
});
const INVALID_ENDPOINTS = [
'/rides/count/from/FAKE/to/g5',
'/rides/count/from/g5/to/FAKE',
'/rides/count/from/FAKE/to/FAKE',
'/rides/count/FAKE',
'/rides/count/FAKE/per_month',
'/rides/count/FAKE/per_day',
'/rides/count/FAKE/per_day_of_year',
'/rides/count/FAKE/per_year',
'/rides/count/FAKE/per_month/memberships',
'/rides/count/FAKE/per_week/memberships',
]
INVALID_ENDPOINTS.forEach( endpoint => {
test(endpoint, (done) => {
request(app).get(endpoint).then((res) => {
expect(res.statusCode).toBe(404);
done();
});
});
});
});