From 8ad93961e252c72fe737c3b99146cb766695591a Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 22 Dec 2016 17:32:10 +0700 Subject: [PATCH] Test cache can be disabled --- test/cache.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/cache.js b/test/cache.js index af8ca87..3e88fdf 100644 --- a/test/cache.js +++ b/test/cache.js @@ -3,6 +3,35 @@ import nock from 'nock' import data from './fixtures/data' import Onionoo from '../' +test('Cache can be disabled', async t => { + const onionoo = new Onionoo({ cache: false }) + + const defaultEndpoint = data.defaultEndpoints[0] + const responseHeaders = { + date: new Date().toUTCString(), + age: 0, + 'cache-control': 'public, max-age=300' + } + + const scope = nock(data.defaultBaseUrl) + .get(`/${defaultEndpoint}`) + .reply(200, data.dummyResponse, responseHeaders) + + const response = await onionoo[defaultEndpoint]() + + t.deepEqual(response.body, data.dummyResponse) + t.truthy(scope.isDone()) + + const scope2 = nock(data.defaultBaseUrl) + .get(`/${defaultEndpoint}`) + .reply(200, data.dummyResponse, responseHeaders) + + const response2 = await onionoo[defaultEndpoint]() + + t.deepEqual(response2.body, data.dummyResponse) + t.truthy(scope2.isDone()) +}) + test('Responses with future max-age are cached', async t => { const onionoo = new Onionoo()