From f93f2810f57659e0eb7f72a93cb03b828ddc1176 Mon Sep 17 00:00:00 2001 From: Gadi Cohen Date: Sun, 11 Apr 2021 18:37:52 +0300 Subject: [PATCH] coverage --- src/lib/yahooFinanceFetch.spec.ts | 19 +++++++++++++++++++ src/lib/yahooFinanceFetch.ts | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/lib/yahooFinanceFetch.spec.ts b/src/lib/yahooFinanceFetch.spec.ts index b506d99d..254390cb 100644 --- a/src/lib/yahooFinanceFetch.spec.ts +++ b/src/lib/yahooFinanceFetch.spec.ts @@ -109,6 +109,25 @@ describe("yahooFinanceFetch", () => { moduleOpts = { queue: { _queue: new Queue() } }; }); + it("Queue takes options in constructor", () => { + const queue = new Queue({ concurrency: 5 }); + expect(queue.concurrency).toBe(5); + }); + + it("yahooFinanceFetch branch check for alternate queue", () => { + const promises = [ + yahooFinanceFetch("", {}), + yahooFinanceFetch("", {}, {}), + yahooFinanceFetch("", {}, { queue: {} }), + ]; + + env.fetch.fetches[0].resolveWith({ ok: true }); + env.fetch.fetches[1].resolveWith({ ok: true }); + env.fetch.fetches[2].resolveWith({ ok: true }); + + return Promise.all(promises); + }); + it("assert defualts to {} for empty queue opts", () => { moduleOpts.queue.concurrency = 1; const opts = { ..._opts }; diff --git a/src/lib/yahooFinanceFetch.ts b/src/lib/yahooFinanceFetch.ts index f92f947f..292dbd2e 100644 --- a/src/lib/yahooFinanceFetch.ts +++ b/src/lib/yahooFinanceFetch.ts @@ -53,8 +53,8 @@ async function yahooFinanceFetch( "yahooFinanceFetch called without this._env set" ); - const queue = moduleOpts?.queue?._queue || _queue; - assertQueueOptions(queue, moduleOpts.queue || this._opts.queue || {}); + const queue = moduleOpts.queue?._queue || _queue; + assertQueueOptions(queue, { ...this._opts.queue, ...moduleOpts.queue }); const { URLSearchParams, fetch, fetchDevel } = this._env;