-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
35 lines (29 loc) · 944 Bytes
/
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
const test = require('ava');
const micro = require('micro');
const nock = require('nock');
const fetch = require('node-fetch');
const listen = require('test-listen');
const api = require('./index');
const service = micro(api);
test('should fail if repository not found', async t => {
nock('https://api.github.com/repos')
.get('/hugomd/not-a-repo')
.reply(404);
const url = await listen(service);
const response = await fetch(`${url}/hugomd/not-a-repo`);
const body = await response.text();
t.is(response.status, 404);
t.is(body, 'Repository not found.');
});
test('should succeed', async t => {
nock('https://api.github.com/repos')
.get('/hugomd/a-repo')
.reply(200, {
description: 'A description'
});
const url = await listen(service);
const response = await fetch(`${url}/hugomd/a-repo`);
const body = await response.text();
t.is(response.status, 200);
t.is(body, 'A description');
});