Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
The tests confirm bad requests return failures, and that a good request should return success.
  • Loading branch information
rmparr authored and mrchrisadams committed Mar 13, 2020
1 parent 85f2a4e commit 20bbcf8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Empty file removed src/__test__
Empty file.
67 changes: 67 additions & 0 deletions src/__test__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

const server = require('../index')

jest.mock('../callSitespeed')

beforeAll((done) => {
server.events.on('start', () => {
done();
});
});

afterAll((done) => {
server.events.on('stop', () => {
done();
});
server.stop();
});

test('GET request returns failure', async () => {
const options = {
method: 'GET',
url: '/'
};
const data = await server.inject(options);
expect(data.statusCode).toBe(404);
});

test('POST request with no payload returns failure', async () => {
const options = {
method: 'POST',
url: '/',
payload: {
url: null
}
};
const data = await server.inject(options);
expect(data.statusCode).toBe(400);
expect(data.payload).toBe('Bad Request: no URL received');
});

test('POST request with incorrect URL returns failure', async () => {
const options = {
method: 'POST',
url: '/',
payload: {
url: 'badurl'
}
};
const data = await server.inject(options);
expect(data.statusCode).toBe(400);
expect(data.payload).toBe('Bad Request: bad URL received');
});

test('POST request with correct URL returns success', async () => {
const options = {
method: 'POST',
url: '/',
payload: {
url: 'http://example.com'
}
};

const data = await server.inject(options);
expect(data.statusCode).toBe(204);
expect(data.payload).toBe('');
});

0 comments on commit 20bbcf8

Please sign in to comment.