From 791cb0ff2f2bdb542f88d14b8c0c821ae6aef495 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 21 Aug 2021 19:11:06 +0300 Subject: [PATCH] Update utils.test.js --- tests/utils.test.js | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/tests/utils.test.js b/tests/utils.test.js index 349010c..edc7474 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -15,8 +15,6 @@ it('can load valid config.js', () => { timeout: 5000, headers: { 'Content-Type': 'application/json', - 'User-Agent': - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71', Cookie: 'abc=123' } }) @@ -81,9 +79,23 @@ it('can escape url', () => { ) }) -it('can fetch data', () => { - const config = utils.loadConfig('./tests/input/example.com.config.js') - utils.fetchData({}, config).then(jest.fn).catch(jest.fn) +it('can fetch data', async () => { + const request = { + data: { accountID: '123' }, + headers: { + 'Content-Type': 'application/json', + Cookie: 'abc=123', + 'User-Agent': + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71' + }, + maxContentLength: 5242880, + method: 'POST', + responseType: 'arraybuffer', + timeout: 5000, + url: 'http://example.com/20210319/1tv.json', + withCredentials: true + } + utils.fetchData(request).then(jest.fn).catch(jest.fn) expect(mockAxios).toHaveBeenCalledWith( expect.objectContaining({ data: { accountID: '123' }, @@ -101,3 +113,24 @@ it('can fetch data', () => { }) ) }) + +it('can build request async', async () => { + const config = utils.loadConfig('./tests/input/async.config.js') + return utils.buildRequest({}, config).then(request => { + expect(request).toMatchObject({ + data: { accountID: '123' }, + headers: { + 'Content-Type': 'application/json', + Cookie: 'abc=123', + 'User-Agent': + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71' + }, + maxContentLength: 5242880, + method: 'POST', + responseType: 'arraybuffer', + timeout: 5000, + url: 'http://example.com/20210319/1tv.json', + withCredentials: true + }) + }) +})