From 3fa958c255bb374b71915a063b4f3d783fb39a50 Mon Sep 17 00:00:00 2001 From: Gadi Cohen Date: Wed, 3 Feb 2021 09:39:30 +0200 Subject: [PATCH] fix(quoteSummary): more optional props, more tests --- schema.json | 81 +++++++++++++++---------------- src/modules/quoteSummary-iface.ts | 8 +-- src/modules/quoteSummary.spec.ts | 23 +++++++-- src/modules/quoteSummary.ts | 4 +- 4 files changed, 64 insertions(+), 52 deletions(-) diff --git a/schema.json b/schema.json index ef69af2e..08440ed1 100644 --- a/schema.json +++ b/schema.json @@ -283,15 +283,12 @@ "maxAge", "endDate", "cash", - "netReceivables", - "inventory", "otherCurrentAssets", "totalCurrentAssets", "longTermInvestments", "propertyPlantEquipment", "otherAssets", "totalAssets", - "accountsPayable", "otherCurrentLiab", "longTermDebt", "otherLiab", @@ -441,7 +438,6 @@ "capitalExpenditures", "otherCashflowsFromInvestingActivities", "totalCashflowsFromInvestingActivities", - "netBorrowings", "otherCashflowsFromFinancingActivities", "totalCashFromFinancingActivities", "changeInCash" @@ -1800,6 +1796,45 @@ ], "type": "object" }, + "QuoteSummaryModules": { + "enum": [ + "assetProfile", + "balanceSheetHistory", + "balanceSheetHistoryQuarterly", + "calendarEvents", + "cashflowStatementHistory", + "cashflowStatementHistoryQuarterly", + "defaultKeyStatistics", + "earnings", + "earningsHistory", + "earningsTrend", + "financialData", + "fundOwnership", + "fundPerformance", + "fundProfile", + "incomeStatementHistory", + "incomeStatementHistoryQuarterly", + "indexTrend", + "industryTrend", + "insiderHolders", + "insiderTransactions", + "institutionOwnership", + "majorDirectHolders", + "majorHoldersBreakdown", + "netSharePurchaseActivity", + "price", + "quoteType", + "recommendationTrend", + "secFilings", + "sectorTrend", + "summaryDetail", + "summaryProfile", + "symbol", + "topHoldings", + "upgradeDowngradeHistory" + ], + "type": "string" + }, "QuoteSummaryOptions": { "additionalProperties": false, "properties": { @@ -1810,43 +1845,7 @@ "anyOf": [ { "items": { - "enum": [ - "assetProfile", - "balanceSheetHistory", - "balanceSheetHistoryQuarterly", - "calendarEvents", - "cashflowStatementHistory", - "cashflowStatementHistoryQuarterly", - "defaultKeyStatistics", - "earnings", - "earningsHistory", - "earningsTrend", - "financialData", - "fundOwnership", - "fundPerformance", - "fundProfile", - "incomeStatementHistory", - "incomeStatementHistoryQuarterly", - "indexTrend", - "industryTrend", - "insiderHolders", - "insiderTransactions", - "institutionOwnership", - "majorDirectHolders", - "majorHoldersBreakdown", - "netSharePurchaseActivity", - "price", - "quoteType", - "recommendationTrend", - "secFilings", - "sectorTrend", - "summaryDetail", - "summaryProfile", - "symbol", - "topHoldings", - "upgradeDowngradeHistory" - ], - "type": "string" + "$ref": "#/definitions/QuoteSummaryModules" }, "type": "array" }, diff --git a/src/modules/quoteSummary-iface.ts b/src/modules/quoteSummary-iface.ts index 4be076ba..cb9286be 100644 --- a/src/modules/quoteSummary-iface.ts +++ b/src/modules/quoteSummary-iface.ts @@ -91,15 +91,15 @@ export interface BalanceSheetStatement { endDate: Date; cash: number; shortTermInvestments?: number; - netReceivables: number; - inventory: number; + netReceivables?: number; + inventory?: number; otherCurrentAssets: number; totalCurrentAssets: number; longTermInvestments: number; propertyPlantEquipment: number; otherAssets: number; totalAssets: number; - accountsPayable: number; + accountsPayable?: number; shortLongTermDebt?: number; otherCurrentLiab: number; longTermDebt: number; @@ -158,7 +158,7 @@ export interface CashflowStatement { otherCashflowsFromInvestingActivities: number; totalCashflowsFromInvestingActivities: number; dividendsPaid?: number; - netBorrowings: number; + netBorrowings?: number; otherCashflowsFromFinancingActivities: number; totalCashFromFinancingActivities: number; changeInCash: number; diff --git a/src/modules/quoteSummary.spec.ts b/src/modules/quoteSummary.spec.ts index 65a1ccde..8ffcaf9d 100644 --- a/src/modules/quoteSummary.spec.ts +++ b/src/modules/quoteSummary.spec.ts @@ -10,8 +10,21 @@ const yf = { quoteSummary }; -function itValidates(name: QuoteSummaryModules|"all", skip:Array=[]) { - const symbols = ['AAPL','OCDO.L'].filter(s => !skip.includes(s)); +const testSymbols = [ + 'AAPL', // NMS (Nasdaq) + 'OCDO.L', // LSE + 'BABA', // NYSE +]; + +interface itValidatesOpts { + skip?: Array +} + +function itValidates(name: QuoteSummaryModules|"all", opts:itValidatesOpts={}) { + let symbols = testSymbols; + if (opts.skip) // @ts-ignore + symbols = symbols.filter(s => !opts.skip.includes(s)); + const modules = name === 'all' ? 'all' : [name]; symbols.forEach(symbol => { it(`validates ${symbol}`, async () => { @@ -138,7 +151,7 @@ describe('quoteSummary', () => { describe('insiderTransactions', () => { - itValidates("insiderTransactions"); + itValidates("insiderTransactions", { skip: ['BABA'] }); }); @@ -186,7 +199,7 @@ describe('quoteSummary', () => { describe('secFilings', () => { - itValidates("secFilings", ['OCDO.L']); + itValidates("secFilings", { skip: ['OCDO.L','BABA'] }); }); @@ -204,7 +217,7 @@ describe('quoteSummary', () => { describe('upgradeDowngradeHistory', () => { - itValidates("upgradeDowngradeHistory", ['OCDO.L']); + itValidates("upgradeDowngradeHistory", { skip: ['OCDO.L'] }); }); diff --git a/src/modules/quoteSummary.ts b/src/modules/quoteSummary.ts index ce95b7c6..18bd80eb 100644 --- a/src/modules/quoteSummary.ts +++ b/src/modules/quoteSummary.ts @@ -8,7 +8,7 @@ const QUERY_URL = 'https://query2.finance.yahoo.com/v10/finance/quoteSummary'; const QUERY_OPTIONS_SCHEMA_KEY = '#/definitions/QuoteSummaryOptions' const QUERY_RESULT_SCHEMA_KEY = "#/definitions/QuoteSummaryResult"; -const quoteSummary_modules = [ +export const quoteSummary_modules = [ 'assetProfile', 'balanceSheetHistory', 'balanceSheetHistoryQuarterly', @@ -45,7 +45,7 @@ const quoteSummary_modules = [ 'upgradeDowngradeHistory', ]; -type QuoteSummaryModules = +export type QuoteSummaryModules = "assetProfile" | "balanceSheetHistory" | "balanceSheetHistoryQuarterly" |