-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.test.ts
59 lines (50 loc) · 1.64 KB
/
example.test.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
import { beforeAll, describe, expect, it, afterAll } from '@jest/globals';
import supertest from 'supertest';
import app from '../src/app';
import { GitHubRepository } from '../src/clients/github';
import githubInterceptor from './interceptors/github';
describe('Example tests', () => {
const ownerName = 'owner';
const repositoryName = 'example';
const repository: GitHubRepository = {
id: 1,
name: repositoryName,
full_name: `${ownerName}/${repositoryName}`,
html_url: `https://github.com/${ownerName}/${repositoryName}`,
owner: { login: ownerName },
};
beforeAll(async () => {
await app.ready();
});
afterAll(async () => {
await app.close();
});
it('should return a GitHub repository, if found', async () => {
githubInterceptor
.get(`/repos/${ownerName}/${repositoryName}`)
.respond({
status: 200,
body: repository,
})
.times(1);
const response = await supertest(app.server).get(`/github/repositories/${ownerName}/${repositoryName}`);
expect(response.status).toBe(200);
expect(response.body).toEqual({
id: repository.id,
fullName: repository.full_name,
homepageURL: repository.html_url,
});
});
it('should return a 404 status code, if the GitHub repository is not found', async () => {
githubInterceptor
.get('/repos/:owner/:name')
.respond({
status: 404,
body: { message: 'Not Found' },
})
.times(1);
const response = await supertest(app.server).get(`/github/repositories/${ownerName}/${repositoryName}`);
expect(response.status).toBe(404);
expect(response.body).toEqual({});
});
});