From 14db4cf04a42290b946fdf3d6a637b80e93b18c0 Mon Sep 17 00:00:00 2001 From: Victor Meyer Date: Mon, 8 Feb 2021 15:01:42 +0100 Subject: [PATCH 1/2] fix: remove multiple exports --- src/modules/autoc.ts | 18 +----------------- src/modules/historical.ts | 18 +----------------- src/modules/quote.ts | 25 +------------------------ src/modules/quoteSummary.ts | 16 ---------------- src/modules/search.ts | 18 +----------------- 5 files changed, 4 insertions(+), 91 deletions(-) diff --git a/src/modules/autoc.ts b/src/modules/autoc.ts index 27670f85..53b71325 100644 --- a/src/modules/autoc.ts +++ b/src/modules/autoc.ts @@ -1,7 +1,5 @@ import type { ModuleOptions, - ModuleOptionsWithValidateTrue, - ModuleOptionsWithValidateFalse, ModuleThis, } from '../lib/moduleCommon'; @@ -29,26 +27,12 @@ const queryOptionsDefaults = { lang: 'en' }; -export default function autoc( - this: ModuleThis, - query: string, - queryOptionsOverrides?: AutocOptions, - moduleOptions?: ModuleOptionsWithValidateFalse -): Promise; - -export default function autoc( - this: ModuleThis, - query: string, - queryOptionsOverrides?: AutocOptions, - moduleOptions?: ModuleOptionsWithValidateTrue -): Promise; - export default function autoc( this: ModuleThis, query: string, queryOptionsOverrides?: AutocOptions, moduleOptions?: ModuleOptions -): Promise { +): Promise { return this._moduleExec({ moduleName: "autoc", diff --git a/src/modules/historical.ts b/src/modules/historical.ts index 4940a8cf..d3a195be 100644 --- a/src/modules/historical.ts +++ b/src/modules/historical.ts @@ -1,7 +1,5 @@ import type { ModuleOptions, - ModuleOptionsWithValidateTrue, - ModuleOptionsWithValidateFalse, ModuleThis, } from '../lib/moduleCommon'; @@ -31,26 +29,12 @@ const queryOptionsDefaults: Omit = { includeAdjustedClose: true, }; -export default function historical( - this: ModuleThis, - symbol: string, - queryOptionsOverrides: HistoricalOptions, - moduleOptions?: ModuleOptionsWithValidateFalse -): Promise; - -export default function historical( - this: ModuleThis, - symbol: string, - queryOptionsOverrides: HistoricalOptions, - moduleOptions?: ModuleOptionsWithValidateTrue -): Promise; - export default function historical( this: ModuleThis, symbol: string, queryOptionsOverrides: HistoricalOptions, moduleOptions?: ModuleOptions -): Promise { +): Promise { return this._moduleExec({ moduleName: "historical", diff --git a/src/modules/quote.ts b/src/modules/quote.ts index 86291090..4b68471f 100644 --- a/src/modules/quote.ts +++ b/src/modules/quote.ts @@ -1,7 +1,5 @@ import type { ModuleOptions, - ModuleOptionsWithValidateTrue, - ModuleOptionsWithValidateFalse, ModuleThis, } from '../lib/moduleCommon'; @@ -114,33 +112,12 @@ export interface QuoteOptions { const queryOptionsDefaults = { }; -export default function quote( - this: ModuleThis, - query: string | string[], - queryOptionsOverrides?: QuoteOptions, - moduleOptions?: ModuleOptionsWithValidateFalse -): Promise; - -export default function quote( - this: ModuleThis, - query: string[], - queryOptionsOverrides?: QuoteOptions, - moduleOptions?: ModuleOptionsWithValidateTrue -): Promise; - -export default function quote( - this: ModuleThis, - query: string, - queryOptionsOverrides?: QuoteOptions, - moduleOptions?: ModuleOptionsWithValidateTrue -): Promise; - export default function quote( this: ModuleThis, query: string | string[], queryOptionsOverrides?: QuoteOptions, moduleOptions?: ModuleOptions -): Promise { +): Promise { const symbols = typeof query === 'string' ? query : query.join(','); return this._moduleExec({ diff --git a/src/modules/quoteSummary.ts b/src/modules/quoteSummary.ts index 7c848441..5c0fd262 100644 --- a/src/modules/quoteSummary.ts +++ b/src/modules/quoteSummary.ts @@ -4,8 +4,6 @@ import { QuoteSummaryResult } from './quoteSummary-iface'; import type { ModuleOptions, - ModuleOptionsWithValidateTrue, - ModuleOptionsWithValidateFalse, ModuleThis, } from '../lib/moduleCommon'; @@ -91,20 +89,6 @@ const queryOptionsDefaults = { modules: ['price', 'summaryDetail'] }; -export default function quoteSummary( - this: ModuleThis, - symbol: string, - queryOptionsOverrides?: QuoteSummaryOptions, - moduleOptions?: ModuleOptionsWithValidateFalse -): Promise; - -export default function quoteSummary( - this: ModuleThis, - symbol: string, - queryOptionsOverrides?: QuoteSummaryOptions, - moduleOptions?: ModuleOptionsWithValidateTrue -): Promise; - export default function quoteSummary( this: ModuleThis, symbol: string, diff --git a/src/modules/search.ts b/src/modules/search.ts index 173a2867..154c1d9d 100644 --- a/src/modules/search.ts +++ b/src/modules/search.ts @@ -1,7 +1,5 @@ import type { ModuleOptions, - ModuleOptionsWithValidateTrue, - ModuleOptionsWithValidateFalse, ModuleThis, } from '../lib/moduleCommon'; @@ -88,26 +86,12 @@ const queryOptionsDefaults = { enableEnhancedTrivialQuery: true }; -export default function search( - this: ModuleThis, - query: string, - queryOptionsOverrides?: SearchOptions, - moduleOptions?: ModuleOptionsWithValidateFalse, -): Promise; - -export default function search( - this: ModuleThis, - query: string, - queryOptionsOverrides?: SearchOptions, - moduleOptions?: ModuleOptionsWithValidateTrue, -): Promise; - export default function search( this: ModuleThis, query: string, queryOptionsOverrides?: SearchOptions, moduleOptions?: ModuleOptions -): Promise { +): Promise { return this._moduleExec({ moduleName: "search", From 16aed8819349e12df1a1a7caf729632e6fd9805d Mon Sep 17 00:00:00 2001 From: Victor Meyer Date: Mon, 8 Feb 2021 15:56:27 +0100 Subject: [PATCH 2/2] chore(search): add another test --- src/modules/search.spec.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/modules/search.spec.ts b/src/modules/search.spec.ts index f993f16b..306637f9 100644 --- a/src/modules/search.spec.ts +++ b/src/modules/search.spec.ts @@ -1,5 +1,4 @@ import search from './search'; -const { InvalidOptionsError } = require('../lib/errors'); import _env from '../env-node'; import _fetch from '../lib/yahooFinanceFetch'; @@ -33,4 +32,31 @@ describe('search', () => { }); }); + it('successfully figure out symbol for Evolution Gaming Group', async () => { + const response = await yf.search('Apple', {}, { devel: 'search-Evolution Gaming Group.json'}); + + const onlyQuotesWithQuoteTypeEquity = response.quotes.filter( + (searchQuote) => { + if ('quoteType' in searchQuote && searchQuote.quoteType === 'EQUITY') { + return true; + } else { + return false; + } + }, + ); + + let symbol; + if ( + 'quoteType' in onlyQuotesWithQuoteTypeEquity[0] && + 'symbol' in onlyQuotesWithQuoteTypeEquity[0] + ) { + symbol = onlyQuotesWithQuoteTypeEquity[0].symbol; + } else { + throw new Error(`The quote we found din't have a symbol`); + } + + expect(symbol).toBe('AAPL'); + + }); + });