fetch plugin test: testing the headers

merge-requests/1/head
Michał 'rysiek' Woźniak 2021-08-29 01:12:03 +00:00
rodzic 4b1019edcb
commit 8069213852
1 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -12,7 +12,9 @@ global.fetch.mockImplementation((url, init) => {
{
status: 200,
statusText: "OK",
headers: [],
headers: {
'ETag': 'TestingETagHeader'
},
url: url
});
return Promise.resolve(response);
@ -46,4 +48,18 @@ describe("plugin: fetch", () => {
expect(await response.json()).toEqual({test: "success"})
expect(response.url).toEqual('https://resilient.is/test.json')
});
test("it should set the LibResilient headers", async () => {
require("../../plugins/fetch.js");
const response = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
expect(fetch).toHaveBeenCalled();
expect(await response.json()).toEqual({test: "success"})
expect(response.url).toEqual('https://resilient.is/test.json')
expect(response.headers.has('X-LibResilient-Method')).toEqual(true)
expect(response.headers.get('X-LibResilient-Method')).toEqual('fetch')
expect(response.headers.has('X-LibResilient-Etag')).toEqual(true)
expect(response.headers.get('X-LibResilient-ETag')).toEqual('TestingETagHeader')
});
});