-
-
Notifications
You must be signed in to change notification settings - Fork 840
Expand file tree
/
Copy pathutils.test.ts
More file actions
82 lines (76 loc) · 2.53 KB
/
utils.test.ts
File metadata and controls
82 lines (76 loc) · 2.53 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
import express from 'express';
import request from 'supertest';
import { Utilities } from '../src/utils';
import { fakeQueryString, fakeQueryStringRes, options } from './fakeInputs';
import { Handlers } from '../src/handlers';
import { createGraph } from '../src/createChart';
describe('Utilities Test', () => {
const handlers = new Handlers();
it('Query Options', () => {
expect(
fakeQueryString.map((arg) => {
const utils = new Utilities(arg);
return utils.queryOptions();
}),
).toEqual(fakeQueryStringRes);
});
// Testing express routes
const fakeServer = () => {
const app = express();
app.use(express.urlencoded({ extended: false }));
return app;
};
describe('GET /graph with correct credential', () => {
test('responding', (done) => {
const app = fakeServer();
app.get('/graph', handlers.getGraph);
request(app)
.get('/graph?username=ashutosh00710')
.expect('Content-Type', 'image/svg+xml; charset=utf-8')
.expect('Cache-Control', 'public, max-age=1800')
.expect(200, done);
});
});
describe('GET /graph with incorrect credential', () => {
test('responding', (done) => {
const app = fakeServer();
app.get('/graph', handlers.getGraph);
request(app)
.get('/graph?username=')
.expect('Content-Type', 'image/svg+xml; charset=utf-8')
.expect('Cache-Control', 'no-store, max-age=0')
.expect(200, done);
});
});
//- Chart Function ([Promise] Inside Graph Cards Class) ✔
it('Graph Generation', async () => {
expect.assertions(1);
const days = [
{
contributionCount: 2,
date: '1',
},
{
contributionCount: 3,
date: '2',
},
{
contributionCount: 10,
date: '3',
},
{
contributionCount: 12,
date: '4',
},
{
contributionCount: 14,
date: '5',
},
];
const graph: Promise<string> = await createGraph('line', options, {
labels: days.map((day) => day.date),
series: [{ value: days.map((day) => day.contributionCount) }],
});
expect(graph).toMatchSnapshot();
});
});