From 5fdd6c82de88fe7e3a23b9cc92ae2b14437d2103 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 28 Nov 2017 16:52:33 +0700 Subject: [PATCH] Test cache options is passed through to Got --- test/cache.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/cache.js b/test/cache.js index f6bfc37..baf33d5 100644 --- a/test/cache.js +++ b/test/cache.js @@ -31,3 +31,27 @@ test('Cache is disabled by default', async t => { t.false(response2.fromCache); t.truthy(scope2.isDone()); }); + +test('Cache options is passed through to Got', async t => { + const onionoo = new Onionoo({cache: new Map()}); + + 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.false(response.fromCache); + t.truthy(scope.isDone()); + + const response2 = await onionoo[defaultEndpoint](); + + t.true(response2.fromCache); +});