-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The tests confirm bad requests return failures, and that a good request should return success.
- Loading branch information
1 parent
85f2a4e
commit 20bbcf8
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(''); | ||
}); |