Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
38 deletions.
There are no files selected for viewing
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
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,26 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
const checkUrlStatus = require('../../index') | ||
|
||
test.cb('Requires url', t => { | ||
const url = false | ||
const expectedErrorMessage = 'Missing required input: uri' | ||
checkUrlStatus(url) | ||
.then(code => console.log(code)) | ||
.catch(error => { | ||
t.deepEqual(error.message, expectedErrorMessage, expectedErrorMessage) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test.cb('Returns expected status code for https', t => { | ||
const url = 'https://www.npmjs.com' | ||
checkUrlStatus(url) | ||
.then(statusCode => { | ||
t.deepEqual(statusCode, 200, '200 OK') | ||
t.end() | ||
}).catch(error => { | ||
throw error | ||
}) | ||
}) |
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,62 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
const checkUrlStatus = require('../../index') | ||
|
||
test('Requires url', t => { | ||
const url = false | ||
const expectedErrorMessage = 'Missing required input: uri' | ||
checkUrlStatus(url, (error, statusCode) => { | ||
t.deepEqual(error.message, expectedErrorMessage, expectedErrorMessage) | ||
}) | ||
}) | ||
|
||
test('URL must be valid', t => { | ||
const url = 'pysjepreik' | ||
const expectedErrorMessage = 'Supplied uri is not valid' | ||
checkUrlStatus(url, (error, statusCode) => { | ||
t.deepEqual(error.message, expectedErrorMessage, expectedErrorMessage) | ||
}) | ||
}) | ||
|
||
test('URL must have valid start', t => { | ||
const url = 'http://https://www.google.com' | ||
const expectedErrorMessage = 'Supplied uri is not valid' | ||
checkUrlStatus(url, (error, statusCode) => { | ||
t.deepEqual(error.message, expectedErrorMessage, expectedErrorMessage) | ||
}) | ||
}) | ||
|
||
test.cb('Returns error as expected', t => { | ||
const url = 'http://detteerenurlsomsannsynligviseikkefinnes.no' | ||
checkUrlStatus(url, (error, statusCode) => { | ||
if (error) { | ||
t.truthy(error, 'Got error') | ||
t.end() | ||
} | ||
}) | ||
}) | ||
|
||
test.cb('Returns expected status code for https', t => { | ||
const url = 'https://www.npmjs.com' | ||
checkUrlStatus(url, (error, statusCode) => { | ||
if (error) { | ||
throw error | ||
} else { | ||
t.deepEqual(statusCode, 200, '200 OK') | ||
t.end() | ||
} | ||
}) | ||
}) | ||
|
||
test.cb('Returns expected status code for http', t => { | ||
const url = 'http://www.npmjs.com' | ||
checkUrlStatus(url, (error, statusCode) => { | ||
if (error) { | ||
throw error | ||
} else { | ||
t.deepEqual(statusCode, 301, '301 OK') | ||
t.end() | ||
} | ||
}) | ||
}) |