From e32d053248dfcacb63284f6b82d7cee4d78dc81c Mon Sep 17 00:00:00 2001 From: Akiomi Kamakura Date: Wed, 15 Jun 2022 16:34:39 +0900 Subject: [PATCH] Remove v2 code --- src/__mocks__/api/v2/client.ts | 35 - src/__mocks__/api/v2/indicator-property.ts | 33 - src/__mocks__/api/v2/quarter-property.ts | 33 - src/__mocks__/api/v3/client.ts | 37 +- src/__mocks__/api/v3/http-response.ts | 38 + src/__mocks__/fixtures/v2/company.js | 107 --- .../fixtures/v2/indicator-property.js | 286 ------- src/__mocks__/fixtures/v2/indicator.js | 186 ----- src/__mocks__/fixtures/v2/quarter-property.js | 746 ------------------ src/__mocks__/fixtures/v2/quarter.js | 189 ----- src/__mocks__/services/company-cache.ts | 4 - src/__mocks__/services/indicator-cache.ts | 12 - .../services/indicator-property-cache.ts | 11 - .../services/quarter-property-cache.ts | 11 - src/api/company-service.test.ts | 12 +- src/api/company-service.ts | 15 +- src/api/ondemand-api-period-range.test.ts | 8 +- src/api/v2/caching-client.test.ts | 176 ----- src/api/v2/caching-client.ts | 75 -- src/api/v2/caching-indicator-property.test.ts | 28 - src/api/v2/caching-indicator-property.ts | 15 - src/api/v2/caching-quarter-property.test.ts | 26 - src/api/v2/caching-quarter-property.ts | 15 - src/api/v2/client.test.ts | 130 --- src/api/v2/client.ts | 107 --- src/api/v2/indicator-property.test.ts | 33 - src/api/v2/indicator-property.ts | 41 - src/api/v2/quarter-property.test.ts | 33 - src/api/v2/quarter-property.ts | 41 - src/custom-functions/bcode-label.test.ts | 23 - src/custom-functions/bcode-label.ts | 23 - src/custom-functions/bcode-unit.test.ts | 23 - src/custom-functions/bcode-unit.ts | 23 - src/custom-functions/bcode.test.ts | 33 - src/custom-functions/bcode.ts | 10 +- .../v2/bcode-indicator.test.ts | 38 - src/custom-functions/v2/bcode-indicator.ts | 19 - src/custom-functions/v2/bcode-quarter.test.ts | 52 -- src/custom-functions/v2/bcode-quarter.ts | 43 - src/custom-functions/v2/bcode-result.test.ts | 21 - src/custom-functions/v2/bcode-result.ts | 31 - src/custom-functions/v2/bcode.ts | 102 --- src/custom-functions/v3/bcode-daily.ts | 10 +- src/custom-functions/v3/bcode-quarter.ts | 10 +- src/main.ts | 41 +- src/services/company-cache.test.ts | 12 +- src/services/company-cache.ts | 10 - src/services/csv-exporter.test.ts | 1 - src/services/csv-exporter.ts | 4 - src/services/indicator-cache.test.ts | 26 - src/services/indicator-cache.ts | 28 - src/services/indicator-property-cache.test.ts | 18 - src/services/indicator-property-cache.ts | 22 - src/services/quarter-cache.test.ts | 4 +- src/services/quarter-property-cache.test.ts | 18 - src/services/quarter-property-cache.ts | 22 - 56 files changed, 90 insertions(+), 3060 deletions(-) delete mode 100644 src/__mocks__/api/v2/client.ts delete mode 100644 src/__mocks__/api/v2/indicator-property.ts delete mode 100644 src/__mocks__/api/v2/quarter-property.ts create mode 100644 src/__mocks__/api/v3/http-response.ts delete mode 100644 src/__mocks__/fixtures/v2/company.js delete mode 100644 src/__mocks__/fixtures/v2/indicator-property.js delete mode 100644 src/__mocks__/fixtures/v2/indicator.js delete mode 100644 src/__mocks__/fixtures/v2/quarter-property.js delete mode 100644 src/__mocks__/fixtures/v2/quarter.js delete mode 100644 src/__mocks__/services/indicator-cache.ts delete mode 100644 src/__mocks__/services/indicator-property-cache.ts delete mode 100644 src/__mocks__/services/quarter-property-cache.ts delete mode 100644 src/api/v2/caching-client.test.ts delete mode 100644 src/api/v2/caching-client.ts delete mode 100644 src/api/v2/caching-indicator-property.test.ts delete mode 100644 src/api/v2/caching-indicator-property.ts delete mode 100644 src/api/v2/caching-quarter-property.test.ts delete mode 100644 src/api/v2/caching-quarter-property.ts delete mode 100644 src/api/v2/client.test.ts delete mode 100644 src/api/v2/client.ts delete mode 100644 src/api/v2/indicator-property.test.ts delete mode 100644 src/api/v2/indicator-property.ts delete mode 100644 src/api/v2/quarter-property.test.ts delete mode 100644 src/api/v2/quarter-property.ts delete mode 100644 src/custom-functions/bcode-label.test.ts delete mode 100644 src/custom-functions/bcode-label.ts delete mode 100644 src/custom-functions/bcode-unit.test.ts delete mode 100644 src/custom-functions/bcode-unit.ts delete mode 100644 src/custom-functions/bcode.test.ts delete mode 100644 src/custom-functions/v2/bcode-indicator.test.ts delete mode 100644 src/custom-functions/v2/bcode-indicator.ts delete mode 100644 src/custom-functions/v2/bcode-quarter.test.ts delete mode 100644 src/custom-functions/v2/bcode-quarter.ts delete mode 100644 src/custom-functions/v2/bcode-result.test.ts delete mode 100644 src/custom-functions/v2/bcode-result.ts delete mode 100644 src/custom-functions/v2/bcode.ts delete mode 100644 src/services/indicator-cache.test.ts delete mode 100644 src/services/indicator-cache.ts delete mode 100644 src/services/indicator-property-cache.test.ts delete mode 100644 src/services/indicator-property-cache.ts delete mode 100644 src/services/quarter-property-cache.test.ts delete mode 100644 src/services/quarter-property-cache.ts diff --git a/src/__mocks__/api/v2/client.ts b/src/__mocks__/api/v2/client.ts deleted file mode 100644 index ca18d3e..0000000 --- a/src/__mocks__/api/v2/client.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { default as company } from '~/__mocks__/fixtures/v2/company.js' -import { default as indicator } from '~/__mocks__/fixtures/v2/indicator.js' -import { default as quarter } from '~/__mocks__/fixtures/v2/quarter.js' - -export class BuffettCodeApiClientV2 { - public mockCompany = jest.fn() - public mockIndicator = jest.fn() - public mockQuarter = jest.fn() - - constructor(readonly token: string) { - this.mockCompany.mockReturnValue(company) - this.mockIndicator.mockReturnValue(indicator) - this.mockQuarter.mockReturnValue(quarter) - } - - company(ticker): object | null { - const company = this.mockCompany()[ticker] - return company ? company[0] : null - } - - quarter(ticker): object | null { - const quarter = this.mockQuarter()[ticker] || null - return quarter ? quarter[0] : null - } - - indicator(ticker): object | null { - const indicator = this.mockIndicator()[ticker] - return indicator ? indicator[0] : null - } - - ondemandQuarter(ticker): object | null { - const quarter = this.mockQuarter()[ticker] || null - return quarter ? quarter[0] : null - } -} diff --git a/src/__mocks__/api/v2/indicator-property.ts b/src/__mocks__/api/v2/indicator-property.ts deleted file mode 100644 index 87cd3ed..0000000 --- a/src/__mocks__/api/v2/indicator-property.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { default as indicator } from '~/__mocks__/fixtures/v2/indicator-property' - -export class IndicatorProperty { - static fetch(): object { - return indicator - } - - static isIndicatorProperty(name: string): boolean { - return Object.keys(this.fetch()).indexOf(name) >= 0 - } - - static labelOf(name: string): string | null { - const property = this.fetch()[name] - if (!property) { - return null - } - - return property.name_jp - } - - static unitOf(name: string): string | null { - const property = this.fetch()[name] - if (!property) { - return null - } - - return property.unit - } - - static names(): string[] { - return Object.keys(this.fetch()) - } -} diff --git a/src/__mocks__/api/v2/quarter-property.ts b/src/__mocks__/api/v2/quarter-property.ts deleted file mode 100644 index 22e597f..0000000 --- a/src/__mocks__/api/v2/quarter-property.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { default as quarter } from '~/__mocks__/fixtures/v2/quarter-property' - -export class QuarterProperty { - static fetch(): object { - return quarter - } - - static isQuarterProperty(name: string): boolean { - return Object.keys(this.fetch()).indexOf(name) >= 0 - } - - static labelOf(name: string): string | null { - const property = this.fetch()[name] - if (!property) { - return null - } - - return property.name_jp - } - - static unitOf(name: string): string | null { - const property = this.fetch()[name] - if (!property) { - return null - } - - return property.unit - } - - static names(): string[] { - return Object.keys(this.fetch()) - } -} diff --git a/src/__mocks__/api/v3/client.ts b/src/__mocks__/api/v3/client.ts index 0f86d63..521a6ee 100644 --- a/src/__mocks__/api/v3/client.ts +++ b/src/__mocks__/api/v3/client.ts @@ -1,6 +1,8 @@ +import { HTTPResnpose } from '~/__mocks__/api/v3/http-response' import { default as company } from '~/__mocks__/fixtures/v3/company.js' import { default as daily } from '~/__mocks__/fixtures/v3/daily.js' import { default as quarter } from '~/__mocks__/fixtures/v3/quarter.js' +import { HttpError } from '~/api/http-error' import { Daily } from '~/entities/v3/daily' import { Quarter } from '~/entities/v3/quarter' @@ -15,23 +17,48 @@ export class BuffettCodeApiClientV3 { this.mockQuarter.mockReturnValue(quarter) } - company(): object { + company(ticker: string): object { + if (ticker !== '2371') { + const res = new HTTPResnpose() + throw new HttpError('/v3/company', res) + } + return this.mockCompany()['data'] } - quarter(): Quarter { + quarter(ticker: string): Quarter { + if (ticker !== '2371') { + const res = new HTTPResnpose() + throw new HttpError('/v3/company', res) + } + return Quarter.fromResponse(this.mockQuarter()) } - daily(): Daily { + daily(ticker: string): Daily { + if (ticker !== '2371') { + const res = new HTTPResnpose() + throw new HttpError('/v3/company', res) + } + return Daily.fromResponse(this.mockDaily()) } - ondemandDaily(): Daily { + ondemandDaily(ticker: string): Daily { + if (ticker !== '2371') { + const res = new HTTPResnpose() + throw new HttpError('/v3/company', res) + } + return Daily.fromResponse(this.mockDaily()) } - ondemandQuarter(): Quarter { + ondemandQuarter(ticker: string): Quarter { + if (ticker !== '2371') { + const res = new HTTPResnpose() + throw new HttpError('/v3/company', res) + } + return Quarter.fromResponse(this.mockQuarter()) } } diff --git a/src/__mocks__/api/v3/http-response.ts b/src/__mocks__/api/v3/http-response.ts new file mode 100644 index 0000000..9807b4f --- /dev/null +++ b/src/__mocks__/api/v3/http-response.ts @@ -0,0 +1,38 @@ +// GoogleAppsScript.URL_Fetch.HTTPResponseと同じI/F +export class HTTPResnpose { + getResponseCode(): number { + return 404 + } + + getContent(): number[] { + const text = this.getContentText() + const content = [] + + for (let i = 0; i < text.length; i++) { + content.push(text.charCodeAt(i)) + } + + return content + } + + getContentText(): string { + return 'NOT FOUND' + } + + getAllHeaders(): object { + return {} + } + + getHeaders(): object { + return {} + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + getAs(contentType: string): GoogleAppsScript.Base.Blob { + return null + } + + getBlob(): GoogleAppsScript.Base.Blob { + return null + } +} diff --git a/src/__mocks__/fixtures/v2/company.js b/src/__mocks__/fixtures/v2/company.js deleted file mode 100644 index fa498cb..0000000 --- a/src/__mocks__/fixtures/v2/company.js +++ /dev/null @@ -1,107 +0,0 @@ -module.exports = { - 2371: [ - { - tosyo_33category: 'サービス業', - url: 'http://corporate.kakaku.com/', - company_name: 'カカクコム', - company_name_en: 'Kakaku.com Inc.', - fiscal_month: 3.0, - established_date: '1997/12/01', - listing_date: '2003/10/09', - priority_market: 't1', - accounting_standard: 'IFRS', - latest_fiscal_year: 2021.0, - latest_fiscal_quarter: 2.0, - oldest_fiscal_year: 2001.0, - oldest_fiscal_quarter: 4.0, - oldest_date: '2003-10-10', - fixed_tier_range: { - oldest_fiscal_year: 2016.0, - oldest_fiscal_quarter: 3.0, - latest_fiscal_year: 2021.0, - latest_fiscal_quarter: 2.0, - oldest_date: '2016-11-13T00:00:00.000Z' - } - } - ], - column_description: { - tosyo_33category: { - name_jp: '東証33業種', - unit: 'なし' - }, - url: { - name_jp: '会社URL', - unit: 'なし' - }, - company_name: { - name_jp: '会社名', - unit: 'なし' - }, - company_name_en: { - name_jp: '会社英名', - unit: 'なし' - }, - fiscal_month: { - name_jp: '決算月', - unit: 'なし' - }, - established_date: { - name_jp: '設立日', - unit: 'なし' - }, - listing_date: { - name_jp: '上場日', - unit: 'なし' - }, - priority_market: { - name_jp: '優先市場', - unit: 'なし' - }, - accounting_standard: { - name_jp: '会計基準', - unit: 'なし' - }, - latest_fiscal_year: { - name_jp: '直近決算年度', - unit: 'なし' - }, - latest_fiscal_quarter: { - name_jp: '直近決算四半期', - unit: 'なし' - }, - oldest_fiscal_year: { - name_jp: '取得可能な最古の決算年度', - unit: 'なし' - }, - oldest_fiscal_quarter: { - name_jp: '取得可能な最古の決算四半期', - unit: 'なし' - }, - oldest_date: { - name_jp: '取得可能な最古の日付', - unit: 'なし' - }, - fixed_tier_range: { - oldest_fiscal_year: { - name_jp: '定額利用可能な下限の決算年度', - unit: 'なし' - }, - oldest_fiscal_quarter: { - name_jp: '定額利用可能な下限の決算四半期', - unit: 'なし' - }, - latest_fiscal_year: { - name_jp: '定額利用可能な上限の決算年度', - unit: 'なし' - }, - latest_fiscal_quarter: { - name_jp: '定額利用可能な上限の決算四半期', - unit: 'なし' - }, - oldest_date: { - name_jp: '定額利用可能な下限の日付', - unit: 'なし' - } - } - } -} diff --git a/src/__mocks__/fixtures/v2/indicator-property.js b/src/__mocks__/fixtures/v2/indicator-property.js deleted file mode 100644 index 05ec207..0000000 --- a/src/__mocks__/fixtures/v2/indicator-property.js +++ /dev/null @@ -1,286 +0,0 @@ -module.exports = { - stockprice: { - name_jp: '株価', - unit: '円' - }, - trading_volume: { - name_jp: '出来高', - unit: '株' - }, - num_of_shares: { - name_jp: '株式数', - unit: '株' - }, - market_capital: { - name_jp: '時価総額', - unit: '百万円' - }, - enterprise_value: { - name_jp: '企業価値', - unit: '百万円' - }, - eps_forecast: { - name_jp: 'EPS(会社予想)', - unit: '円' - }, - eps_actual: { - name_jp: 'EPS(実績)', - unit: '円' - }, - per_forecast: { - name_jp: 'PER(会社予想)', - unit: '倍' - }, - bps: { - name_jp: 'BPS', - unit: '円' - }, - pbr: { - name_jp: 'PBR', - unit: '倍' - }, - per_pbr: { - name_jp: 'PER×PBR', - unit: '単位無し' - }, - ebitda_forecast: { - name_jp: 'EBITDA(会社予想)', - unit: '百万円' - }, - ebitda_actual: { - name_jp: 'EBITDA(実績)', - unit: '百万円' - }, - ev_ebitda_forecast: { - name_jp: 'EV/EBITDA(会社予想)', - unit: '倍' - }, - psr_forecast: { - name_jp: 'PSR(会社予想)', - unit: '倍' - }, - pcfr_forecast: { - name_jp: 'PCFR', - unit: '倍' - }, - listed_years: { - name_jp: '上場年数', - unit: '年' - }, - roe: { - name_jp: 'ROE', - unit: '%' - }, - real_roe: { - name_jp: '実質ROE', - unit: '%' - }, - net_profit_margin: { - name_jp: '当期純利益率', - unit: '%' - }, - total_asset_turnover: { - name_jp: '総資産回転率', - unit: '倍' - }, - financial_leverage: { - name_jp: '財務レバレッジ', - unit: '倍' - }, - roa: { - name_jp: 'ROA', - unit: '%' - }, - roic: { - name_jp: 'ROIC', - unit: '%' - }, - dividend_yield_forecast: { - name_jp: '配当利回り(会社予想)', - unit: '%' - }, - dividend_yield_actual: { - name_jp: '配当利回り(実績)', - unit: '%' - }, - dividend_payout_ratio: { - name_jp: '配当性向', - unit: '%' - }, - doe: { - name_jp: '自己資本配当率', - unit: '%' - }, - gross_margin: { - name_jp: '売上高総利益率', - unit: '%' - }, - operating_margin: { - name_jp: '営業利益率', - unit: '%' - }, - net_sales_operating_cash_flow_ratio: { - name_jp: '営業キャッシュフロー/売上比率', - unit: '%' - }, - sga_ratio: { - name_jp: '販管費/売上率', - unit: '%' - }, - depreciation_gross_profit_ratio: { - name_jp: '減価償却費/粗利比率', - unit: '%' - }, - r_and_d_ratio: { - name_jp: '研究開発費/売上比率', - unit: '%' - }, - interest_op_income_ratio: { - name_jp: '支払利息/営業利益比率', - unit: '%' - }, - interest_coverage_ratio: { - name_jp: 'インタレストカバレッジレシオ', - unit: '倍' - }, - real_corp_tax_rate: { - name_jp: '実質法人税率', - unit: '%' - }, - net_sales_progress: { - name_jp: '売上進捗率', - unit: '%' - }, - operating_income_progress: { - name_jp: '営業利益進捗率', - unit: '%' - }, - net_income_progress: { - name_jp: '純利益進捗率', - unit: '%' - }, - net_sales_growth_rate_forecast: { - name_jp: '売上高成長率(直近年度実績→会社予想)', - unit: '%' - }, - operating_income_growth_rate_forecast: { - name_jp: '営業利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - net_income_growth_rate_forecast: { - name_jp: '純利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - net_sales_per_employee: { - name_jp: '従業員一人あたり売上', - unit: '百万円' - }, - operating_income_per_employee: { - name_jp: '従業員一人あたり営業利益', - unit: '百万円' - }, - trade_receivables: { - name_jp: '売上債権', - unit: '百万円' - }, - accounts_receivable_turnover: { - name_jp: '売上債権回転期間', - unit: '日' - }, - inventory_turnover: { - name_jp: '棚卸資産回転期間', - unit: '日' - }, - trade_payables: { - name_jp: '仕入債務', - unit: '百万円' - }, - trade_payable_turnover: { - name_jp: '仕入債務回転期間', - unit: '日' - }, - working_capital: { - name_jp: '運転資本', - unit: '百万円' - }, - ccc: { - name_jp: 'CCC', - unit: '日' - }, - tangible_fixed_assets_turnover: { - name_jp: '有形固定資産回転率', - unit: '%' - }, - debt: { - name_jp: '有利子負債', - unit: '百万円' - }, - debt_assets_ratio: { - name_jp: '有利子負債/総資産比率', - unit: '%' - }, - debt_monthly_sales_ratio: { - name_jp: '有利子負債/月商比率', - unit: 'ヶ月' - }, - debt_market_capital_ratio: { - name_jp: '有利子負債/時価総額比率', - unit: '倍' - }, - operating_cash_flow_debt_ratio: { - name_jp: '有利子負債/営業キャッシュフロー倍率', - unit: '倍' - }, - net_debt: { - name_jp: '純有利子負債', - unit: '百万円' - }, - adjusted_debt_ratio: { - name_jp: '自己株式調整済み負債比率', - unit: '%' - }, - de_ratio: { - name_jp: 'DE比率', - unit: '%' - }, - current_ratio: { - name_jp: '流動比率', - unit: '%' - }, - net_debt_net_income_ratio: { - name_jp: 'ネットD純利益比率', - unit: '倍' - }, - equity: { - name_jp: '自己資本', - unit: '百万円' - }, - equity_ratio: { - name_jp: '自己資本比率', - unit: '%' - }, - free_cash_flow: { - name_jp: 'フリーキャッシュフロー', - unit: '百万円' - }, - cash_market_capital_ratio: { - name_jp: 'キャッシュ時価総額比率', - unit: '%' - }, - cash_assets_ratio: { - name_jp: 'キャッシュ総資産比率', - unit: '%' - }, - cash_monthly_sales_ratio: { - name_jp: 'キャッシュ売上倍率', - unit: '倍' - }, - accrual: { - name_jp: 'アクルーアル', - unit: '百万円' - }, - day: { - name_jp: '日時', - unit: 'なし' - } -} diff --git a/src/__mocks__/fixtures/v2/indicator.js b/src/__mocks__/fixtures/v2/indicator.js deleted file mode 100644 index 1ae6fc2..0000000 --- a/src/__mocks__/fixtures/v2/indicator.js +++ /dev/null @@ -1,186 +0,0 @@ -module.exports = { - '2371': [ - { - stockprice: 2287.0, - trading_volume: 398200.0, - num_of_shares: 210605000.0, - market_capital: 481653635000.0, - enterprise_value: 462429635000.0, - eps_forecast: 81.14717124474727, - eps_actual: 74.54238978181904, - per_forecast: 28.18336073727326, - bps: 169.68732936065146, - pbr: 13.47772994375577, - per_pbr: 379.84772492441857, - ebitda_forecast: 26781000000.0, - ebitda_actual: 24457000000.0, - ev_ebitda_forecast: 17.26707871252007, - psr_forecast: 9.262569903846154, - pcfr_forecast: 25.79688474104226, - listed_years: null, - roe: 43.929260990010356, - real_roe: 39.53810507228127, - net_profit_margin: 33.55777863280749, - total_asset_turnover: 1.0589673359440432, - financial_leverage: 1.2361697960097378, - roa: 35.53659143898409, - roic: 43.47574739855751, - ex_dividend: 36.0, - dividend: 32.0, - dividend_yield_forecast: 1.5741145605596851, - dividend_yield_actual: null, - dividend_payout_ratio: 42.92859417797312, - doe: 18.8582141757842, - gross_margin: 48.473771963575736, - operating_margin: 48.89914924543628, - net_sales_operating_cash_flow_ratio: 34.20118849130007, - sga_ratio: -0.4253772818605447, - depreciation_gross_profit_ratio: 6.971821669533007, - r_and_d_ratio: 0.0, - interest_op_income_ratio: 0.0, - interest_coverage_ratio: null, - real_corp_tax_rate: 31.038562664329536, - net_sales_progress: 0.0, - operating_income_progress: 0.0, - net_income_progress: 0.0, - net_sales_growth_rate_forecast: 11.15386259672524, - operating_income_growth_rate_forecast: 10.159118727050176, - net_income_growth_rate_forecast: 8.860436970507667, - net_sales_per_employee: 54972972.972972974, - operating_income_per_employee: 26881316.098707404, - trade_receivables: 8379000000.0, - accounts_receivable_turnover: 65.37418237783763, - inventories: null, - inventory_turnover: null, - trade_payables: 2486000000.0, - trade_payable_turnover: 37.643227546152254, - working_capital: null, - ccc: null, - tangible_fixed_assets_turnover: null, - debt: 589000000.0, - debt_assets_ratio: 1.333272970097562, - debt_monthly_sales_ratio: 0.15108375016031808, - debt_market_capital_ratio: 0.12228704554466821, - operating_cash_flow_debt_ratio: 3.68125, - net_debt: -19224000000.0, - adjusted_debt_ratio: 19.653064267607736, - de_ratio: 0.016481517754708006, - current_ratio: 411.0206896551724, - net_debt_net_income_ratio: -1.2245365946875597, - equity: 35737000000.0, - equity_ratio: 80.8950358783983, - free_cash_flow: 7585000000.0, - cash_market_capital_ratio: 4.113536898771667, - cash_assets_ratio: 44.84912963759422, - cash_monthly_sales_ratio: 5.082211106835962, - accrual: -310000000.0, - day: '2019-04-19T00:00:00.000Z' - } - ], - column_description: { - stockprice: { name_jp: '株価', unit: '円' }, - trading_volume: { name_jp: '出来高', unit: '株' }, - num_of_shares: { name_jp: '株式数', unit: '株' }, - market_capital: { name_jp: '時価総額', unit: '百万円' }, - enterprise_value: { name_jp: '企業価値', unit: '百万円' }, - eps_forecast: { name_jp: 'EPS(会社予想)', unit: '円' }, - eps_actual: { name_jp: 'EPS(実績)', unit: '円' }, - per_forecast: { name_jp: 'PER(会社予想)', unit: '倍' }, - bps: { name_jp: 'BPS', unit: '円' }, - pbr: { name_jp: 'PBR', unit: '倍' }, - per_pbr: { name_jp: 'PER×PBR', unit: '単位無し' }, - ebitda_forecast: { name_jp: 'EBITDA(会社予想)', unit: '百万円' }, - ebitda_actual: { name_jp: 'EBITDA(実績)', unit: '百万円' }, - ev_ebitda_forecast: { name_jp: 'EV/EBITDA(会社予想)', unit: '倍' }, - psr_forecast: { name_jp: 'PSR(会社予想)', unit: '倍' }, - pcfr_forecast: { name_jp: 'PCFR', unit: '倍' }, - listed_years: { name_jp: '上場年数', unit: '年' }, - roe: { name_jp: 'ROE', unit: '%' }, - real_roe: { name_jp: '実質ROE', unit: '%' }, - net_profit_margin: { name_jp: '当期純利益率', unit: '%' }, - total_asset_turnover: { name_jp: '総資産回転率', unit: '倍' }, - financial_leverage: { name_jp: '財務レバレッジ', unit: '倍' }, - roa: { name_jp: 'ROA', unit: '%' }, - roic: { name_jp: 'ROIC', unit: '%' }, - ex_dividend: { name_jp: '配当金(会社予想)', unit: '円' }, - dividend: { name_jp: '配当金(実績)', unit: '円' }, - dividend_yield_forecast: { name_jp: '配当利回り(会社予想)', unit: '%' }, - dividend_yield_actual: { name_jp: '配当利回り(実績)', unit: '%' }, - dividend_payout_ratio: { name_jp: '配当性向', unit: '%' }, - doe: { name_jp: '自己資本配当率', unit: '%' }, - gross_margin: { name_jp: '売上高総利益率', unit: '%' }, - operating_margin: { name_jp: '営業利益率', unit: '%' }, - net_sales_operating_cash_flow_ratio: { - name_jp: '営業キャッシュフロー/売上比率', - unit: '%' - }, - sga_ratio: { name_jp: '販管費/売上率', unit: '%' }, - depreciation_gross_profit_ratio: { - name_jp: '減価償却費/粗利比率', - unit: '%' - }, - r_and_d_ratio: { name_jp: '研究開発費/売上比率', unit: '%' }, - interest_op_income_ratio: { name_jp: '支払利息/営業利益比率', unit: '%' }, - interest_coverage_ratio: { - name_jp: 'インタレストカバレッジレシオ ', - unit: '倍' - }, - real_corp_tax_rate: { name_jp: '実質法人税率', unit: '%' }, - net_sales_progress: { name_jp: '売上進捗率', unit: '%' }, - operating_income_progress: { name_jp: '営業利益進捗率', unit: '%' }, - net_income_progress: { name_jp: '純利益進捗率', unit: '%' }, - net_sales_growth_rate_forecast: { - name_jp: '売上高成長率(直近年度実績→会社予想)', - unit: '%' - }, - operating_income_growth_rate_forecast: { - name_jp: '営業利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - net_income_growth_rate_forecast: { - name_jp: '純利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - net_sales_per_employee: { name_jp: '従業員一人あたり売上', unit: '百万円' }, - operating_income_per_employee: { - name_jp: '従業員一人あたり営業利益', - unit: '百万円' - }, - trade_receivables: { name_jp: '売上債権', unit: '百万円' }, - accounts_receivable_turnover: { name_jp: '売上債権回転期間', unit: '日' }, - inventories: { name_jp: '棚卸資産', unit: '百万円' }, - inventory_turnover: { name_jp: '棚卸資産回転期間', unit: '日' }, - trade_payables: { name_jp: '仕入債務', unit: '百万円' }, - trade_payable_turnover: { name_jp: '仕入債務回転期間', unit: '日' }, - working_capital: { name_jp: '運転資本', unit: '百万円' }, - ccc: { name_jp: 'CCC', unit: '日' }, - tangible_fixed_assets_turnover: { - name_jp: '有形固定資産回転率', - unit: '%' - }, - debt: { name_jp: '有利子負債', unit: '百万円' }, - debt_assets_ratio: { name_jp: '有利子負債/総資産比率', unit: '%' }, - debt_monthly_sales_ratio: { name_jp: '有利子負債/月商比率', unit: 'ヶ月' }, - debt_market_capital_ratio: { - name_jp: '有利子負債/時価総額比率', - unit: '倍' - }, - operating_cash_flow_debt_ratio: { - name_jp: '有利子負債/営業キャッシュフロー倍率', - unit: '倍' - }, - net_debt: { name_jp: '純有利子負債', unit: '百万円' }, - adjusted_debt_ratio: { name_jp: '自己株式調整済み負債比率', unit: '%' }, - de_ratio: { name_jp: 'DE比率', unit: '%' }, - current_ratio: { name_jp: '流動比率', unit: '%' }, - net_debt_net_income_ratio: { name_jp: 'ネットD純利益比率', unit: '倍' }, - equity: { name_jp: '自己資本', unit: '百万円' }, - equity_ratio: { name_jp: '自己資本比率', unit: '%' }, - free_cash_flow: { name_jp: 'フリーキャッシュフロー', unit: '百万円' }, - cash_market_capital_ratio: { name_jp: 'キャッシュ時価総額比率', unit: '%' }, - cash_assets_ratio: { name_jp: 'キャッシュ総資産比率', unit: '%' }, - cash_monthly_sales_ratio: { name_jp: 'キャッシュ売上倍率', unit: '倍' }, - accrual: { name_jp: 'アクルーアル ', unit: '百万円' }, - day: { name_jp: '日時', unit: 'なし' } - } -} diff --git a/src/__mocks__/fixtures/v2/quarter-property.js b/src/__mocks__/fixtures/v2/quarter-property.js deleted file mode 100644 index d284384..0000000 --- a/src/__mocks__/fixtures/v2/quarter-property.js +++ /dev/null @@ -1,746 +0,0 @@ -module.exports = { - company_name: { - name_jp: '社名', - unit: 'なし' - }, - ceo_name: { - name_jp: '代表者名', - unit: 'なし' - }, - headquarters_address: { - name_jp: '所在地', - unit: 'なし' - }, - end_date: { - name_jp: '有価証券報告書の期末日', - unit: '日付' - }, - edinet_updated_date: { - name_jp: 'edinet発行日', - unit: '日付' - }, - tdnet_updated_date: { - name_jp: 'tdnet発行日', - unit: '日付' - }, - edinet_title: { - name_jp: 'edinet開示資料名', - unit: 'なし' - }, - tdnet_title: { - name_jp: 'tdnet開示資料名', - unit: 'なし' - }, - accounting_standard: { - name_jp: '会計基準', - unit: 'なし' - }, - num_of_shares: { - name_jp: '株式総数', - unit: '株' - }, - issued_share_num: { - name_jp: '発行済株式総数', - unit: '株' - }, - treasury_stock_num: { - name_jp: '自己株数', - unit: '株' - }, - assets: { - name_jp: '総資産', - unit: '百万円' - }, - current_assets: { - name_jp: '流動資産', - unit: '百万円' - }, - cash_and_deposits: { - name_jp: '現預金', - unit: '百万円' - }, - trade_receivables: { - name_jp: '売上債権', - unit: '百万円' - }, - notes_accounts_receivable: { - name_jp: '受取手形および売掛金', - unit: '百万円' - }, - notes_receivable: { - name_jp: '受取手形', - unit: '百万円' - }, - accounts_receivable: { - name_jp: '売掛金', - unit: '百万円' - }, - current_securities: { - name_jp: '有価証券', - unit: '百万円' - }, - inventories: { - name_jp: '棚卸資産', - unit: '百万円' - }, - merchandise: { - name_jp: '商品', - unit: '百万円' - }, - work_in_process: { - name_jp: '仕掛品', - unit: '百万円' - }, - raw_materials_and_supplies: { - name_jp: '原材料', - unit: '百万円' - }, - prepaid_expenses: { - name_jp: '前払金', - unit: '百万円' - }, - current_dta: { - name_jp: '繰延税金資産(流動)', - unit: '百万円' - }, - current_allowance_doubtful_accounts: { - name_jp: '貸倒引当金', - unit: '百万円' - }, - non_current_assets: { - name_jp: '固定資産', - unit: '百万円' - }, - tangible_fixed_assets: { - name_jp: '有形固定資産', - unit: '百万円' - }, - buildings: { - name_jp: '建物・構築物', - unit: '百万円' - }, - machineries: { - name_jp: '機械・運搬具・工具', - unit: '百万円' - }, - land: { - name_jp: '土地', - unit: '百万円' - }, - construction_in_progress: { - name_jp: '建設仮勘定', - unit: '百万円' - }, - intangible_assets: { - name_jp: '無形固定資産', - unit: '百万円' - }, - good_will: { - name_jp: 'のれん', - unit: '百万円' - }, - investments_and_other_assets: { - name_jp: '投資その他の資産', - unit: '百万円' - }, - investment_securities: { - name_jp: '投資有価証券', - unit: '百万円' - }, - non_current_dta: { - name_jp: '繰延税金資産(固定)', - unit: '百万円' - }, - non_current_allowance_doubtful_accounts: { - name_jp: '貸倒引当金', - unit: '百万円' - }, - lease_and_guarantee_deposits: { - name_jp: '敷金および保証金', - unit: '百万円' - }, - liabilities: { - name_jp: '負債', - unit: '百万円' - }, - debt: { - name_jp: '有利子負債', - unit: '百万円' - }, - current_liabilities: { - name_jp: '流動負債', - unit: '百万円' - }, - trade_payables: { - name_jp: '仕入債務', - unit: '百万円' - }, - notes_accounts_payable: { - name_jp: '支払手形および買掛金', - unit: '百万円' - }, - accounts_payable: { - name_jp: '買掛金', - unit: '百万円' - }, - notes_payable: { - name_jp: '支払手形', - unit: '百万円' - }, - short_term_bonds_payable: { - name_jp: '短期社債', - unit: '百万円' - }, - short_term_loans_payable: { - name_jp: '短期借入金', - unit: '百万円' - }, - commercial_papers_liabilities: { - name_jp: 'コマーシャルペーパー', - unit: '百万円' - }, - current_lease_obligations: { - name_jp: 'リース債務(流動負債)', - unit: '百万円' - }, - current_portion_of_long_term_loans: { - name_jp: '1年以内返済の長期借入金', - unit: '百万円' - }, - current_portion_of_bonds: { - name_jp: '1年以内返済の社債', - unit: '百万円' - }, - current_portion_of_convertible_bonds: { - name_jp: '1年以内返済の転換社債', - unit: '百万円' - }, - current_portion_of_bonds_with_subscription_rights: { - name_jp: '1年以内返済の新株予約権付社債', - unit: '百万円' - }, - advances_received: { - name_jp: '前受金', - unit: '百万円' - }, - corporate_tax_payable: { - name_jp: '未払法人税等', - unit: '百万円' - }, - non_current_liabilities: { - name_jp: '固定負債', - unit: '百万円' - }, - bonds_payable: { - name_jp: '社債', - unit: '百万円' - }, - convertible_bonds: { - name_jp: '転換社債', - unit: '百万円' - }, - convertible_bond_type_bonds_with_subscription_rights: { - name_jp: '新株予約権付転換社債', - unit: '百万円' - }, - non_current_bonds_with_subscription_right: { - name_jp: '新株予約権付社債', - unit: '百万円' - }, - long_term_loans_payable: { - name_jp: '長期借入金', - unit: '百万円' - }, - non_current_lease_obligations: { - name_jp: 'リース債務(固定負債)', - unit: '百万円' - }, - non_current_dtl: { - name_jp: '繰延税金負債(固定)', - unit: '百万円' - }, - net_assets: { - name_jp: '純資産', - unit: '百万円' - }, - shareholders_equity: { - name_jp: '株主資本', - unit: '百万円' - }, - capital_stock: { - name_jp: '資本金', - unit: '百万円' - }, - additional_capital_stock: { - name_jp: '資本剰余金', - unit: '百万円' - }, - retained_earnings: { - name_jp: '利益剰余金', - unit: '百万円' - }, - treasury_stock: { - name_jp: '自己株式', - unit: '百万円' - }, - valuation_and_translation_adjustments: { - name_jp: '評価換算差額等', - unit: '百万円' - }, - non_controlling_interests: { - name_jp: '非支配持分', - unit: '百万円' - }, - net_sales: { - name_jp: '売上', - unit: '百万円' - }, - cost_of_sales: { - name_jp: '売上原価', - unit: '百万円' - }, - gross_profit: { - name_jp: '売上高総利益', - unit: '百万円' - }, - gross_margin: { - name_jp: '売上高総利益率', - unit: '%' - }, - sga: { - name_jp: '販売費および一般管理費', - unit: '百万円' - }, - operating_income: { - name_jp: '営業利益', - unit: '百万円' - }, - operating_margin: { - name_jp: '営業利益率', - unit: '%' - }, - non_operating_income: { - name_jp: '営業外収益', - unit: '百万円' - }, - interest_and_dividends_income: { - name_jp: '受取利息および受取配当金', - unit: '百万円' - }, - interest_income: { - name_jp: '受取利息', - unit: '百万円' - }, - dividends_income: { - name_jp: '受取配当金', - unit: '百万円' - }, - equity_method_income: { - name_jp: '持分法による投資利益', - unit: '百万円' - }, - non_operating_expenses: { - name_jp: '営業外費用', - unit: '百万円' - }, - interest_expense: { - name_jp: '支払利息', - unit: '百万円' - }, - equity_method_loss: { - name_jp: '持分法による投資損失', - unit: '百万円' - }, - ordinary_income: { - name_jp: '経常利益', - unit: '百万円' - }, - extraordinary_income: { - name_jp: '特別利益', - unit: '百万円' - }, - gain_of_sales_non_current_assets: { - name_jp: '固定資産売却益', - unit: '百万円' - }, - gain_of_sales_investment_securities: { - name_jp: '投資有価証券売却益', - unit: '百万円' - }, - extraordinary_loss: { - name_jp: '特別損失', - unit: '百万円' - }, - loss_of_sales_non_current_assets: { - name_jp: '固定資産売却損', - unit: '百万円' - }, - loss_of_valuation_investment_securities: { - name_jp: '投資有価証券売却損', - unit: '百万円' - }, - impairment_loss: { - name_jp: '減損損失', - unit: '百万円' - }, - income_before_income_taxes: { - name_jp: '税引前当期純利益', - unit: '百万円' - }, - income_taxes: { - name_jp: '法人税等', - unit: '百万円' - }, - real_corporate_tax_rate: { - name_jp: '実質法人税率', - unit: '%' - }, - net_income: { - name_jp: '当期純利益', - unit: '百万円' - }, - non_controling_interests: { - name_jp: '非支配株主に帰属する当期純利益', - unit: '百万円' - }, - profit_loss_attributable_to_owners_of_parent: { - name_jp: '親会社株主に帰属する当期純利益', - unit: '百万円' - }, - net_profit_margin: { - name_jp: '当期純利益率', - unit: '%' - }, - operating_cash_flow: { - name_jp: '営業キャッシュフロー', - unit: '百万円' - }, - income_before_taxes: { - name_jp: '税金等調整前当期純利益', - unit: '百万円' - }, - depreciation: { - name_jp: '減価償却費', - unit: '百万円' - }, - amortization: { - name_jp: 'のれん償却費', - unit: '百万円' - }, - decrease_trade_receivables_op_cf: { - name_jp: '売上債権の増減額', - unit: '百万円' - }, - decrease_inventories_op_cf: { - name_jp: '棚卸資産の増減額', - unit: '百万円' - }, - increase_trade_payables_op_cf: { - name_jp: '仕入債務の増減額', - unit: '百万円' - }, - investment_cash_flow: { - name_jp: '投資キャッシュフロー', - unit: '百万円' - }, - purchase_of_property: { - name_jp: '有形固定資産の取得による支出', - unit: '百万円' - }, - sale_of_property: { - name_jp: '有形固定資産の売却による収入', - unit: '百万円' - }, - purchase_of_intangible_assets: { - name_jp: '無形固定資産の取得による支出', - unit: '百万円' - }, - sale_of_intangible_assets: { - name_jp: '無形固定資産の売却による収入', - unit: '百万円' - }, - purchase_of_non_current_assets: { - name_jp: '固定資産の取得による支出', - unit: '百万円' - }, - sale_of_non_current_assets: { - name_jp: '固定資産の売却による収入', - unit: '百万円' - }, - purchase_of_securities: { - name_jp: '有価証券の取得による支出', - unit: '百万円' - }, - sale_of_securities: { - name_jp: '有価証券の売却・償還による収入', - unit: '百万円' - }, - purchase_of_investment_securities: { - name_jp: '投資有価証券の取得による支出', - unit: '百万円' - }, - sale_of_investment_securities: { - name_jp: '投資有価証券の売却・償還による収入', - unit: '百万円' - }, - lending: { - name_jp: '貸付けによる支出', - unit: '百万円' - }, - return_of_lending: { - name_jp: '貸付金の回収による収入', - unit: '百万円' - }, - financial_cash_flow: { - name_jp: '財務キャッシュフロー', - unit: '百万円' - }, - net_short_term_debt: { - name_jp: '短期借入金の純増減額', - unit: '百万円' - }, - long_term_debt_issuance: { - name_jp: '長期借入れによる収入', - unit: '百万円' - }, - long_term_debt_repayment: { - name_jp: '長期借入金の返済による支出', - unit: '百万円' - }, - bonds_issuance: { - name_jp: '社債の発行による収入', - unit: '百万円' - }, - bonds_repayment: { - name_jp: '社債の償還による支出', - unit: '百万円' - }, - share_repurchase: { - name_jp: '自己株式の取得による支出', - unit: '百万円' - }, - share_sales: { - name_jp: '自己株式の売却による収入', - unit: '百万円' - }, - dividend_payment: { - name_jp: '配当金の支払額', - unit: '百万円' - }, - cash_translation_difference: { - name_jp: '現金及び現金同等物に係る換算差額', - unit: '百万円' - }, - free_cash_flow: { - name_jp: 'フリーキャッシュフロー', - unit: '百万円' - }, - ex_net_sales: { - name_jp: '売上(会社予想)', - unit: '百万円' - }, - ex_operating_income: { - name_jp: '営業利益(会社予想)', - unit: '百万円' - }, - ex_ordinary_income: { - name_jp: '経常利益(会社予想)', - unit: '百万円' - }, - ex_net_income: { - name_jp: '当期純利益(会社予想)', - unit: '百万円' - }, - dividend: { - name_jp: '配当金(実績)', - unit: '円' - }, - eps_actual: { - name_jp: 'EPS(実績)', - unit: '円' - }, - bps: { - name_jp: 'BPS', - unit: '円' - }, - ebitda_forecast: { - name_jp: 'EBITDA(会社予想)', - unit: '百万円' - }, - ebitda_actual: { - name_jp: 'EBITDA(実績)', - unit: '百万円' - }, - roe: { - name_jp: 'ROE', - unit: '%' - }, - real_roe: { - name_jp: '実質ROE', - unit: '%' - }, - total_asset_turnover: { - name_jp: '総資産回転率', - unit: '倍' - }, - financial_leverage: { - name_jp: '財務レバレッジ', - unit: '倍' - }, - roa: { - name_jp: 'ROA', - unit: '%' - }, - roic: { - name_jp: 'ROIC', - unit: '%' - }, - doe: { - name_jp: '自己資本配当率', - unit: '%' - }, - net_sales_operating_cash_flow_ratio: { - name_jp: '営業キャッシュフロー/売上比率', - unit: '%' - }, - sga_ratio: { - name_jp: '販管費/売上率', - unit: '%' - }, - depreciation_gross_profit_ratio: { - name_jp: '減価償却費/粗利比率', - unit: '%' - }, - r_and_d_ratio: { - name_jp: '研究開発費/売上比率', - unit: '%' - }, - interest_op_income_ratio: { - name_jp: '支払利息/営業利益比率', - unit: '%' - }, - interest_coverage_ratio: { - name_jp: 'インタレストカバレッジレシオ ', - unit: '倍' - }, - net_sales_progress: { - name_jp: '売上進捗率', - unit: '%' - }, - operating_income_progress: { - name_jp: '営業利益進捗率', - unit: '%' - }, - net_income_progress: { - name_jp: '純利益進捗率', - unit: '%' - }, - net_sales_growth_rate_forecast: { - name_jp: '売上高成長率(直近年度実績→会社予想)', - unit: '%' - }, - operating_income_growth_rate_forecast: { - name_jp: '営業利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - net_income_growth_rate_forecast: { - name_jp: '純利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - cash_assets_ratio: { - name_jp: '現金総資産比率', - unit: '%' - }, - cash_monthly_sales_ratio: { - name_jp: '現金売上倍率', - unit: '倍' - }, - accounts_receivable_turnover: { - name_jp: '売上債権回転期間', - unit: '日' - }, - inventory_turnover: { - name_jp: '棚卸資産回転期間', - unit: '日' - }, - trade_payable_turnover: { - name_jp: '仕入債務回転期間', - unit: '日' - }, - working_capital: { - name_jp: '運転資本', - unit: '百万円' - }, - ccc: { - name_jp: 'CCC', - unit: '日' - }, - tangible_fixed_assets_turnover: { - name_jp: '有形固定資産回転率', - unit: '%' - }, - debt_assets_ratio: { - name_jp: '有利子負債/総資産比率', - unit: '%' - }, - debt_monthly_sales_ratio: { - name_jp: '有利子負債/月商比率', - unit: 'ヶ月' - }, - operating_cash_flow_debt_ratio: { - name_jp: '有利子負債/営業キャッシュフロー倍率', - unit: '倍' - }, - net_debt: { - name_jp: '純有利子負債', - unit: '百万円' - }, - adjusted_debt_ratio: { - name_jp: '自己株式調整済負債比率', - unit: '%' - }, - de_ratio: { - name_jp: 'DE比率', - unit: '%' - }, - current_ratio: { - name_jp: '流動比率', - unit: '%' - }, - net_debt_net_income_ratio: { - name_jp: 'ネットD純利益比率', - unit: '倍' - }, - equity: { - name_jp: '自己資本', - unit: '百万円' - }, - equity_ratio: { - name_jp: '自己資本比率', - unit: '%' - }, - accrual: { - name_jp: 'アクルーアル ', - unit: '百万円' - }, - employee_num: { - name_jp: '従業員数', - unit: '人' - }, - net_sales_per_employee: { - name_jp: '従業員一人あたり売上', - unit: '百万円' - }, - operating_income_per_employee: { - name_jp: '従業員一人あたり営業利益', - unit: '百万円' - }, - fiscal_year: { - name_jp: '会計年度', - unit: 'なし' - }, - fiscal_quarter: { - name_jp: '四半期', - unit: 'なし' - } -} diff --git a/src/__mocks__/fixtures/v2/quarter.js b/src/__mocks__/fixtures/v2/quarter.js deleted file mode 100644 index 3998cde..0000000 --- a/src/__mocks__/fixtures/v2/quarter.js +++ /dev/null @@ -1,189 +0,0 @@ -module.exports = { - '2371': [ - { - issued_share_num: null, - treasury_stock_num: 0.0, - ex_net_sales: 52000000000.0, - ex_operating_income: 25200000000.0, - ex_ordinary_income: null, - ex_net_income: 17090000000.0, - ex_dividend: 36.0, - dividend: null, - fiscal_year: 2018.0, - fiscal_quarter: 1.0, - company_name: '株式会社カカクコム', - ceo_name: '代表取締役社長  畑 彰之介', - headquarters_address: '東京都渋谷区恵比寿南三丁目5番7号', - accounting_standard: 'IFRS', - employee_num: null, - assets: 42143000000.0, - current_assets: 28774000000.0, - cash_and_deposits: 20517000000.0, - notes_accounts_receivable: 6857000000.0, - notes_receivable: null, - accounts_receivable: null, - inventories: null, - merchandise: null, - work_in_process: null, - raw_materials_and_supplies: null, - non_current_assets: 13369000000.0, - tangible_fixed_assets: null, - liabilities: 7737000000.0, - current_liabilities: 7132000000.0, - notes_accounts_payable: 1986000000.0, - accounts_payable: null, - notes_payable: null, - short_term_bonds_payable: null, - short_term_loans_payable: 223000000.0, - commercial_papers_liabilities: null, - current_lease_obligations: null, - current_portion_of_long_term_loans: null, - current_portion_of_bonds: null, - current_portion_of_convertible_bonds: null, - current_portion_of_bonds_with_subscription_rights: null, - non_current_liabilities: 605000000.0, - bonds_payable: null, - convertible_bonds: null, - convertible_bond_type_bonds_with_subscription_rights: null, - non_current_bonds_with_subscription_right: null, - long_term_loans_payable: 264000000.0, - non_current_lease_obligations: null, - net_assets: 34406000000.0, - shareholders_equity: 34049000000.0, - capital_stock: 916000000.0, - retained_earnings: 33238000000.0, - treasury_stock: -1115000000.0, - valuation_and_translation_adjustments: null, - non_controlling_interests: 357000000.0, - subscription_rights: 172000000.0, - net_sales: 12513000000.0, - cost_of_sales: 0.0, - gross_profit: 12512000000.0, - sga: 6952000000.0, - operating_income: 5560000000.0, - non_operating_income: 3000000.0, - non_operating_expenses: 31000000.0, - interest_expense: null, - ordinary_income: 5533000000.0, - extraordinary_income: null, - extraordinary_loss: null, - impairment_loss: null, - income_before_income_taxes: 5533000000.0, - income_taxes: 1997000000.0, - net_income: 3534000000.0, - operating_cash_flow: 3110000000.0, - investment_cash_flow: -525000000.0, - financial_cash_flow: -3098000000.0, - depreciation: 452000000.0, - amortization: null - } - ], - column_description: { - company_name: { name_jp: '社名', unit: 'なし' }, - ceo_name: { name_jp: '代表社名', unit: 'なし' }, - headquarters_address: { name_jp: '所在地', unit: 'なし' }, - accounting_standard: { name_jp: '会計基準', unit: 'なし' }, - issued_share_num: { name_jp: '発行済株式総数', unit: '株' }, - employee_num: { name_jp: '従業員数', unit: '人' }, - assets: { name_jp: '総資産', unit: '百万円' }, - current_assets: { name_jp: '流動資産', unit: '百万円' }, - cash_and_deposits: { name_jp: '現預金', unit: '百万円' }, - notes_accounts_receivable: { - name_jp: '受取手形及び売掛金', - unit: '百万円' - }, - notes_receivable: { name_jp: '受取手形', unit: '百万円' }, - accounts_receivable: { name_jp: '売掛金', unit: '百万円' }, - inventories: { name_jp: '在庫', unit: '百万円' }, - merchandise: { name_jp: '商品', unit: '百万円' }, - work_in_process: { name_jp: '仕掛品', unit: '百万円' }, - raw_materials_and_supplies: { name_jp: '原材料', unit: '百万円' }, - non_current_assets: { name_jp: '固定資産', unit: '百万円' }, - tangible_fixed_assets: { name_jp: '有形固定資産', unit: '百万円' }, - liabilities: { name_jp: '負債', unit: '百万円' }, - current_liabilities: { name_jp: '流動負債', unit: '百万円' }, - notes_accounts_payable: { name_jp: '支払手形及び買掛金', unit: '百万円' }, - accounts_payable: { name_jp: '買掛金', unit: '百万円' }, - notes_payable: { name_jp: '支払手形', unit: '百万円' }, - short_term_bonds_payable: { name_jp: '短期社債', unit: '百万円' }, - short_term_loans_payable: { name_jp: '短期借入金', unit: '百万円' }, - commercial_papers_liabilities: { - name_jp: 'コマーシャルペーパー', - unit: '百万円' - }, - current_lease_obligations: { - name_jp: 'リース債務(流動負債)', - unit: '百万円' - }, - current_portion_of_long_term_loans: { - name_jp: '1年以内返済の長期借入金', - unit: '百万円' - }, - current_portion_of_bonds: { name_jp: '1年以内返済の社債', unit: '百万円' }, - current_portion_of_convertible_bonds: { - name_jp: '1年以内返済の転換社債', - unit: '百万円' - }, - current_portion_of_bonds_with_subscription_rights: { - name_jp: '1年以内返済の新株予約権付社債', - unit: '百万円' - }, - non_current_liabilities: { name_jp: '固定負債', unit: '百万円' }, - bonds_payable: { name_jp: '社債', unit: '百万円' }, - convertible_bonds: { name_jp: '転換社債', unit: '百万円' }, - convertible_bond_type_bonds_with_subscription_rights: { - name_jp: '新株予約権付転換社債', - unit: '百万円' - }, - non_current_bonds_with_subscription_right: { - name_jp: '新株予約権付社債', - unit: '百万円' - }, - long_term_loans_payable: { name_jp: '長期借入金', unit: '百万円' }, - non_current_lease_obligations: { - name_jp: 'リース債務(固定負債)', - unit: '百万円' - }, - net_assets: { name_jp: '純資産', unit: '百万円' }, - shareholders_equity: { name_jp: '株主資本', unit: '百万円' }, - capital_stock: { name_jp: '資本金', unit: '百万円' }, - retained_earnings: { name_jp: '利益剰余金', unit: '百万円' }, - treasury_stock: { name_jp: '自己株式', unit: '百万円' }, - valuation_and_translation_adjustments: { - name_jp: '評価換算差額等', - unit: '百万円' - }, - non_controlling_interests: { name_jp: '非支配持分', unit: '百万円' }, - subscription_rights: { name_jp: '新株予約権', unit: '百万円' }, - net_sales_summary: { name_jp: '売上', unit: '百万円' }, - net_sales: { name_jp: '売上', unit: '百万円' }, - cost_of_sales: { name_jp: '売上原価', unit: '百万円' }, - gross_profit: { name_jp: '売上高総利益', unit: '百万円' }, - sga: { name_jp: '販売費および一般管理費', unit: '百万円' }, - operating_income: { name_jp: '営業利益', unit: '百万円' }, - non_operating_income: { name_jp: '営業外利益', unit: '百万円' }, - non_operating_expenses: { name_jp: '営業外損失', unit: '百万円' }, - interest_expense: { name_jp: '支払利息', unit: '百万円' }, - ordinary_income: { name_jp: '経常利益', unit: '百万円' }, - extraordinary_income: { name_jp: '特別利益', unit: '百万円' }, - extraordinary_loss: { name_jp: '特別損失', unit: '百万円' }, - impairment_loss: { name_jp: '減損損失', unit: '百万円' }, - income_before_income_taxes: { name_jp: '税引前当期純利益', unit: '百万円' }, - income_taxes: { name_jp: '法人税等', unit: '百万円' }, - net_income: { name_jp: '当期純利益', unit: '百万円' }, - operating_cash_flow: { name_jp: '営業キャッシュフロー', unit: '百万円' }, - investment_cash_flow: { name_jp: '投資キャッシュフロー', unit: '百万円' }, - financial_cash_flow: { name_jp: '財務キャッシュフロー', unit: '百万円' }, - depreciation: { name_jp: '減価償却費', unit: '百万円' }, - amortization: { name_jp: 'のれん償却費', unit: '百万円' }, - treasury_stock_num: { name_jp: '自己株数', unit: '株' }, - ex_net_sales: { name_jp: '売上(会予)', unit: '百万円' }, - ex_operating_income: { name_jp: '営業利益(会予)', unit: '百万円' }, - ex_ordinary_income: { name_jp: '経常利益(会予)', unit: '百万円' }, - ex_net_income: { name_jp: '当期純利益(会予)', unit: '百万円' }, - ex_dividend: { name_jp: '配当予想', unit: '円' }, - dividend: { name_jp: '配当金', unit: '円' }, - fiscal_year: { name_jp: '会計年度', unit: '年' }, - fiscal_quarter: { name_jp: '四半期', unit: 'なし' } - } -} diff --git a/src/__mocks__/services/company-cache.ts b/src/__mocks__/services/company-cache.ts index afb6097..ee4fb19 100644 --- a/src/__mocks__/services/company-cache.ts +++ b/src/__mocks__/services/company-cache.ts @@ -10,10 +10,6 @@ export class CompanyCache { CompanyCache.cache[ticker] = company } - static putAll(companies: object): void { - Object.keys(companies).forEach(ticker => CompanyCache.put(ticker, companies[ticker][0])) - } - // for testing static clearAll(): void { CompanyCache.cache = {} diff --git a/src/__mocks__/services/indicator-cache.ts b/src/__mocks__/services/indicator-cache.ts deleted file mode 100644 index 76c669d..0000000 --- a/src/__mocks__/services/indicator-cache.ts +++ /dev/null @@ -1,12 +0,0 @@ -export class IndicatorCache { - static readonly cache = {} - - static get(ticker: string): object[] | null { - const cached = IndicatorCache.cache[ticker] - return cached === undefined ? null : cached - } - - static put(ticker: string, indicator: object[]): void { - IndicatorCache.cache[ticker] = indicator - } -} diff --git a/src/__mocks__/services/indicator-property-cache.ts b/src/__mocks__/services/indicator-property-cache.ts deleted file mode 100644 index 3fdc5d6..0000000 --- a/src/__mocks__/services/indicator-property-cache.ts +++ /dev/null @@ -1,11 +0,0 @@ -export class IndicatorPropertyCache { - static cache = null - - static get(): object | null { - return this.cache - } - - static put(indicator: object): void { - this.cache = indicator - } -} diff --git a/src/__mocks__/services/quarter-property-cache.ts b/src/__mocks__/services/quarter-property-cache.ts deleted file mode 100644 index 8903516..0000000 --- a/src/__mocks__/services/quarter-property-cache.ts +++ /dev/null @@ -1,11 +0,0 @@ -export class QuarterPropertyCache { - static cache = null - - static get(): object | null { - return this.cache - } - - static put(quarter: object): void { - this.cache = quarter - } -} diff --git a/src/api/company-service.test.ts b/src/api/company-service.test.ts index 99f6478..161a449 100644 --- a/src/api/company-service.test.ts +++ b/src/api/company-service.test.ts @@ -1,5 +1,4 @@ import { CompanyService } from '~/api/company-service' -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' import { DateParam } from '~/fiscal-periods/date-param' import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' @@ -10,18 +9,11 @@ import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' const LY = new LyWithOffset() const LQ = new LqWithOffset() -jest.mock('~/api/v2/client', () => jest.requireActual('~/__mocks__/api/v2/client')) jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) -test('isSupportedTicker', () => { - const client = new CachingBuffettCodeApiClientV2('token') - expect(new CompanyService('2371', client).isSupportedTicker()).toBe(true) - expect(new CompanyService('9999', client).isSupportedTicker()).toBe(false) -}) - test('convertYearQuarterParamToYearQuarter', () => { - const client = new CachingBuffettCodeApiClientV2('token') + const client = new CachingBuffettCodeApiClientV3('token') const service = new CompanyService('2371', client) expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, 3))).toEqual(new YearQuarter(2021, 3)) expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(2016, LQ))).toEqual(new YearQuarter(2016, 2)) @@ -50,7 +42,7 @@ test('convertYearQuarterParamToYearQuarter', () => { }) test('isOndemandQuarterApiPeriod', () => { - const client = new CachingBuffettCodeApiClientV2('token') + const client = new CachingBuffettCodeApiClientV3('token') const service = new CompanyService('2371', client) expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2001, 4))).toBe(true) diff --git a/src/api/company-service.ts b/src/api/company-service.ts index f78dd55..76e3a9e 100644 --- a/src/api/company-service.ts +++ b/src/api/company-service.ts @@ -1,4 +1,3 @@ -import { BuffettCodeApiClientV2 } from '~/api/v2/client' import { BuffettCodeApiClientV3 } from '~/api/v3/client' import { DateParam } from '~/fiscal-periods/date-param' import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' @@ -9,18 +8,10 @@ import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' export class CompanyService { public company: object - constructor( - public ticker: string, - client: BuffettCodeApiClientV2 | BuffettCodeApiClientV3, - private today: Date = new Date() - ) { + constructor(public ticker: string, client: BuffettCodeApiClientV3, private today: Date = new Date()) { this.company = client.company(ticker) } - public isSupportedTicker(): boolean { - return !!this.company - } - public convertYearQuarterParamToYearQuarter(period: YearQuarterParam): YearQuarter { if (period.year instanceof LyWithOffset) { period.year = this.company['latest_fiscal_year'] + period.year.offset @@ -40,10 +31,6 @@ export class CompanyService { } public isOndemandQuarterApiPeriod(_period: YearQuarter | YearQuarterParam): boolean { - if (!this.isSupportedTicker()) { - throw new Error('unsupported ticker') - } - let period: YearQuarter if (_period instanceof YearQuarterParam) { period = this.convertYearQuarterParamToYearQuarter(_period) diff --git a/src/api/ondemand-api-period-range.test.ts b/src/api/ondemand-api-period-range.test.ts index ef1448c..bc71ec2 100644 --- a/src/api/ondemand-api-period-range.test.ts +++ b/src/api/ondemand-api-period-range.test.ts @@ -1,15 +1,15 @@ import { CompanyService } from '~/api/company-service' import { OndemandApiPeriodRange } from '~/api/ondemand-api-period-range' -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' +import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' import { YearQuarter } from '~/fiscal-periods/year-quarter' import { YearQuarterRange } from '~/fiscal-periods/year-quarter-range' -jest.mock('~/api/v2/client', () => jest.requireActual('~/__mocks__/api/v2/client')) +jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) test('selectOndemandQuarterApiPeriod', () => { const ticker = '2371' - const client = new CachingBuffettCodeApiClientV2('token') + const client = new CachingBuffettCodeApiClientV3('token') const companyService = new CompanyService(ticker, client) const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange(companyService) @@ -32,7 +32,7 @@ test('selectOndemandQuarterApiPeriod', () => { test('filterOndemandQuarterApiPeriod', () => { const ticker = '2371' - const client = new CachingBuffettCodeApiClientV2('token') + const client = new CachingBuffettCodeApiClientV3('token') const companyService = new CompanyService(ticker, client) const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange(companyService) diff --git a/src/api/v2/caching-client.test.ts b/src/api/v2/caching-client.test.ts deleted file mode 100644 index a10eb24..0000000 --- a/src/api/v2/caching-client.test.ts +++ /dev/null @@ -1,176 +0,0 @@ -import { CompanyCache } from '~/__mocks__/services/company-cache' -import { QuarterCache } from '~/__mocks__/services/quarter-cache' -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' -import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' -import { YearQuarter } from '~/fiscal-periods/year-quarter' -import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' -import { IndicatorCache } from '~/services/indicator-cache' - -jest.mock('~/api/v2/client', () => jest.requireActual('~/__mocks__/api/v2/client')) -jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) -jest.mock('~/services/indicator-cache', () => jest.requireActual('~/__mocks__/services/indicator-cache')) -jest.mock('~/services/quarter-cache', () => jest.requireActual('~/__mocks__/services/quarter-cache')) - -const LY = new LyWithOffset() -const LQ = new LqWithOffset() - -describe('company', () => { - const ticker = '2371' - - test('(uncached)', () => { - expect(CompanyCache.get(ticker)).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.company(ticker) - expect(res).not.toBeNull() - - expect(CompanyCache.get(ticker)).toEqual(res) - }) - - test('(cached)', () => { - const cached = CompanyCache.get(ticker) - expect(cached).not.toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.company(ticker) - expect(res).toEqual(cached) - - expect(CompanyCache.get(ticker)).toEqual(cached) - }) -}) - -describe('indicator', () => { - const ticker = '2371' - - test('(uncached)', () => { - expect(IndicatorCache.get(ticker)).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.indicator(ticker) - expect(res).not.toBeNull() - - expect(IndicatorCache.get(ticker)).toEqual(res) - }) - - test('(cached)', () => { - const cached = IndicatorCache.get(ticker) - expect(cached).not.toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.indicator(ticker) - expect(res).toEqual(cached) - - expect(IndicatorCache.get(ticker)).toEqual(cached) - }) -}) - -describe('quarter', () => { - const ticker = '2371' - - describe('(FY, FQ)', () => { - beforeAll(() => { - QuarterCache.clearAll() - }) - - const period = new YearQuarterParam(2018, 1) - - test('(uncached)', () => { - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.quarter(ticker, period) - expect(res).not.toBeNull() - expect(res['fiscal_year']).toBe(period.year) - expect(res['fiscal_quarter']).toBe(period.quarter) - - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual(res) - }) - - test('(cached)', () => { - const cached = QuarterCache.getData(ticker, period.toYearQuarter()) - expect(cached).not.toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.quarter(ticker, period) - expect(res).toEqual(cached) - expect(res['fiscal_year']).toBe(period.year) - expect(res['fiscal_quarter']).toBe(period.quarter) - - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual(cached) - }) - }) - - describe('(LY, LQ)', () => { - beforeAll(() => { - QuarterCache.clearAll() - }) - - const period = new YearQuarterParam(LY, LQ) - - test('(uncached)', () => { - expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.quarter(ticker, period) - expect(res).not.toBeNull() - expect(res['fiscal_year']).toBe(2018) - expect(res['fiscal_quarter']).toBe(1) - - expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toEqual(res) - }) - }) -}) - -describe('ondemandQuarter', () => { - const ticker = '2371' - - describe('(FY, FQ)', () => { - beforeAll(() => { - QuarterCache.clearAll() - }) - - const period = new YearQuarterParam(2018, 1) - - test('(uncached)', () => { - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.ondemandQuarter(ticker, period) - expect(res).not.toBeNull() - - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual(res) - }) - - test('(cached)', () => { - const cached = QuarterCache.getData(ticker, period.toYearQuarter()) - expect(cached).not.toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.ondemandQuarter(ticker, period) - expect(res).toEqual(cached) - - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual(cached) - }) - }) - - describe('(LY, LQ)', () => { - beforeAll(() => { - QuarterCache.clearAll() - }) - - const period = new YearQuarterParam(LY, LQ) - - test('(uncached)', () => { - expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const res = client.ondemandQuarter(ticker, period) - expect(res).not.toBeNull() - expect(res['fiscal_year']).toBe(2018) - expect(res['fiscal_quarter']).toBe(1) - - expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toEqual(res) - }) - }) -}) diff --git a/src/api/v2/caching-client.ts b/src/api/v2/caching-client.ts deleted file mode 100644 index b566ddb..0000000 --- a/src/api/v2/caching-client.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { BuffettCodeApiClientV2 } from '~/api/v2/client' -import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' -import { CompanyCache } from '~/services/company-cache' -import { IndicatorCache } from '~/services/indicator-cache' -import { QuarterCache } from '~/services/quarter-cache' - -export class CachingBuffettCodeApiClientV2 extends BuffettCodeApiClientV2 { - constructor(token: string) { - super(token) - } - - company(ticker: string): object { - const cached = CompanyCache.get(ticker) - if (cached) { - return cached - } - - const company = super.company(ticker) - CompanyCache.put(ticker, company) - - return company - } - - indicator(ticker: string): object | null { - const cached = IndicatorCache.get(ticker) - if (cached) { - return cached - } - - const indicator = super.indicator(ticker) - if (!indicator) { - return null - } - - IndicatorCache.put(ticker, indicator) - - return indicator - } - - quarter(ticker: string, period: YearQuarterParam): object | null { - if (period.convertibleToYearQuarter()) { - const cached = QuarterCache.getData(ticker, period.toYearQuarter()) - if (cached) { - return cached - } - } - - const quarter = super.quarter(ticker, period) - if (!quarter) { - return null - } - - QuarterCache.putData(ticker, quarter) - - return quarter - } - - ondemandQuarter(ticker: string, period: YearQuarterParam): object | null { - if (period.convertibleToYearQuarter()) { - const cached = QuarterCache.getData(ticker, period.toYearQuarter()) - if (cached) { - return cached - } - } - - const quarter = super.ondemandQuarter(ticker, period) - if (!quarter) { - return null - } - - QuarterCache.putData(ticker, quarter) - - return quarter - } -} diff --git a/src/api/v2/caching-indicator-property.test.ts b/src/api/v2/caching-indicator-property.test.ts deleted file mode 100644 index 6c2764c..0000000 --- a/src/api/v2/caching-indicator-property.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' -import { IndicatorPropertyCache } from '~/services/indicator-property-cache' - -jest.mock('~/api/v2/indicator-property', () => jest.requireActual('~/__mocks__/api/v2/indicator-property')) - -jest.mock('~/services/indicator-property-cache', () => - jest.requireActual('~/__mocks__/services/indicator-property-cache') -) - -describe('fetch', () => { - test('(uncached)', () => { - expect(IndicatorPropertyCache.get()).toBeNull() - - const fetched = CachingIndicatorProperty.fetch() - expect(fetched).not.toBeNull() - - expect(IndicatorPropertyCache.get()).toEqual(fetched) - }) - - test('(cached)', () => { - const cached = IndicatorPropertyCache.get() - expect(cached).not.toBeNull() - - expect(CachingIndicatorProperty.fetch()).toEqual(cached) - - expect(IndicatorPropertyCache.get()).toEqual(cached) - }) -}) diff --git a/src/api/v2/caching-indicator-property.ts b/src/api/v2/caching-indicator-property.ts deleted file mode 100644 index 4a589ed..0000000 --- a/src/api/v2/caching-indicator-property.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { IndicatorProperty } from '~/api/v2/indicator-property' -import { IndicatorPropertyCache } from '~/services/indicator-property-cache' - -export class CachingIndicatorProperty extends IndicatorProperty { - static fetch(): object { - const cached = IndicatorPropertyCache.get() - if (cached) { - return cached - } else { - const res = super.fetch() - IndicatorPropertyCache.put(res) - return res - } - } -} diff --git a/src/api/v2/caching-quarter-property.test.ts b/src/api/v2/caching-quarter-property.test.ts deleted file mode 100644 index 6f4eb7d..0000000 --- a/src/api/v2/caching-quarter-property.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CachingQuarterProperty } from '~/api/v2/caching-quarter-property' -import { QuarterPropertyCache } from '~/services/quarter-property-cache' - -jest.mock('~/api/v2/quarter-property', () => jest.requireActual('~/__mocks__/api/v2/quarter-property')) - -jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) - -describe('fetch', () => { - test('(uncached)', () => { - expect(QuarterPropertyCache.get()).toBeNull() - - const fetched = CachingQuarterProperty.fetch() - expect(fetched).not.toBeNull() - - expect(QuarterPropertyCache.get()).toEqual(fetched) - }) - - test('(cached)', () => { - const cached = QuarterPropertyCache.get() - expect(cached).not.toBeNull() - - expect(CachingQuarterProperty.fetch()).toEqual(cached) - - expect(QuarterPropertyCache.get()).toEqual(cached) - }) -}) diff --git a/src/api/v2/caching-quarter-property.ts b/src/api/v2/caching-quarter-property.ts deleted file mode 100644 index 21e071e..0000000 --- a/src/api/v2/caching-quarter-property.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { QuarterProperty } from '~/api/v2/quarter-property' -import { QuarterPropertyCache } from '~/services/quarter-property-cache' - -export class CachingQuarterProperty extends QuarterProperty { - static fetch(): object { - const cached = QuarterPropertyCache.get() - if (cached) { - return cached - } else { - const res = super.fetch() - QuarterPropertyCache.put(res) - return res - } - } -} diff --git a/src/api/v2/client.test.ts b/src/api/v2/client.test.ts deleted file mode 100644 index c1007cc..0000000 --- a/src/api/v2/client.test.ts +++ /dev/null @@ -1,130 +0,0 @@ -import * as company from '~/__mocks__/fixtures/v2/company' -import * as indicator from '~/__mocks__/fixtures/v2/indicator' -import * as quarter from '~/__mocks__/fixtures/v2/quarter' -import { HttpError } from '~/api/http-error' -import { useMockedUrlFetchApp } from '~/api/test-helper' -import { BuffettCodeApiClientV2 } from '~/api/v2/client' -import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' - -test('HttpError#isInvalidTestingRequest', () => { - const res1 = useMockedUrlFetchApp( - 200, - '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}' - )() - const error1 = new HttpError('https://example.com', res1) - expect(error1.isInvalidTestingRequest()).toBeTruthy() - - const res2 = useMockedUrlFetchApp(403, '{"message": "Forbidden"}')() - const error2 = new HttpError('https://example.com', res2) - expect(error2.isInvalidTestingRequest()).toBeFalsy() -}) - -test('request', () => { - const mockFetch = useMockedUrlFetchApp(200, '{"message": "this is a message"}') - - expect( - BuffettCodeApiClientV2['request']('http://example.com', { - headers: { 'x-api-key': 'foo' } - }) - ).toEqual({ - message: 'this is a message' - }) - expect(mockFetch.mock.calls.length).toBe(1) - expect(mockFetch.mock.calls[0].length).toBe(2) - expect(mockFetch.mock.calls[0][0]).toBe('http://example.com') - expect(mockFetch.mock.calls[0][1]).toEqual({ - headers: { 'x-api-key': 'foo' }, - muteHttpExceptions: true - }) -}) - -test('request when testing apikey error', () => { - useMockedUrlFetchApp(200, '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}') - - const request = BuffettCodeApiClientV2['request'] - expect(() => request('http://example.com')).toThrow(HttpError) -}) - -test('request when 403 error', () => { - useMockedUrlFetchApp(403, '{"message": "Forbidden"}') - - const request = BuffettCodeApiClientV2['request'] - expect(() => request('http://example.com')).toThrow(HttpError) -}) - -test('request when 503 error', () => { - useMockedUrlFetchApp(503, '{"message": "Service Unavailable"}') - - const request = BuffettCodeApiClientV2['request'] - expect(() => request('http://example.com')).toThrow(HttpError) - try { - request('http://example.com') - } catch (e) { - expect(e.response.getResponseCode()).toBe(503) - expect(e.response.getContentText()).toBe('{"message": "Service Unavailable"}') - } -}) - -test('company', () => { - const mockFetch = useMockedUrlFetchApp(200, JSON.stringify(company)) - - const client = new BuffettCodeApiClientV2('foo') - const ticker = '2371' - expect(client.company(ticker)).toEqual(company[ticker][0]) - expect(mockFetch.mock.calls.length).toBe(1) - expect(mockFetch.mock.calls[0].length).toBe(2) - expect(mockFetch.mock.calls[0][0]).toBe(`https://api.buffett-code.com/api/v2/company?ticker=${ticker}`) - expect(mockFetch.mock.calls[0][1]).toEqual({ - headers: { 'x-api-key': 'foo' }, - muteHttpExceptions: true - }) -}) - -test('quarter', () => { - const mockFetch = useMockedUrlFetchApp(200, JSON.stringify(quarter)) - - const client = new BuffettCodeApiClientV2('foo') - const ticker = '2371' - const period = new YearQuarterParam(2018, 1) - expect(client.quarter(ticker, period)).toEqual(quarter[ticker][0]) - expect(mockFetch.mock.calls.length).toBe(1) - expect(mockFetch.mock.calls[0].length).toBe(2) - expect(mockFetch.mock.calls[0][0]).toBe('https://api.buffett-code.com/api/v2/quarter?ticker=2371&fy=2018&fq=1') - expect(mockFetch.mock.calls[0][1]).toEqual({ - headers: { 'x-api-key': 'foo' }, - muteHttpExceptions: true - }) -}) - -test('indicator', () => { - const mockFetch = useMockedUrlFetchApp(200, JSON.stringify(indicator)) - - const client = new BuffettCodeApiClientV2('foo') - const ticker = '2371' - expect(client.indicator(ticker)).toEqual(indicator[ticker][0]) - expect(mockFetch.mock.calls.length).toBe(1) - expect(mockFetch.mock.calls[0].length).toBe(2) - expect(mockFetch.mock.calls[0][0]).toBe('https://api.buffett-code.com/api/v2/indicator?tickers=2371') - expect(mockFetch.mock.calls[0][1]).toEqual({ - headers: { 'x-api-key': 'foo' }, - muteHttpExceptions: true - }) -}) - -test('ondemandQuarter', () => { - const mockFetch = useMockedUrlFetchApp(200, JSON.stringify(quarter)) - - const client = new BuffettCodeApiClientV2('foo') - const ticker = '2371' - const period = new YearQuarterParam(2018, 1) - expect(client.ondemandQuarter(ticker, period)).toEqual(quarter[ticker][0]) - expect(mockFetch.mock.calls.length).toBe(1) - expect(mockFetch.mock.calls[0].length).toBe(2) - expect(mockFetch.mock.calls[0][0]).toBe( - 'https://api.buffett-code.com/api/v2/ondemand/quarter?ticker=2371&fy=2018&fq=1' - ) - expect(mockFetch.mock.calls[0][1]).toEqual({ - headers: { 'x-api-key': 'foo' }, - muteHttpExceptions: true - }) -}) diff --git a/src/api/v2/client.ts b/src/api/v2/client.ts deleted file mode 100644 index f76fa4e..0000000 --- a/src/api/v2/client.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { HttpError } from '~/api/http-error' -import { UrlBuilder } from '~/api/url-builder' -import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' - -export class BuffettCodeApiClientV2 { - static readonly baseUrl = 'https://api.buffett-code.com/api/v2' - - constructor(private _token: string) {} - - private static request(url: string, options = {}): object { - const defaultOptions = { - muteHttpExceptions: true - } - const fullOptions = { ...defaultOptions, ...options } - const res = UrlFetchApp.fetch(url, fullOptions) - - const code = res.getResponseCode() - const content = res.getContentText() - const error = new HttpError(url, res) - if (Math.floor(code / 100) === 4 || Math.floor(code / 100) === 5 || error.isInvalidTestingRequest()) { - throw error - } - - let json - try { - json = JSON.parse(content) - } catch (e) { - console.error('JSON parsing error', url, code, content) - throw new HttpError(url, res) - } - - return json - } - - private defaultOptions(): object { - return { - headers: { - 'x-api-key': this._token - } - } - } - - public company(ticker: string): object | null { - const endpoint = BuffettCodeApiClientV2.baseUrl + '/company' - const builder = new UrlBuilder(endpoint, { ticker: ticker }) - const url = builder.toString() - const options = this.defaultOptions() - - const res = BuffettCodeApiClientV2.request(url, options) - if (!res[ticker] || !res[ticker].length) { - return null - } - - return res[ticker][0] - } - - public quarter(ticker: string, period: YearQuarterParam): object | null { - const endpoint = BuffettCodeApiClientV2.baseUrl + '/quarter' - const builder = new UrlBuilder(endpoint, { - ticker, - fy: period.year, - fq: period.quarter - }) - const url = builder.toString() - const options = this.defaultOptions() - - const res = BuffettCodeApiClientV2.request(url, options) - if (!res[ticker] || !res[ticker].length) { - return null - } - - return res[ticker][0] - } - - // NOTE: 本来はticker単体ではなくtickersを扱うべき - public indicator(ticker: string): object | null { - const endpoint = BuffettCodeApiClientV2.baseUrl + '/indicator' - const builder = new UrlBuilder(endpoint, { tickers: ticker }) - const url = builder.toString() - const options = this.defaultOptions() - - const res = BuffettCodeApiClientV2.request(url, options) - if (!res[ticker] || !res[ticker].length) { - return null - } - - return res[ticker][0] // NOTE: indicatorは常に1つ - } - - public ondemandQuarter(ticker: string, period: YearQuarterParam): object | null { - const endpoint = BuffettCodeApiClientV2.baseUrl + '/ondemand/quarter' - const builder = new UrlBuilder(endpoint, { - ticker, - fy: period.year, - fq: period.quarter - }) - const url = builder.toString() - const options = this.defaultOptions() - - const res = BuffettCodeApiClientV2.request(url, options) - if (!res[ticker] || !res[ticker].length) { - return null - } - - return res[ticker][0] // NOTE: ondemend/quarterは常に1レコード - } -} diff --git a/src/api/v2/indicator-property.test.ts b/src/api/v2/indicator-property.test.ts deleted file mode 100644 index b653783..0000000 --- a/src/api/v2/indicator-property.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { default as indicator } from '~/__mocks__/fixtures/v2/indicator-property' -import { useMockedUrlFetchApp } from '~/api/test-helper' -import { IndicatorProperty } from '~/api/v2/indicator-property' - -test('isIndicatorProperty', () => { - useMockedUrlFetchApp(200, JSON.stringify(indicator)) - - expect(IndicatorProperty.isIndicatorProperty('company_name')).toBeFalsy() - expect(IndicatorProperty.isIndicatorProperty('edinet_title')).toBeFalsy() - - expect(IndicatorProperty.isIndicatorProperty('stockprice')).toBeTruthy() - expect(IndicatorProperty.isIndicatorProperty('day')).toBeTruthy() -}) - -test('unitOf', () => { - useMockedUrlFetchApp(200, JSON.stringify(indicator)) - - expect(IndicatorProperty.unitOf('company_name')).toBeNull() - expect(IndicatorProperty.unitOf('edinet_title')).toBeNull() - - expect(IndicatorProperty.unitOf('stockprice')).toBe('円') - expect(IndicatorProperty.unitOf('day')).toBe('なし') -}) - -test('labelOf', () => { - useMockedUrlFetchApp(200, JSON.stringify(indicator)) - - expect(IndicatorProperty.labelOf('company_name')).toBeNull() - expect(IndicatorProperty.labelOf('edinet_title')).toBeNull() - - expect(IndicatorProperty.labelOf('stockprice')).toBe('株価') - expect(IndicatorProperty.labelOf('day')).toBe('日時') -}) diff --git a/src/api/v2/indicator-property.ts b/src/api/v2/indicator-property.ts deleted file mode 100644 index 0656449..0000000 --- a/src/api/v2/indicator-property.ts +++ /dev/null @@ -1,41 +0,0 @@ -export class IndicatorProperty { - static readonly url = 'https://docs.buffett-code.com/v2-indicator.json' - - protected constructor() { - // - } - - protected static fetch(): object { - const res = UrlFetchApp.fetch(this.url) - return JSON.parse(res.getContentText()) - } - - static names(): string[] { - const properties = this.fetch() - return Object.keys(properties) - } - - static isIndicatorProperty(name: string): boolean { - return this.names().indexOf(name) >= 0 - } - - static unitOf(name: string): string | null { - const properties = this.fetch() - const property = properties[name] - if (!property) { - return null - } - - return property.unit - } - - static labelOf(name: string): string | null { - const properties = this.fetch() - const property = properties[name] - if (!property) { - return null - } - - return property.name_jp - } -} diff --git a/src/api/v2/quarter-property.test.ts b/src/api/v2/quarter-property.test.ts deleted file mode 100644 index 48e834f..0000000 --- a/src/api/v2/quarter-property.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { default as quarter } from '~/__mocks__/fixtures/v2/quarter-property' -import { useMockedUrlFetchApp } from '~/api/test-helper' -import { QuarterProperty } from '~/api/v2/quarter-property' - -test('isQuarterProperty', () => { - useMockedUrlFetchApp(200, JSON.stringify(quarter)) - - expect(QuarterProperty.isQuarterProperty('company_name')).toBeTruthy() - expect(QuarterProperty.isQuarterProperty('edinet_title')).toBeTruthy() - - expect(QuarterProperty.isQuarterProperty('stockprice')).toBeFalsy() - expect(QuarterProperty.isQuarterProperty('day')).toBeFalsy() -}) - -test('unitOf', () => { - useMockedUrlFetchApp(200, JSON.stringify(quarter)) - - expect(QuarterProperty.unitOf('company_name')).toBe('なし') - expect(QuarterProperty.unitOf('edinet_title')).toBe('なし') - - expect(QuarterProperty.unitOf('stockprice')).toBeNull() - expect(QuarterProperty.unitOf('day')).toBeNull() -}) - -test('labelOf', () => { - useMockedUrlFetchApp(200, JSON.stringify(quarter)) - - expect(QuarterProperty.labelOf('company_name')).toBe('社名') - expect(QuarterProperty.labelOf('edinet_title')).toBe('edinet開示資料名') - - expect(QuarterProperty.labelOf('stockprice')).toBeNull() - expect(QuarterProperty.labelOf('day')).toBeNull() -}) diff --git a/src/api/v2/quarter-property.ts b/src/api/v2/quarter-property.ts deleted file mode 100644 index 9990ba7..0000000 --- a/src/api/v2/quarter-property.ts +++ /dev/null @@ -1,41 +0,0 @@ -export class QuarterProperty { - static readonly url = 'https://docs.buffett-code.com/v2-quarter.json' - - protected constructor() { - // - } - - protected static fetch(): object { - const res = UrlFetchApp.fetch(this.url) - return JSON.parse(res.getContentText()) - } - - static names(): string[] { - const properties = this.fetch() - return Object.keys(properties) - } - - static isQuarterProperty(name: string): boolean { - return this.names().indexOf(name) >= 0 - } - - static unitOf(name: string): string | null { - const properties = this.fetch() - const property = properties[name] - if (!property) { - return null - } - - return property.unit - } - - static labelOf(name: string): string | null { - const properties = this.fetch() - const property = properties[name] - if (!property) { - return null - } - - return property.name_jp - } -} diff --git a/src/custom-functions/bcode-label.test.ts b/src/custom-functions/bcode-label.test.ts deleted file mode 100644 index 2196bbd..0000000 --- a/src/custom-functions/bcode-label.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { bcodeLabel } from '~/custom-functions/bcode-label' -import { IndicatorPropertyCache } from '~/services/indicator-property-cache' -import { QuarterPropertyCache } from '~/services/quarter-property-cache' - -jest.mock('~/api/v2/indicator-property', () => jest.requireActual('~/__mocks__/api/v2/indicator-property')) -jest.mock('~/api/v2/quarter-property', () => jest.requireActual('~/__mocks__/api/v2/quarter-property')) -jest.mock('~/services/indicator-property-cache', () => - jest.requireActual('~/__mocks__/services/indicator-property-cache') -) -jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) - -test('bcodeLabel', () => { - expect(IndicatorPropertyCache.get()).toBeNull() - expect(QuarterPropertyCache.get()).toBeNull() - - expect(bcodeLabel('net_sales')).toBe('売上') - expect(bcodeLabel('stockprice')).toBe('株価') - expect(() => bcodeLabel('foo')).toThrow(Error) - expect(() => bcodeLabel('')).toThrow(Error) - - expect(IndicatorPropertyCache.get()).not.toBeNull() - expect(QuarterPropertyCache.get()).not.toBeNull() -}) diff --git a/src/custom-functions/bcode-label.ts b/src/custom-functions/bcode-label.ts deleted file mode 100644 index 8d93bca..0000000 --- a/src/custom-functions/bcode-label.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' -import { CachingQuarterProperty } from '~/api/v2/caching-quarter-property' - -export function bcodeLabel(propertyName: string): string { - if (!propertyName) { - throw new Error('<>') - } - - const isQuarterProperty = CachingQuarterProperty.isQuarterProperty(propertyName) - const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty(propertyName) - - if (!isQuarterProperty && !isIndicatorProperty) { - throw new Error(`<<指定された項目が見つかりません: ${propertyName}>>`) - } - - // NOTE: プロパティがquarterとindicatornの両方に存在する可能性もあるが、 - // どちらを見ても同じはずなので決め打ちでquarterを優先に見ている - if (isQuarterProperty) { - return CachingQuarterProperty.labelOf(propertyName) - } else { - return CachingIndicatorProperty.labelOf(propertyName) - } -} diff --git a/src/custom-functions/bcode-unit.test.ts b/src/custom-functions/bcode-unit.test.ts deleted file mode 100644 index 06767c4..0000000 --- a/src/custom-functions/bcode-unit.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { bcodeUnit } from '~/custom-functions/bcode-unit' -import { IndicatorPropertyCache } from '~/services/indicator-property-cache' -import { QuarterPropertyCache } from '~/services/quarter-property-cache' - -jest.mock('~/api/v2/indicator-property', () => jest.requireActual('~/__mocks__/api/v2/indicator-property')) -jest.mock('~/api/v2/quarter-property', () => jest.requireActual('~/__mocks__/api/v2/quarter-property')) -jest.mock('~/services/indicator-property-cache', () => - jest.requireActual('~/__mocks__/services/indicator-property-cache') -) -jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) - -test('bcodeUnit', () => { - expect(IndicatorPropertyCache.get()).toBeNull() - expect(QuarterPropertyCache.get()).toBeNull() - - expect(bcodeUnit('net_sales')).toBe('百万円') - expect(bcodeUnit('stockprice')).toBe('円') - expect(() => bcodeUnit('foo')).toThrow(Error) - expect(() => bcodeUnit('')).toThrow(Error) - - expect(IndicatorPropertyCache.get()).not.toBeNull() - expect(QuarterPropertyCache.get()).not.toBeNull() -}) diff --git a/src/custom-functions/bcode-unit.ts b/src/custom-functions/bcode-unit.ts deleted file mode 100644 index 8a1b94e..0000000 --- a/src/custom-functions/bcode-unit.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' -import { CachingQuarterProperty } from '~/api/v2/caching-quarter-property' - -export function bcodeUnit(propertyName: string): string { - if (!propertyName) { - throw new Error('<>') - } - - const isQuarterProperty = CachingQuarterProperty.isQuarterProperty(propertyName) - const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty(propertyName) - - if (!isQuarterProperty && !isIndicatorProperty) { - throw new Error(`<<指定された項目が見つかりません: ${propertyName}>>`) - } - - // NOTE: プロパティがquarterとindicatornの両方に存在する可能性もあるが、 - // どちらを見ても同じはずなので決め打ちでquarterを優先に見ている - if (isQuarterProperty) { - return CachingQuarterProperty.unitOf(propertyName) - } else { - return CachingIndicatorProperty.unitOf(propertyName) - } -} diff --git a/src/custom-functions/bcode.test.ts b/src/custom-functions/bcode.test.ts deleted file mode 100644 index ef0820c..0000000 --- a/src/custom-functions/bcode.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { castStringAsBoolean, isV3Call } from '~/custom-functions/bcode' - -test('castStringAsBoolean', () => { - expect(castStringAsBoolean(true)).toBeTruthy() - expect(castStringAsBoolean('true')).toBeTruthy() - expect(castStringAsBoolean('TRUE')).toBeTruthy() - expect(castStringAsBoolean('True')).toBeTruthy() - expect(castStringAsBoolean(false)).toBeFalsy() - expect(castStringAsBoolean('false')).toBeFalsy() - expect(castStringAsBoolean('FALSE')).toBeFalsy() - expect(castStringAsBoolean('False')).toBeFalsy() - expect(castStringAsBoolean('t')).toBeFalsy() - expect(castStringAsBoolean('f')).toBeFalsy() - expect(castStringAsBoolean('')).toBeFalsy() -}) - -test('isV3Call', () => { - expect(isV3Call(2020, 1)).toBeFalsy() - expect(isV3Call(2020, '1')).toBeFalsy() - expect(isV3Call('2020', 1)).toBeFalsy() - expect(isV3Call('2020', '1')).toBeFalsy() - expect(isV3Call('LY', '4')).toBeFalsy() - expect(isV3Call('ly', '4')).toBeFalsy() - expect(isV3Call('2020', 'LQ')).toBeFalsy() - expect(isV3Call('2020', 'lq')).toBeFalsy() - expect(isV3Call('LY', 'LQ')).toBeFalsy() - expect(isV3Call('LY-1', 'LQ-1')).toBeFalsy() - expect(isV3Call('', '')).toBeFalsy() - expect(isV3Call('2020Q1', 'net_sales')).toBeTruthy() - expect(isV3Call('LYLQ', 'net_sales')).toBeTruthy() - expect(isV3Call('2020-09-06', 'market_capital')).toBeTruthy() - expect(isV3Call('latest', 'market_capital')).toBeTruthy() -}) diff --git a/src/custom-functions/bcode.ts b/src/custom-functions/bcode.ts index 563a976..82946da 100644 --- a/src/custom-functions/bcode.ts +++ b/src/custom-functions/bcode.ts @@ -1,4 +1,3 @@ -import { bcode as bcodeV2 } from '~/custom-functions/v2/bcode' import { bcode as bcodeV3 } from '~/custom-functions/v3/bcode' import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' @@ -28,8 +27,7 @@ export function bcode( param1: string | number | Date, param2: string | number, param3: string | boolean = false, - param4: string | boolean = false, - param5: string | boolean = false + param4: string | boolean = false ): number | string { if (param1 instanceof Date || isV3Call(param1, param2)) { if (typeof param1 === 'number') { @@ -41,7 +39,9 @@ export function bcode( } return bcodeV3(ticker, param1, param2, castStringAsBoolean(param3), castStringAsBoolean(param4)) - } else { - return bcodeV2(ticker, param1, param2, param3.toString(), castStringAsBoolean(param4), castStringAsBoolean(param5)) } + + const message = + 'BCODE(ticker, FY, FQ, name)の形式は現在サポートしていません。BCODE(ticker, FYFQ, name)をご利用ください。' + throw new Error(message) } diff --git a/src/custom-functions/v2/bcode-indicator.test.ts b/src/custom-functions/v2/bcode-indicator.test.ts deleted file mode 100644 index dc214fc..0000000 --- a/src/custom-functions/v2/bcode-indicator.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { bcodeIndicator } from '~/custom-functions/v2/bcode-indicator' -import { BcodeResult } from '~/custom-functions/v2/bcode-result' -import { IndicatorCache } from '~/services/indicator-cache' -import { IndicatorPropertyCache } from '~/services/indicator-property-cache' - -jest.mock('~/api/v2/client', () => jest.requireActual('~/__mocks__/api/v2/client')) -jest.mock('~/api/v2/indicator-property', () => jest.requireActual('~/__mocks__/api/v2/indicator-property')) -jest.mock('~/services/indicator-cache', () => jest.requireActual('~/__mocks__/services/indicator-cache')) -jest.mock('~/services/indicator-property-cache', () => - jest.requireActual('~/__mocks__/services/indicator-property-cache') -) - -test('bcodeIndicator (uncached)', () => { - const ticker = '2371' - expect(IndicatorCache.get(ticker)).toBeNull() - expect(IndicatorPropertyCache.get()).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const result = bcodeIndicator(client, ticker, 'roa') - - expect(result).toEqual(new BcodeResult(35.53659143898409, '%')) - expect(IndicatorCache.get(ticker)['roa']).toBe(35.53659143898409) - expect(IndicatorPropertyCache.get()).not.toBeNull() -}) - -test('bcodeIndicator (cached)', () => { - const ticker = '2371' - expect(IndicatorCache.get(ticker)['roa']).not.toBeNull() - expect(IndicatorPropertyCache.get()).not.toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const result = bcodeIndicator(client, ticker, 'roa') - - expect(result).toEqual(new BcodeResult(35.53659143898409, '%')) - expect(IndicatorCache.get(ticker)['roa']).toBe(35.53659143898409) - expect(IndicatorPropertyCache.get()).not.toBeNull() -}) diff --git a/src/custom-functions/v2/bcode-indicator.ts b/src/custom-functions/v2/bcode-indicator.ts deleted file mode 100644 index 7d4bc53..0000000 --- a/src/custom-functions/v2/bcode-indicator.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' -import { ApiResponseError } from '~/custom-functions/error' -import { BcodeResult } from '~/custom-functions/v2/bcode-result' - -export function bcodeIndicator( - client: CachingBuffettCodeApiClientV2, - ticker: string, - propertyName: string -): BcodeResult { - const indicator = client.indicator(ticker) - if (!indicator) { - throw new ApiResponseError() - } - - const value = indicator[propertyName] - const unit = CachingIndicatorProperty.unitOf(propertyName) - return new BcodeResult(value, unit) -} diff --git a/src/custom-functions/v2/bcode-quarter.test.ts b/src/custom-functions/v2/bcode-quarter.test.ts deleted file mode 100644 index 91f03c8..0000000 --- a/src/custom-functions/v2/bcode-quarter.test.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { QuarterCache } from '~/__mocks__/services/quarter-cache' -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { bcodeQuarter } from '~/custom-functions/v2/bcode-quarter' -import { BcodeResult } from '~/custom-functions/v2/bcode-result' -import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' -import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' -import { YearQuarter } from '~/fiscal-periods/year-quarter' -import { QuarterPropertyCache } from '~/services/quarter-property-cache' - -jest.mock('~/api/v2/client', () => jest.requireActual('~/__mocks__/api/v2/client')) -jest.mock('~/api/v2/quarter-property', () => jest.requireActual('~/__mocks__/api/v2/quarter-property')) -jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) -jest.mock('~/services/quarter-cache', () => jest.requireActual('~/__mocks__/services/quarter-cache')) -jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) - -// TODO: ondemand apiのテスト -describe('bcodeQuarter', () => { - beforeEach(() => { - QuarterCache.clearAll() - QuarterPropertyCache.put(null) - }) - - test('(quarter, FY, FQ)', () => { - const ticker = '2371' - const yearQuarter = new YearQuarter(2018, 1) - expect(QuarterCache.getData(ticker, yearQuarter)).toBeNull() - expect(QuarterPropertyCache.get()).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const result = bcodeQuarter(client, ticker, 2018, 1, 'net_sales', false) - - expect(result).toEqual(new BcodeResult(12513000000.0, '百万円')) - expect(QuarterCache.getData(ticker, yearQuarter)['net_sales']).toBe(12513000000.0) - expect(QuarterPropertyCache.get()).not.toBeNull() - }) - - test('(quarter, LY, LQ)', () => { - const LY = new LyWithOffset() - const LQ = new LqWithOffset() - const ticker = '2371' - const period = new YearQuarter(2018, 1) - expect(QuarterCache.getData(ticker, period)).toBeNull() - expect(QuarterPropertyCache.get()).toBeNull() - - const client = new CachingBuffettCodeApiClientV2('token') - const result = bcodeQuarter(client, ticker, LY, LQ, 'net_sales', false) - - expect(result).toEqual(new BcodeResult(12513000000.0, '百万円')) - expect(QuarterCache.getData(ticker, period)['net_sales']).toBe(12513000000.0) - expect(QuarterPropertyCache.get()).not.toBeNull() - }) -}) diff --git a/src/custom-functions/v2/bcode-quarter.ts b/src/custom-functions/v2/bcode-quarter.ts deleted file mode 100644 index 4544c3f..0000000 --- a/src/custom-functions/v2/bcode-quarter.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { CompanyService } from '~/api/company-service' -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { CachingQuarterProperty } from '~/api/v2/caching-quarter-property' -import { ApiResponseError, OndemandApiNotEnabledError, UnsupportedTickerError } from '~/custom-functions/error' -import { BcodeResult } from '~/custom-functions/v2/bcode-result' -import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' -import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' -import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' - -export function bcodeQuarter( - client: CachingBuffettCodeApiClientV2, - ticker: string, - fiscalYear: number | LyWithOffset, - fiscalQuarter: number | LqWithOffset, - propertyName: string, - ondemandApiEnabled: boolean -): BcodeResult { - const period = new YearQuarterParam(fiscalYear, fiscalQuarter) - const companyService = new CompanyService(ticker, client) - if (!companyService.isSupportedTicker()) { - throw new UnsupportedTickerError() - } - - let quarter - if ((period.isLatestYear() && period.isLatestQuarter()) || !companyService.isOndemandQuarterApiPeriod(period)) { - quarter = client.quarter(ticker, period) - } else { - if (!ondemandApiEnabled) { - throw new OndemandApiNotEnabledError() - } - - quarter = client.ondemandQuarter(ticker, period) - } - - if (!quarter) { - throw new ApiResponseError() - } - - const value = quarter[propertyName] - const unit = CachingQuarterProperty.unitOf(propertyName) - - return new BcodeResult(value, unit) -} diff --git a/src/custom-functions/v2/bcode-result.test.ts b/src/custom-functions/v2/bcode-result.test.ts deleted file mode 100644 index c6fae02..0000000 --- a/src/custom-functions/v2/bcode-result.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { BcodeResult } from '~/custom-functions/v2/bcode-result' - -test('format', () => { - expect(new BcodeResult(1234.5678, '日').format(false, false)).toBe(1234.6) - expect(new BcodeResult(1234.5678, '日').format(true, false)).toBe(1234.5678) - expect(new BcodeResult(1234.5678, '日').format(false, true)).toBe('1,234.6日') - expect(new BcodeResult(1234.5678, '日').format(true, true)).toBe('1,234.5678日') - - expect(new BcodeResult(430602000000, '百万円').format(false, false)).toBe(430602) - expect(new BcodeResult(430602000000, '百万円').format(true, false)).toBe(430602) - expect(new BcodeResult(430602000000, '百万円').format(false, true)).toBe('430,602百万円') - expect(new BcodeResult(430602000000, '百万円').format(true, true)).toBe('430,602百万円') - - expect(new BcodeResult(430602000000, '円').format(false, false)).toBe(430602000000) - expect(new BcodeResult(430602000000, '円').format(true, false)).toBe(430602000000) - expect(new BcodeResult(430602000000, '円').format(false, true)).toBe('430,602,000,000円') - expect(new BcodeResult(430602000000, '円').format(true, true)).toBe('430,602,000,000円') - - expect(new BcodeResult(null, '百万円').format(true, false)).toBe('') - expect(new BcodeResult(null, '百万円').format(true, true)).toBe('') -}) diff --git a/src/custom-functions/v2/bcode-result.ts b/src/custom-functions/v2/bcode-result.ts deleted file mode 100644 index 73ec9ab..0000000 --- a/src/custom-functions/v2/bcode-result.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Formatter } from '~/services/formatter' - -export class BcodeResult { - constructor(public value: number | string | null, public unit: string) {} - - public format(isRawValue: boolean, isWithUnits: boolean): number | string { - let value = this.value - - if (value === null) { - return '' - } - - if (typeof value === 'number' && this.unit === '百万円') { - value /= 1000000 - } - - if (!isRawValue && typeof value === 'number') { - value = Formatter.round(value, 1) // 小数点第1位までに丸める - } - - if (isWithUnits) { - if (typeof value == 'number') { - return Formatter.commaStyled(value) + this.unit - } else { - return value + this.unit - } - } else { - return value - } - } -} diff --git a/src/custom-functions/v2/bcode.ts b/src/custom-functions/v2/bcode.ts deleted file mode 100644 index 78b3e3a..0000000 --- a/src/custom-functions/v2/bcode.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { HttpError } from '~/api/http-error' -import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' -import { QuarterProperty } from '~/api/v2/quarter-property' -import { ApiResponseError, OndemandApiNotEnabledError, UnsupportedTickerError } from '~/custom-functions/error' -import { bcodeIndicator } from '~/custom-functions/v2/bcode-indicator' -import { bcodeQuarter } from '~/custom-functions/v2/bcode-quarter' -import { BcodeResult } from '~/custom-functions/v2/bcode-result' -import { InvalidLYLQError, InvalidYearError, InvalidQuarterError } from '~/fiscal-periods/error' -import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' -import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' -import { Setting } from '~/setting' - -function validate(ticker: string, fiscalYear: string, fiscalQuarter: string, propertyName: string): void { - if (!ticker) { - throw new Error('<>') - } - - if (!propertyName) { - throw new Error('<>') - } - - const isQuarterProperty = QuarterProperty.isQuarterProperty(propertyName) - const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty(propertyName) - - if (!isQuarterProperty && !isIndicatorProperty) { - throw new Error(`<<指定された項目が見つかりません: ${propertyName}>>`) - } -} - -// TODO: エラーハンドリングの改善 -export function bcode( - ticker: string, - fiscalYear: string | number, - fiscalQuarter: string | number, - propertyName: string, - isRawValue = false, - isWithUnits = false -): number | string { - validate(ticker, fiscalYear.toString(), fiscalQuarter.toString(), propertyName) - - const setting = Setting.load() - if (!setting.token) { - throw new Error('<>') - } - - const client = new CachingBuffettCodeApiClientV2(setting.token) - - try { - let result: BcodeResult - if (fiscalYear && fiscalQuarter) { - const fy = - typeof fiscalYear === 'string' && fiscalYear.substring(0, 2) === 'LY' - ? LyWithOffset.parse(fiscalYear) - : parseInt(fiscalYear.toString(), 10) - const fq = - typeof fiscalQuarter === 'string' && fiscalQuarter.substring(0, 2) === 'LQ' - ? LqWithOffset.parse(fiscalQuarter) - : parseInt(fiscalQuarter.toString(), 10) - - result = bcodeQuarter(client, ticker, fy, fq, propertyName, setting.ondemandApiEnabled) - } else { - result = bcodeIndicator(client, ticker, propertyName) - } - - return result.format(isRawValue, isWithUnits) - } catch (e) { - if (e instanceof ApiResponseError) { - throw new Error('<<指定されたデータを取得できませんでした>>') - } else if (e instanceof OndemandApiNotEnabledError) { - throw new Error('<<従量課金APIが有効になっていません>>') - } else if (e instanceof UnsupportedTickerError) { - throw new Error('<<サポートされていないtickerです>>') - } else if (e instanceof HttpError) { - const code = e.response.getResponseCode() - - if (e.isInvalidTestingRequest()) { - throw new Error('<<テスト用のAPIキーでは取得できないデータです>>') - } else if (e.isInvalidTokenRequest()) { - throw new Error('<>') - } else if (code === 403) { - throw new Error('<<月間リクエスト制限に達しています>>') - } else if (code === 429) { - throw new Error('<>') - } else if (Math.floor(code / 100) === 4) { - throw new Error(`<<無効なリクエストです。${e.name}: ${e.message}>>`) - } else { - console.error('システムエラー', e.name, e.message) - throw new Error(`<<システムエラーが発生しました。${e.name}: ${e.message}>>`) - } - } else if (e instanceof InvalidLYLQError) { - throw new Error('<>') - } else if (e instanceof InvalidYearError) { - throw new Error(`<<無効な決算年度が指定されています: ${fiscalYear}>>`) - } else if (e instanceof InvalidQuarterError) { - throw new Error(`<<無効な四半期が指定されています: ${fiscalQuarter}>>`) - } else { - console.error('未定義のエラー', e.name, e.message) - throw new Error(`<<未定義のエラーが発生しました。${e.name}: ${e.message}>>`) - } - } -} diff --git a/src/custom-functions/v3/bcode-daily.ts b/src/custom-functions/v3/bcode-daily.ts index 8f49559..27793d0 100644 --- a/src/custom-functions/v3/bcode-daily.ts +++ b/src/custom-functions/v3/bcode-daily.ts @@ -1,11 +1,6 @@ import { CompanyService } from '~/api/company-service' import { BuffettCodeApiClientV3 } from '~/api/v3/client' -import { - ApiResponseError, - OndemandApiNotEnabledError, - PropertyNotFoundError, - UnsupportedTickerError -} from '~/custom-functions/error' +import { ApiResponseError, OndemandApiNotEnabledError, PropertyNotFoundError } from '~/custom-functions/error' import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { Daily } from '~/entities/v3/daily' import { DateParam } from '~/fiscal-periods/date-param' @@ -19,9 +14,6 @@ export function bcodeDaily( forceOndemandApiEnabled: boolean ): BcodeResult { const companyService = new CompanyService(ticker, client) - if (!companyService.isSupportedTicker()) { - throw new UnsupportedTickerError() - } let daily: Daily if (forceOndemandApiEnabled || companyService.isOndemandDailyApiPeriod(date)) { diff --git a/src/custom-functions/v3/bcode-quarter.ts b/src/custom-functions/v3/bcode-quarter.ts index 3e6faf1..ec73abe 100644 --- a/src/custom-functions/v3/bcode-quarter.ts +++ b/src/custom-functions/v3/bcode-quarter.ts @@ -1,11 +1,6 @@ import { CompanyService } from '~/api/company-service' import { BuffettCodeApiClientV3 } from '~/api/v3/client' -import { - ApiResponseError, - OndemandApiNotEnabledError, - PropertyNotFoundError, - UnsupportedTickerError -} from '~/custom-functions/error' +import { ApiResponseError, OndemandApiNotEnabledError, PropertyNotFoundError } from '~/custom-functions/error' import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { Quarter } from '~/entities/v3/quarter' import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' @@ -19,9 +14,6 @@ export function bcodeQuarter( forceOndemandApiEnabled: boolean ): BcodeResult { const companyService = new CompanyService(ticker, client) - if (!companyService.isSupportedTicker()) { - throw new UnsupportedTickerError() - } let quarter: Quarter if (forceOndemandApiEnabled || companyService.isOndemandQuarterApiPeriod(period)) { diff --git a/src/main.ts b/src/main.ts index b4643bf..bbc66f5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,4 @@ import { bcode } from '~/custom-functions/bcode' -import { bcodeLabel } from '~/custom-functions/bcode-label' -import { bcodeUnit } from '~/custom-functions/bcode-unit' import { Setting } from '~/setting' import { exportCsv } from '~/ui/csv-export-dialog' import * as menu from '~/ui/menu' @@ -47,41 +45,6 @@ global.exportCsv = exportCsv * @return 指定した銘柄の財務数字または指標 * @customfunction */ -global.BCODE = ( - ticker, - period, - propertyName, - isRawValue = false, - isWithUnits = false, - param5 = false -): number | string => { - return bcode(ticker, period, propertyName, isRawValue, isWithUnits, param5) -} - -/** - * 近日廃止予定です。 - * - * 指定した項目の名称を日本語で取得します。 - * - * @deprecated 近日廃止予定です - * @param {"net_sales"} propertyName 項目名 - * @return 指定した項目の名称 - * @customfunction - */ -global.BCODE_LABEL = (propertyName: string): string => { - return bcodeLabel(propertyName) -} - -/** - * 近日廃止予定です。 - * - * 指定した項目の単位を取得します。 - * - * @deprecated 近日廃止予定です - * @param {"net_sales"} propertyName 項目名 - * @return 指定した項目の単位 - * @customfunction - */ -global.BCODE_UNIT = (propertyName: string): string => { - return bcodeUnit(propertyName) +global.BCODE = (ticker, period, propertyName, isRawValue = false, isWithUnits = false): number | string => { + return bcode(ticker, period, propertyName, isRawValue, isWithUnits) } diff --git a/src/services/company-cache.test.ts b/src/services/company-cache.test.ts index fc80e9a..32de284 100644 --- a/src/services/company-cache.test.ts +++ b/src/services/company-cache.test.ts @@ -1,9 +1,8 @@ -import * as companyFixture from '~/__mocks__/fixtures/v2/company' +import * as companyFixture from '~/__mocks__/fixtures/v3/company' import { getMock, putMock } from '~/services/cache-test-helper' import { CompanyCache } from '~/services/company-cache' -const companies = companyFixture.default -const company = companies['2371'][0] +const company = companyFixture['data'] test('key', () => { expect(CompanyCache.key('2371')).toBe('company-2371') @@ -29,10 +28,3 @@ test('put', () => { expect(putMock).toBeCalledTimes(1) expect(putMock).toBeCalledWith('company-2371', JSON.stringify(company), 21600) }) - -test('putAll', () => { - CompanyCache.putAll(companies) - - expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith('company-2371', JSON.stringify(company), 21600) -}) diff --git a/src/services/company-cache.ts b/src/services/company-cache.ts index 9f8f8d3..b0dcbaf 100644 --- a/src/services/company-cache.ts +++ b/src/services/company-cache.ts @@ -23,14 +23,4 @@ export class CompanyCache { const cache = CacheService.getUserCache() cache.put(this.key(ticker), JSON.stringify(company), expirationInSeconds) } - - static putAll(companies: object, expirationInSeconds = 21600): void { - Object.keys(companies).forEach(ticker => { - if (ticker === 'column_description') { - return - } - - this.put(ticker, companies[ticker][0], expirationInSeconds) - }) - } } diff --git a/src/services/csv-exporter.test.ts b/src/services/csv-exporter.test.ts index d0325b6..bef4df1 100644 --- a/src/services/csv-exporter.test.ts +++ b/src/services/csv-exporter.test.ts @@ -5,7 +5,6 @@ import { QuarterCache } from '~/services/quarter-cache' jest.mock('~/setting', () => jest.requireActual('~/__mocks__/setting')) jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) -jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) jest.mock('~/services/quarter-cache', () => jest.requireActual('~/__mocks__/services/quarter-cache')) diff --git a/src/services/csv-exporter.ts b/src/services/csv-exporter.ts index b91dcbc..acc099a 100644 --- a/src/services/csv-exporter.ts +++ b/src/services/csv-exporter.ts @@ -29,10 +29,6 @@ export class CsvExporter { const setting = Setting.load() const client = new CachingBuffettCodeApiClientV3(setting.token) const companyService = new CompanyService(ticker, client, today) - if (!companyService.isSupportedTicker()) { - throw new Error('<<サポートされていないtickerです>>') - } - const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange(companyService) let ondemandQuarterApiPeriods = [] diff --git a/src/services/indicator-cache.test.ts b/src/services/indicator-cache.test.ts deleted file mode 100644 index 9e67681..0000000 --- a/src/services/indicator-cache.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as indicatorFixture from '~/__mocks__/fixtures/v2/indicator' -import { getMock, putMock } from '~/services/cache-test-helper' -import { IndicatorCache } from '~/services/indicator-cache' - -test('key', () => { - expect(IndicatorCache.key('6501')).toBe('indicator-6501') -}) - -const indicator = indicatorFixture['2371'][0] - -test('get', () => { - getMock.mockReturnValueOnce(JSON.stringify(indicator)) - expect(IndicatorCache.get('2371')).toEqual(indicator) - expect(IndicatorCache.get('9999')).toBeNull() - - expect(getMock).toBeCalledTimes(2) - expect(getMock).nthCalledWith(1, 'indicator-2371') - expect(getMock).nthCalledWith(2, 'indicator-9999') -}) - -test('put', () => { - IndicatorCache.put('2371', indicator) - - expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith('indicator-2371', JSON.stringify(indicator), 21600) -}) diff --git a/src/services/indicator-cache.ts b/src/services/indicator-cache.ts deleted file mode 100644 index ab2dc54..0000000 --- a/src/services/indicator-cache.ts +++ /dev/null @@ -1,28 +0,0 @@ -export class IndicatorCache { - static readonly prefix = 'indicator' - - private constructor() { - // - } - - static key(ticker: string): string { - return `${this.prefix}-${ticker}` - } - - static get(ticker: string): object | null { - const cache = CacheService.getUserCache() - const key = this.key(ticker) - const cached = cache.get(key) - if (!cached) { - return null - } - - return JSON.parse(cached) - } - - static put(ticker: string, indicator: object, expirationInSeconds = 21600): void { - const cache = CacheService.getUserCache() - const key = this.key(ticker) - cache.put(key, JSON.stringify(indicator), expirationInSeconds) - } -} diff --git a/src/services/indicator-property-cache.test.ts b/src/services/indicator-property-cache.test.ts deleted file mode 100644 index d0ec00e..0000000 --- a/src/services/indicator-property-cache.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as indicatorProperty from '~/__mocks__/fixtures/v2/indicator-property' -import { getMock, putMock } from '~/services/cache-test-helper' -import { IndicatorPropertyCache } from '~/services/indicator-property-cache' - -test('get', () => { - getMock.mockReturnValue(JSON.stringify(indicatorProperty)) - expect(IndicatorPropertyCache.get()).toEqual(indicatorProperty) - - expect(getMock).toBeCalledTimes(1) - expect(getMock).toBeCalledWith('indicator-property') -}) - -test('put', () => { - IndicatorPropertyCache.put(indicatorProperty) - - expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith('indicator-property', JSON.stringify(indicatorProperty), 21600) -}) diff --git a/src/services/indicator-property-cache.ts b/src/services/indicator-property-cache.ts deleted file mode 100644 index 403df9a..0000000 --- a/src/services/indicator-property-cache.ts +++ /dev/null @@ -1,22 +0,0 @@ -export class IndicatorPropertyCache { - static readonly key = 'indicator-property' - - private constructor() { - // - } - - static get(): object | null { - const cache = CacheService.getUserCache() - const cached = cache.get(IndicatorPropertyCache.key) - if (!cached) { - return null - } - - return JSON.parse(cached) - } - - static put(indicatorProperty: object, expirationInSeconds = 21600): void { - const cache = CacheService.getUserCache() - cache.put(IndicatorPropertyCache.key, JSON.stringify(indicatorProperty), expirationInSeconds) - } -} diff --git a/src/services/quarter-cache.test.ts b/src/services/quarter-cache.test.ts index 97e7e44..636a5b3 100644 --- a/src/services/quarter-cache.test.ts +++ b/src/services/quarter-cache.test.ts @@ -1,4 +1,4 @@ -import * as quarterFixture from '~/__mocks__/fixtures/v2/quarter' +import * as quarterFixture from '~/__mocks__/fixtures/v3/quarter' import { YearQuarter } from '~/fiscal-periods/year-quarter' import { getMock, putMock } from '~/services/cache-test-helper' import { QuarterCache } from '~/services/quarter-cache' @@ -7,7 +7,7 @@ test('key', () => { expect(QuarterCache.key('6501', new YearQuarter(2019, 4))).toBe('quarter-6501-2019Q4') }) -const quarter = quarterFixture['2371'][0] +const quarter = quarterFixture['data'] const columnDescription = quarterFixture['column_description'] const yearQuarter = new YearQuarter(2018, 1) diff --git a/src/services/quarter-property-cache.test.ts b/src/services/quarter-property-cache.test.ts deleted file mode 100644 index 6c3ef98..0000000 --- a/src/services/quarter-property-cache.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as quarterProperty from '~/__mocks__/fixtures/v2/quarter-property' -import { getMock, putMock } from '~/services/cache-test-helper' -import { QuarterPropertyCache } from '~/services/quarter-property-cache' - -test('get', () => { - getMock.mockReturnValue(JSON.stringify(quarterProperty)) - expect(QuarterPropertyCache.get()).toEqual(quarterProperty) - - expect(getMock).toBeCalledTimes(1) - expect(getMock).toBeCalledWith('quarter-property') -}) - -test('put', () => { - QuarterPropertyCache.put(quarterProperty) - - expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith('quarter-property', JSON.stringify(quarterProperty), 21600) -}) diff --git a/src/services/quarter-property-cache.ts b/src/services/quarter-property-cache.ts deleted file mode 100644 index c820f0b..0000000 --- a/src/services/quarter-property-cache.ts +++ /dev/null @@ -1,22 +0,0 @@ -export class QuarterPropertyCache { - static readonly key = 'quarter-property' - - private constructor() { - // - } - - static get(): object | null { - const cache = CacheService.getUserCache() - const cached = cache.get(this.key) - if (!cached) { - return null - } - - return JSON.parse(cached) - } - - static put(quarterProperty: object, expirationInSeconds = 21600): void { - const cache = CacheService.getUserCache() - cache.put(this.key, JSON.stringify(quarterProperty), expirationInSeconds) - } -}