Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding initial crappy fetchData test.
- Loading branch information
1 parent
540dea9
commit 57d2355
Showing
1 changed file
with
60 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var RedisCache = require('../../cache/RedisCache'); | ||
var FakeRedis = require('fakeredis'); | ||
var Promise = require('bluebird'); | ||
|
||
var assert = require('assert'); | ||
var expect = require('expect'); | ||
var rewire = require('rewire'); | ||
var sinon = require('sinon'); | ||
|
||
var fetchData = rewire('../fetchData'); | ||
|
||
describe('fetchData', function() { | ||
var cache = new RedisCache(FakeRedis.createClient()); | ||
|
||
it('should throw on isReset response', function() { | ||
var mockSendRequest = sinon.stub() | ||
.returns(Promise.resolve({ | ||
delay: 500, | ||
isReset: true, | ||
lists: [] | ||
})); | ||
|
||
return fetchData.__with__({ | ||
sendRequest: mockSendRequest | ||
})(function() { | ||
return fetchData(cache, 'abc', []) | ||
.then(() => assert(false)) | ||
.catch(() => assert(mockSendRequest.called)); | ||
}); | ||
}); | ||
|
||
it('should expire all expire ranges and call fetch', function() { | ||
var mockSendRequest = sinon.stub() | ||
.returns(Promise.resolve({ | ||
delay: 500, | ||
isReset: false, | ||
lists: [{ | ||
name: 'my happy list', | ||
urls: ['a url', 'another url'], | ||
expireAdd: [1, 2, 3], | ||
expireSub: [[7, 12]] | ||
}] | ||
})); | ||
|
||
var mockExpireChunkRanges = sinon.stub().returns(Promise.resolve()); | ||
var mockFetchDataRedirect = sinon.stub().returns(Promise.resolve()); | ||
|
||
return fetchData.__with__({ | ||
sendRequest: mockSendRequest, | ||
expireChunkRanges: mockExpireChunkRanges, | ||
fetchDataRedirect: mockFetchDataRedirect | ||
})(function() { | ||
return fetchData(cache, 'abc', ['my happy list']) | ||
.then(function() { | ||
assert(mockExpireChunkRanges.calledTwice); | ||
assert(mockFetchDataRedirect.calledTwice); | ||
}); | ||
}); | ||
}); | ||
}); |