-
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.
- Loading branch information
Showing
1 changed file
with
148 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,203 +1,203 @@ | ||
|
||
(function () { | ||
|
||
'use strict'; | ||
'use strict'; | ||
|
||
var requireHelper = require('./requireHelper'); | ||
var apiv1 = requireHelper.require('tests/coverage/instrumented/routes/apiv1'); | ||
var assert = require('chai').assert; | ||
var sinon = require('sinon'); | ||
var apiv1 = requireHelper.require('tests/coverage/instrumented/routes/apiv1'); | ||
var assert = require('chai').assert; | ||
var sinon = require('sinon'); | ||
|
||
|
||
|
||
// create mock request and response | ||
var reqMock = {}; | ||
// create mock request and response | ||
var reqMock = {}; | ||
|
||
var resMock = {}; | ||
resMock.status = function() { | ||
return this; | ||
}; | ||
resMock.send = function() { | ||
return this; | ||
}; | ||
resMock.end = function() { | ||
return this; | ||
}; | ||
sinon.spy(resMock, "status"); | ||
sinon.spy(resMock, "send"); | ||
var resMock = {}; | ||
resMock.status = function() { | ||
return this; | ||
}; | ||
resMock.send = function() { | ||
return this; | ||
}; | ||
resMock.end = function() { | ||
return this; | ||
}; | ||
sinon.spy(resMock, "status"); | ||
sinon.spy(resMock, "send"); | ||
|
||
|
||
describe('Get Weather', function() { | ||
describe('Get Weather', function() { | ||
|
||
it('with without zip code', function() { | ||
reqMock = { | ||
query: { | ||
it('with without zip code', function() { | ||
reqMock = { | ||
query: { | ||
|
||
} | ||
}; | ||
} | ||
}; | ||
|
||
apiv1.getWeather(reqMock, resMock); | ||
apiv1.getWeather(reqMock, resMock); | ||
|
||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected status code:' + resMock.status.lastCall.args); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected status code:' + resMock.status.lastCall.args); | ||
}); | ||
|
||
it('with valid zip code and error from request call', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
it('with valid zip code and error from request call', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
|
||
var request = function( obj, callback ){ | ||
callback("error", null, null); | ||
}; | ||
var request = function( obj, callback ){ | ||
callback("error", null, null); | ||
}; | ||
|
||
apiv1.__set__("request", request); | ||
apiv1.__set__("request", request); | ||
|
||
apiv1.getWeather(reqMock, resMock); | ||
apiv1.getWeather(reqMock, resMock); | ||
|
||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.calledWith('Failed to get the data'), 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.calledWith('Failed to get the data'), 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
|
||
it('with incomplete zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
it('with incomplete zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
|
||
var request = function( obj, callback ){ | ||
callback(null, null, {}); | ||
}; | ||
var request = function( obj, callback ){ | ||
callback(null, null, {}); | ||
}; | ||
|
||
apiv1.__set__("request", request); | ||
apiv1.__set__("request", request); | ||
|
||
apiv1.getWeather(reqMock, resMock); | ||
apiv1.getWeather(reqMock, resMock); | ||
|
||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].msg === 'Failed', 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].msg === 'Failed', 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
|
||
it('with valid zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
|
||
var body = { | ||
cod: 200, | ||
name: 'El Paso', | ||
weather: [ | ||
{ | ||
main: 'cold' | ||
} | ||
], | ||
main: { | ||
temp: 78 | ||
it('with valid zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
|
||
var body = { | ||
cod: 200, | ||
name: 'El Paso', | ||
weather: [ | ||
{ | ||
main: 'cold' | ||
} | ||
}; | ||
], | ||
main: { | ||
temp: 78 | ||
} | ||
}; | ||
|
||
var request = function( obj, callback ){ | ||
callback(null, null, body); | ||
}; | ||
var request = function( obj, callback ){ | ||
callback(null, null, body); | ||
}; | ||
|
||
apiv1.__set__("request", request); | ||
apiv1.__set__("request", request); | ||
|
||
apiv1.getWeather(reqMock, resMock); | ||
apiv1.getWeather(reqMock, resMock); | ||
|
||
assert(resMock.status.lastCall.calledWith(200), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].city === 'El Paso', 'Unexpected response:' + resMock.send.lastCall.args[0].city); | ||
assert(resMock.send.lastCall.args[0].weather === 'Conditions are cold and temperature is 78 F', 'Unexpected response:' + resMock.send.lastCall.args[0].weather); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(200), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].city === 'El Paso', 'Unexpected response:' + resMock.send.lastCall.args[0].city); | ||
assert(resMock.send.lastCall.args[0].weather === 'Conditions are cold and temperature is 78 F', 'Unexpected response:' + resMock.send.lastCall.args[0].weather); | ||
}); | ||
}); | ||
|
||
/* | ||
describe('Get Weather 2', function() { | ||
/* | ||
describe('Get Weather 2', function() { | ||
it('with without zip code', function() { | ||
reqMock = { | ||
query: { | ||
it('with without zip code', function() { | ||
reqMock = { | ||
query: { | ||
} | ||
}; | ||
} | ||
}; | ||
apiv1.getWeather2(reqMock, resMock); | ||
apiv1.getWeather2(reqMock, resMock); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected status code:' + resMock.status.lastCall.args); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected status code:' + resMock.status.lastCall.args); | ||
}); | ||
it('with valid zip code and error from request call', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
it('with valid zip code and error from request call', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
var request = function( obj, callback ){ | ||
callback("error", null, null); | ||
}; | ||
var request = function( obj, callback ){ | ||
callback("error", null, null); | ||
}; | ||
apiv1.__set__("request", request); | ||
apiv1.__set__("request", request); | ||
apiv1.getWeather2(reqMock, resMock); | ||
apiv1.getWeather2(reqMock, resMock); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.calledWith('Failed to get the data'), 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.calledWith('Failed to get the data'), 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
it('with incomplete zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
it('with incomplete zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
var request = function( obj, callback ){ | ||
callback(null, null, {}); | ||
}; | ||
var request = function( obj, callback ){ | ||
callback(null, null, {}); | ||
}; | ||
apiv1.__set__("request", request); | ||
apiv1.__set__("request", request); | ||
apiv1.getWeather2(reqMock, resMock); | ||
apiv1.getWeather2(reqMock, resMock); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].msg === 'Failed', 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(400), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].msg === 'Failed', 'Unexpected response:' + resMock.send.lastCall.args); | ||
}); | ||
it('with valid zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
var body = { | ||
cod: 200, | ||
name: 'El Paso', | ||
weather: [ | ||
{ | ||
main: 'cold' | ||
} | ||
], | ||
main: { | ||
temp: 78 | ||
it('with valid zip code', function() { | ||
reqMock = { | ||
query: { | ||
zip: 79968 | ||
} | ||
}; | ||
var body = { | ||
cod: 200, | ||
name: 'El Paso', | ||
weather: [ | ||
{ | ||
main: 'cold' | ||
} | ||
}; | ||
], | ||
main: { | ||
temp: 78 | ||
} | ||
}; | ||
var request = function( obj, callback ){ | ||
callback(null, null, body); | ||
}; | ||
var request = function( obj, callback ){ | ||
callback(null, null, body); | ||
}; | ||
apiv1.__set__("request", request); | ||
apiv1.__set__("request", request); | ||
apiv1.getWeather2(reqMock, resMock); | ||
apiv1.getWeather2(reqMock, resMock); | ||
assert(resMock.status.lastCall.calledWith(200), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].city === 'El Paso', 'Unexpected response:' + resMock.send.lastCall.args[0].city); | ||
assert(resMock.send.lastCall.args[0].weather === 'Conditions are cold and temperature is 78 F', 'Unexpected response:' + resMock.send.lastCall.args[0].weather); | ||
}); | ||
assert(resMock.status.lastCall.calledWith(200), 'Unexpected response:' + resMock.status.lastCall.args); | ||
assert(resMock.send.lastCall.args[0].city === 'El Paso', 'Unexpected response:' + resMock.send.lastCall.args[0].city); | ||
assert(resMock.send.lastCall.args[0].weather === 'Conditions are cold and temperature is 78 F', 'Unexpected response:' + resMock.send.lastCall.args[0].weather); | ||
}); | ||
*/ | ||
}); | ||
*/ | ||
}()); |