Skip to content

Commit

Permalink
Test setting opts.cache to false bypasses cache for a single request
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Aug 12, 2017
1 parent 28dcea2 commit 6111577
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/cache.js
Expand Up @@ -137,6 +137,25 @@ test('Cacheable responses have unique cache key', async t => {
t.not(firstResponse.body, secondResponse.body);
});

test('Setting opts.cache to false bypasses cache for a single request', async t => {
const endpoint = '/cache';
const cache = new Map();
const cacheableRequest = new CacheableRequest(request, cache);
const cacheableRequestHelper = promisify(cacheableRequest);
const opts = url.parse(s.url + endpoint);
const optsNoCache = Object.assign({ cache: false }, opts);

const firstResponse = await cacheableRequestHelper(opts);
const secondResponse = await cacheableRequestHelper(opts);
const thirdResponse = await cacheableRequestHelper(optsNoCache);
const fourthResponse = await cacheableRequestHelper(opts);

t.false(firstResponse.fromCache);
t.true(secondResponse.fromCache);
t.false(thirdResponse.fromCache);
t.true(fourthResponse.fromCache);
});

test('TTL is passed to cache', async t => {
const endpoint = '/cache';
const store = new Map();
Expand Down

0 comments on commit 6111577

Please sign in to comment.