climate-data-crawler
Advanced tools
Comparing version 1.3.1 to 1.4.0
"use strict"; | ||
var CdoApiClient = require('./cdoApiClient'); | ||
var CdoApiClientFactory = require('./cdoApiClientFactory'); | ||
@@ -8,5 +7,3 @@ exports.createInstance = function( | ||
return CdoApiClient.createInstance(locationid, dataset, datatypeid, startDate, endDate) | ||
}; |
@@ -8,3 +8,3 @@ "use strict"; | ||
cdoApiClientFactory, timer, | ||
locationId, dataset, datatypeid, startYear, endYear) { | ||
locationId, dataset, datatypeid, startYear, endYear) { | ||
@@ -16,5 +16,5 @@ var queryYear = startYear; | ||
var onApiCallComplete = function(result){ | ||
if (result){ | ||
onQueryComplete(result); | ||
var onApiCallComplete = function(results){ | ||
if (results){ | ||
onQueryComplete(appendLocationIdToResults(results)); | ||
} | ||
@@ -34,2 +34,9 @@ else { | ||
var appendLocationIdToResults = function(results){ | ||
for (var i = 0; i < results.length; i++){ | ||
results[i].locationId = locationId; | ||
} | ||
return results; | ||
}; | ||
var queryNext = function(){ | ||
@@ -36,0 +43,0 @@ var cdoApiClient = cdoApiClientFactory.createInstance( |
@@ -23,3 +23,3 @@ "use strict"; | ||
request.on('socket', function (socket) { | ||
socket.setTimeout(60000); | ||
socket.setTimeout(600000); | ||
socket.on('timeout', function() { | ||
@@ -26,0 +26,0 @@ request.abort(); |
{ | ||
"name": "climate-data-crawler", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Data Crawler for CDO (Climate Data Online) web services", | ||
@@ -5,0 +5,0 @@ "main": "app.js", |
@@ -81,3 +81,3 @@ "use strict"; | ||
describe('#run', function(){ | ||
it('should call apiClientFactory with expected parameters', function() { | ||
it('call apiClientFactory with expected parameters', function() { | ||
// arrange | ||
@@ -99,3 +99,3 @@ sinon.stub(api, 'query'); | ||
it('should invoke apiClient\'s query method', function() { | ||
it('invoke apiClient\'s query method', function() { | ||
// arrange | ||
@@ -114,37 +114,47 @@ sinon.stub(api, 'query'); | ||
describe('#onQueryCompleteCallback', function(){ | ||
it('should call onQueryCompleteCallback with results when receiving data from api client', function(){ | ||
// arrange | ||
var expectedRunResults = fs.readFileSync('test-resources/dataset.json', {encoding: 'utf8'}); | ||
var actualRunResults = null; | ||
describe('results', function(){ | ||
it('invoke onQueryCompleteCallback with api results and append locationId', function(){ | ||
// arrange | ||
var resultFromApi = JSON.parse(fs.readFileSync('test-resources/dataset.json', {encoding: 'utf8'})); | ||
var results = null; | ||
sinon.stub(api, 'query', function(onApiCallComplete){ | ||
onApiCallComplete(expectedRunResults); | ||
}); | ||
var temp = resultFromApi; | ||
for (var i = 0; i < temp.length; i++){ | ||
temp[i].locationId = locationId; | ||
} | ||
var expectedRunResults = temp; | ||
var query = getInstance(); | ||
sinon.stub(api, 'query', function(onApiCallComplete){ | ||
onApiCallComplete(resultFromApi); | ||
}); | ||
// act | ||
query.run(function(results){ | ||
actualRunResults = results; | ||
var query = getInstance(); | ||
// act | ||
query.run(function(res){ | ||
results = res; | ||
}); | ||
// assert | ||
assert.notEqual(results, null); | ||
assert.equal(results, expectedRunResults); | ||
}); | ||
// assert | ||
assert.notEqual(actualRunResults, null); | ||
assert.equal(actualRunResults, expectedRunResults); | ||
}); | ||
it('should be possible to call run without specifying onQueryCompleteCallback', function(){ | ||
// arrange | ||
var runResults = fs.readFileSync('test-resources/dataset.json', {encoding: 'utf8'}); | ||
describe('onQueryCompleteCallback not given', function(){ | ||
it('not throw exception', function(){ | ||
// arrange | ||
var runResults = JSON.parse(fs.readFileSync('test-resources/dataset.json', {encoding: 'utf8'})); | ||
sinon.stub(api, 'query', function(onApiCallComplete){ | ||
onApiCallComplete(runResults); | ||
}); | ||
sinon.stub(api, 'query', function(onApiCallComplete){ | ||
onApiCallComplete(runResults); | ||
}); | ||
var query = getInstance(); | ||
var query = getInstance(); | ||
// act + assert | ||
assert.doesNotThrow(function(){ | ||
query.run(); | ||
}); | ||
// act + assert | ||
assert.doesNotThrow(function(){ | ||
query.run(); | ||
}); | ||
}) | ||
}); | ||
@@ -155,3 +165,3 @@ | ||
describe('api returns no data for the current year\'s query', function(){ | ||
it('should query each year until it reaches endYear to probe for data', function(){ | ||
it('query each year until it reaches endYear to probe for data', function(){ | ||
// arrange | ||
@@ -190,3 +200,3 @@ sinon.stub(api, 'query', function(onApiCallComplete){ | ||
describe('#onRunCompleteCallback', function(){ | ||
it('should invoke onRunCompleteCallback when no data until endYear', function(){ | ||
it('invoke onRunCompleteCallback when no data until endYear', function(){ | ||
// arrange | ||
@@ -213,38 +223,36 @@ sinon.stub(api, 'query', function(onApiCallComplete){ | ||
}); | ||
it('pause shortly before probing next year', function() { | ||
// arrange | ||
sinon.stub(api, 'query', function(onApiCallComplete){ | ||
onApiCallComplete(null); | ||
}); | ||
it('should pause shortly before probing next year', function() { | ||
// arrange | ||
sinon.stub(api, 'query', function(onApiCallComplete){ | ||
onApiCallComplete(null); | ||
}); | ||
startYear = 2014; | ||
endYear = 2000; | ||
var expectedCallCount = startYear - endYear; | ||
var actualCallCount = 0; | ||
startYear = 2014; | ||
endYear = 2000; | ||
var expectedCallCount = startYear - endYear; | ||
var actualCallCount = 0; | ||
var actualDelay = null; | ||
var actualDelay = null; | ||
timer.setTimeout.restore(); | ||
sinon.stub(timer, 'setTimeout', function(callback, delay){ | ||
actualDelay = delay; | ||
actualCallCount++; | ||
callback(); | ||
}); | ||
timer.setTimeout.restore(); | ||
sinon.stub(timer, 'setTimeout', function(callback, delay){ | ||
actualDelay = delay; | ||
actualCallCount++; | ||
callback(); | ||
}); | ||
var query = getInstance(); | ||
var query = getInstance(); | ||
// act | ||
query.run(); | ||
// act | ||
query.run(); | ||
// assert | ||
assert.equal(actualDelay, 1000); | ||
assert.equal(actualCallCount, expectedCallCount); | ||
// assert | ||
assert.equal(actualDelay, 1000); | ||
assert.equal(actualCallCount, expectedCallCount); | ||
}); | ||
}); | ||
}); | ||
describe('error handling', function(){ | ||
it('should invoke error callback', function(){ | ||
it('invoke error callback', function(){ | ||
// arrange | ||
@@ -281,3 +289,3 @@ var errorTrigger = null; | ||
describe('#createInstance', function(){ | ||
it('should not return null', function(){ | ||
it('not return null', function(){ | ||
// arrange | ||
@@ -284,0 +292,0 @@ var query = CdoDataProbingQuery.createInstance('CITY:BR000023', 'GHCNDMS', 'MMNT', 2014, 2000); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64425
1704