diff --git a/.prettierrc.js b/.prettierrc.js index 09bb5f8..db9ff30 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,5 @@ module.exports = { + printWidth: 120, semi: false, singleQuote: true } diff --git a/src/__mocks__/services/company-cache.ts b/src/__mocks__/services/company-cache.ts index d4a4caa..afb6097 100644 --- a/src/__mocks__/services/company-cache.ts +++ b/src/__mocks__/services/company-cache.ts @@ -11,9 +11,7 @@ export class CompanyCache { } static putAll(companies: object): void { - Object.keys(companies).forEach(ticker => - CompanyCache.put(ticker, companies[ticker][0]) - ) + Object.keys(companies).forEach(ticker => CompanyCache.put(ticker, companies[ticker][0])) } // for testing diff --git a/src/__mocks__/services/quarter-cache.ts b/src/__mocks__/services/quarter-cache.ts index b9a4472..7f1db9f 100644 --- a/src/__mocks__/services/quarter-cache.ts +++ b/src/__mocks__/services/quarter-cache.ts @@ -30,9 +30,7 @@ export class QuarterCache { } static putData(ticker: string, quarter: object): void { - this.cache[ - `${ticker}-${quarter['fiscal_year']}Q${quarter['fiscal_quarter']}` - ] = quarter + this.cache[`${ticker}-${quarter['fiscal_year']}Q${quarter['fiscal_quarter']}`] = quarter } static putColumnDescription(columnDescription: object): void { diff --git a/src/api/company-service.test.ts b/src/api/company-service.test.ts index 4e54137..99f6478 100644 --- a/src/api/company-service.test.ts +++ b/src/api/company-service.test.ts @@ -10,15 +10,9 @@ 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') -) +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') @@ -29,49 +23,29 @@ test('isSupportedTicker', () => { test('convertYearQuarterParamToYearQuarter', () => { const client = new CachingBuffettCodeApiClientV2('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)) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, LQ))).toEqual(new YearQuarter(2021, 2)) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(new LyWithOffset(-5), LQ))).toEqual( + new YearQuarter(2016, 2) + ) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, new LqWithOffset(-1)))).toEqual( + new YearQuarter(2021, 1) + ) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, new LqWithOffset(-2)))).toEqual( + new YearQuarter(2020, 4) + ) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, new LqWithOffset(-3)))).toEqual( + new YearQuarter(2020, 3) + ) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, new LqWithOffset(-4)))).toEqual( + new YearQuarter(2020, 2) + ) + expect(service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, new LqWithOffset(-5)))).toEqual( + new YearQuarter(2020, 1) + ) expect( - service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, 3)) - ).toEqual(new YearQuarter(2021, 3)) - expect( - service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(2016, LQ)) - ).toEqual(new YearQuarter(2016, 2)) - expect( - service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(LY, LQ)) - ).toEqual(new YearQuarter(2021, 2)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(new LyWithOffset(-5), LQ) - ) - ).toEqual(new YearQuarter(2016, 2)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(LY, new LqWithOffset(-1)) - ) - ).toEqual(new YearQuarter(2021, 1)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(LY, new LqWithOffset(-2)) - ) - ).toEqual(new YearQuarter(2020, 4)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(LY, new LqWithOffset(-3)) - ) - ).toEqual(new YearQuarter(2020, 3)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(LY, new LqWithOffset(-4)) - ) - ).toEqual(new YearQuarter(2020, 2)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(LY, new LqWithOffset(-5)) - ) - ).toEqual(new YearQuarter(2020, 1)) - expect( - service.convertYearQuarterParamToYearQuarter( - new YearQuarterParam(new LyWithOffset(-5), new LqWithOffset(-5)) - ) + service.convertYearQuarterParamToYearQuarter(new YearQuarterParam(new LyWithOffset(-5), new LqWithOffset(-5))) ).toEqual(new YearQuarter(2015, 1)) }) @@ -79,56 +53,28 @@ test('isOndemandQuarterApiPeriod', () => { const client = new CachingBuffettCodeApiClientV2('token') const service = new CompanyService('2371', client) - expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2001, 4))).toBe( - true - ) - expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2016, 2))).toBe( - true - ) - expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2016, 3))).toBe( - false - ) - expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(LY, 3))).toBe( + expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2001, 4))).toBe(true) + expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2016, 2))).toBe(true) + expect(service.isOndemandQuarterApiPeriod(new YearQuarter(2016, 3))).toBe(false) + expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(LY, 3))).toBe(false) + expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(2016, LQ))).toBe(true) + expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(LY, LQ))).toBe(false) + expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(new LyWithOffset(-4), new LqWithOffset(-3)))).toBe( false ) - expect( - service.isOndemandQuarterApiPeriod(new YearQuarterParam(2016, LQ)) - ).toBe(true) - expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(LY, LQ))).toBe( - false + expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(new LyWithOffset(-4), new LqWithOffset(-4)))).toBe( + true ) - expect( - service.isOndemandQuarterApiPeriod( - new YearQuarterParam(new LyWithOffset(-4), new LqWithOffset(-3)) - ) - ).toBe(false) - expect( - service.isOndemandQuarterApiPeriod( - new YearQuarterParam(new LyWithOffset(-4), new LqWithOffset(-4)) - ) - ).toBe(true) - expect( - service.isOndemandQuarterApiPeriod( - new YearQuarterParam(new LyWithOffset(-5), LQ) - ) - ).toBe(true) + expect(service.isOndemandQuarterApiPeriod(new YearQuarterParam(new LyWithOffset(-5), LQ))).toBe(true) }) test('isOndemandDailyApiPeriod', () => { const client = new CachingBuffettCodeApiClientV3('token') const service = new CompanyService('2371', client) - expect( - service.isOndemandDailyApiPeriod(new DateParam(new Date('2003-10-10'))) - ).toBe(true) - expect( - service.isOndemandDailyApiPeriod(new DateParam(new Date('2016-11-12'))) - ).toBe(true) - expect( - service.isOndemandDailyApiPeriod(new DateParam(new Date('2016-11-13'))) - ).toBe(false) - expect(service.isOndemandDailyApiPeriod(new DateParam(new Date()))).toBe( - false - ) + expect(service.isOndemandDailyApiPeriod(new DateParam(new Date('2003-10-10')))).toBe(true) + expect(service.isOndemandDailyApiPeriod(new DateParam(new Date('2016-11-12')))).toBe(true) + expect(service.isOndemandDailyApiPeriod(new DateParam(new Date('2016-11-13')))).toBe(false) + expect(service.isOndemandDailyApiPeriod(new DateParam(new Date()))).toBe(false) expect(service.isOndemandDailyApiPeriod(new DateParam('latest'))).toBe(false) }) diff --git a/src/api/company-service.ts b/src/api/company-service.ts index 9d27c9f..f78dd55 100644 --- a/src/api/company-service.ts +++ b/src/api/company-service.ts @@ -21,18 +21,14 @@ export class CompanyService { return !!this.company } - public convertYearQuarterParamToYearQuarter( - period: YearQuarterParam - ): YearQuarter { + public convertYearQuarterParamToYearQuarter(period: YearQuarterParam): YearQuarter { if (period.year instanceof LyWithOffset) { period.year = this.company['latest_fiscal_year'] + period.year.offset } if (period.quarter instanceof LqWithOffset) { - period.year = - (period.year as number) + Math.ceil(period.quarter.offset / 4) - period.quarter = - this.company['latest_fiscal_quarter'] + (period.quarter.offset % 4) + period.year = (period.year as number) + Math.ceil(period.quarter.offset / 4) + period.quarter = this.company['latest_fiscal_quarter'] + (period.quarter.offset % 4) if (period.quarter <= 0) { period.year -= 1 @@ -43,9 +39,7 @@ export class CompanyService { return period.toYearQuarter() } - public isOndemandQuarterApiPeriod( - _period: YearQuarter | YearQuarterParam - ): boolean { + public isOndemandQuarterApiPeriod(_period: YearQuarter | YearQuarterParam): boolean { if (!this.isSupportedTicker()) { throw new Error('unsupported ticker') } diff --git a/src/api/http-error.ts b/src/api/http-error.ts index 2d183b4..0b4597b 100644 --- a/src/api/http-error.ts +++ b/src/api/http-error.ts @@ -12,11 +12,9 @@ export class HttpError implements Error { public isInvalidTestingRequest(): boolean { const content = this.response.getContentText() return ( - content === - '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}' || + content === '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}' || content === '{"message":"Testing apikey is not allowed"}' || - content === - '{"message":"Trial request only supports ticker ending \'01\'"}' + content === '{"message":"Trial request only supports ticker ending \'01\'"}' ) } diff --git a/src/api/ondemand-api-period-range.test.ts b/src/api/ondemand-api-period-range.test.ts index 55b5e19..ef1448c 100644 --- a/src/api/ondemand-api-period-range.test.ts +++ b/src/api/ondemand-api-period-range.test.ts @@ -4,27 +4,19 @@ import { CachingBuffettCodeApiClientV2 } from '~/api/v2/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('~/services/company-cache', () => - jest.requireActual('~/__mocks__/services/company-cache') -) +jest.mock('~/api/v2/client', () => jest.requireActual('~/__mocks__/api/v2/client')) +jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) test('selectOndemandQuarterApiPeriod', () => { const ticker = '2371' const client = new CachingBuffettCodeApiClientV2('token') const companyService = new CompanyService(ticker, client) - const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange( - companyService - ) + const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange(companyService) const from = new YearQuarter(2014, 1) const to = new YearQuarter(2017, 4) const range = new YearQuarterRange(from, to) - expect( - ondemandQuarterApiPeriodRange.selectOndemandQuarterApiPeriod(ticker, range) - ).toEqual([ + expect(ondemandQuarterApiPeriodRange.selectOndemandQuarterApiPeriod(ticker, range)).toEqual([ new YearQuarter(2014, 1), new YearQuarter(2014, 2), new YearQuarter(2014, 3), @@ -42,16 +34,12 @@ test('filterOndemandQuarterApiPeriod', () => { const ticker = '2371' const client = new CachingBuffettCodeApiClientV2('token') const companyService = new CompanyService(ticker, client) - const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange( - companyService - ) + const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange(companyService) const from = new YearQuarter(2014, 1) const to = new YearQuarter(2017, 4) const range = new YearQuarterRange(from, to) - expect( - ondemandQuarterApiPeriodRange.filterOndemandQuarterApiPeriod(ticker, range) - ).toEqual([ + expect(ondemandQuarterApiPeriodRange.filterOndemandQuarterApiPeriod(ticker, range)).toEqual([ new YearQuarter(2016, 3), new YearQuarter(2016, 4), new YearQuarter(2017, 1), diff --git a/src/api/ondemand-api-period-range.ts b/src/api/ondemand-api-period-range.ts index 62ceda3..075dc96 100644 --- a/src/api/ondemand-api-period-range.ts +++ b/src/api/ondemand-api-period-range.ts @@ -5,21 +5,11 @@ import { YearQuarterRange } from '~/fiscal-periods/year-quarter-range' export class OndemandApiPeriodRange { constructor(public companyService: CompanyService) {} - public selectOndemandQuarterApiPeriod( - ticker: string, - range: YearQuarterRange - ): YearQuarter[] { - return range - .range() - .filter(period => this.companyService.isOndemandQuarterApiPeriod(period)) + public selectOndemandQuarterApiPeriod(ticker: string, range: YearQuarterRange): YearQuarter[] { + return range.range().filter(period => this.companyService.isOndemandQuarterApiPeriod(period)) } - public filterOndemandQuarterApiPeriod( - ticker: string, - range: YearQuarterRange - ): YearQuarter[] { - return range - .range() - .filter(period => !this.companyService.isOndemandQuarterApiPeriod(period)) + public filterOndemandQuarterApiPeriod(ticker: string, range: YearQuarterRange): YearQuarter[] { + return range.range().filter(period => !this.companyService.isOndemandQuarterApiPeriod(period)) } } diff --git a/src/api/test-helper.ts b/src/api/test-helper.ts index a610456..788dafb 100644 --- a/src/api/test-helper.ts +++ b/src/api/test-helper.ts @@ -4,10 +4,7 @@ declare const global: any // FIXME: Mockの型がみつからない /* eslint @typescript-eslint/no-explicit-any: 0 */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function useMockedUrlFetchApp( - responseCode: number, - contentText: string -) { +export function useMockedUrlFetchApp(responseCode: number, contentText: string) { const mockGetResponseCode = jest.fn() mockGetResponseCode.mockReturnValue(responseCode) diff --git a/src/api/url-builder.test.ts b/src/api/url-builder.test.ts index 923a700..3525bf5 100644 --- a/src/api/url-builder.test.ts +++ b/src/api/url-builder.test.ts @@ -7,7 +7,5 @@ test('toString', () => { bar: 'baz?' } const builder = new UrlBuilder(endpoint, params) - expect(builder.toString()).toBe( - 'https://example.com?foo=foo%20bar&bar=baz%3F' - ) + expect(builder.toString()).toBe('https://example.com?foo=foo%20bar&bar=baz%3F') }) diff --git a/src/api/v2/caching-client.test.ts b/src/api/v2/caching-client.test.ts index 1d8f180..a10eb24 100644 --- a/src/api/v2/caching-client.test.ts +++ b/src/api/v2/caching-client.test.ts @@ -7,18 +7,10 @@ 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') -) +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() @@ -105,9 +97,7 @@ describe('quarter', () => { expect(res['fiscal_year']).toBe(period.year) expect(res['fiscal_quarter']).toBe(period.quarter) - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual( - cached - ) + expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual(cached) }) }) @@ -127,9 +117,7 @@ describe('quarter', () => { expect(res['fiscal_year']).toBe(2018) expect(res['fiscal_quarter']).toBe(1) - expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toEqual( - res - ) + expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toEqual(res) }) }) }) @@ -162,9 +150,7 @@ describe('ondemandQuarter', () => { const res = client.ondemandQuarter(ticker, period) expect(res).toEqual(cached) - expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual( - cached - ) + expect(QuarterCache.getData(ticker, period.toYearQuarter())).toEqual(cached) }) }) @@ -184,9 +170,7 @@ describe('ondemandQuarter', () => { expect(res['fiscal_year']).toBe(2018) expect(res['fiscal_quarter']).toBe(1) - expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toEqual( - res - ) + expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).toEqual(res) }) }) }) diff --git a/src/api/v2/caching-indicator-property.test.ts b/src/api/v2/caching-indicator-property.test.ts index 92f3f4b..6c2764c 100644 --- a/src/api/v2/caching-indicator-property.test.ts +++ b/src/api/v2/caching-indicator-property.test.ts @@ -1,9 +1,7 @@ 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('~/api/v2/indicator-property', () => jest.requireActual('~/__mocks__/api/v2/indicator-property')) jest.mock('~/services/indicator-property-cache', () => jest.requireActual('~/__mocks__/services/indicator-property-cache') diff --git a/src/api/v2/caching-quarter-property.test.ts b/src/api/v2/caching-quarter-property.test.ts index 3f9d9a9..6f4eb7d 100644 --- a/src/api/v2/caching-quarter-property.test.ts +++ b/src/api/v2/caching-quarter-property.test.ts @@ -1,13 +1,9 @@ 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('~/api/v2/quarter-property', () => jest.requireActual('~/__mocks__/api/v2/quarter-property')) -jest.mock('~/services/quarter-property-cache', () => - jest.requireActual('~/__mocks__/services/quarter-property-cache') -) +jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) describe('fetch', () => { test('(uncached)', () => { diff --git a/src/api/v2/client.test.ts b/src/api/v2/client.test.ts index 0d6f1d5..c1007cc 100644 --- a/src/api/v2/client.test.ts +++ b/src/api/v2/client.test.ts @@ -20,10 +20,7 @@ test('HttpError#isInvalidTestingRequest', () => { }) test('request', () => { - const mockFetch = useMockedUrlFetchApp( - 200, - '{"message": "this is a message"}' - ) + const mockFetch = useMockedUrlFetchApp(200, '{"message": "this is a message"}') expect( BuffettCodeApiClientV2['request']('http://example.com', { @@ -42,10 +39,7 @@ test('request', () => { }) test('request when testing apikey error', () => { - useMockedUrlFetchApp( - 200, - '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}' - ) + useMockedUrlFetchApp(200, '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}') const request = BuffettCodeApiClientV2['request'] expect(() => request('http://example.com')).toThrow(HttpError) @@ -67,9 +61,7 @@ test('request when 503 error', () => { request('http://example.com') } catch (e) { expect(e.response.getResponseCode()).toBe(503) - expect(e.response.getContentText()).toBe( - '{"message": "Service Unavailable"}' - ) + expect(e.response.getContentText()).toBe('{"message": "Service Unavailable"}') } }) @@ -81,9 +73,7 @@ test('company', () => { 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][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 @@ -99,9 +89,7 @@ test('quarter', () => { 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][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 @@ -116,9 +104,7 @@ test('indicator', () => { 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][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 diff --git a/src/api/v2/client.ts b/src/api/v2/client.ts index 461da63..f76fa4e 100644 --- a/src/api/v2/client.ts +++ b/src/api/v2/client.ts @@ -17,11 +17,7 @@ export class BuffettCodeApiClientV2 { 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() - ) { + if (Math.floor(code / 100) === 4 || Math.floor(code / 100) === 5 || error.isInvalidTestingRequest()) { throw error } @@ -91,10 +87,7 @@ export class BuffettCodeApiClientV2 { return res[ticker][0] // NOTE: indicatorは常に1つ } - public ondemandQuarter( - ticker: string, - period: YearQuarterParam - ): object | null { + public ondemandQuarter(ticker: string, period: YearQuarterParam): object | null { const endpoint = BuffettCodeApiClientV2.baseUrl + '/ondemand/quarter' const builder = new UrlBuilder(endpoint, { ticker, diff --git a/src/api/v3/caching-client.test.ts b/src/api/v3/caching-client.test.ts index 47e3a09..c70082e 100644 --- a/src/api/v3/caching-client.test.ts +++ b/src/api/v3/caching-client.test.ts @@ -8,18 +8,10 @@ import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' import { YearQuarter } from '~/fiscal-periods/year-quarter' import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' -jest.mock('~/api/v3/client', () => - jest.requireActual('~/__mocks__/api/v3/client') -) -jest.mock('~/services/company-cache', () => - jest.requireActual('~/__mocks__/services/company-cache') -) -jest.mock('~/services/daily-cache', () => - jest.requireActual('~/__mocks__/services/daily-cache') -) -jest.mock('~/services/quarter-cache', () => - jest.requireActual('~/__mocks__/services/quarter-cache') -) +jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) +jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) +jest.mock('~/services/daily-cache', () => jest.requireActual('~/__mocks__/services/daily-cache')) +jest.mock('~/services/quarter-cache', () => jest.requireActual('~/__mocks__/services/quarter-cache')) const LY = new LyWithOffset() const LQ = new LqWithOffset() diff --git a/src/api/v3/client.test.ts b/src/api/v3/client.test.ts index 470cf76..52b4cc3 100644 --- a/src/api/v3/client.test.ts +++ b/src/api/v3/client.test.ts @@ -16,10 +16,7 @@ import { YearQuarterRange } from '~/fiscal-periods/year-quarter-range' describe('BuffettCodeApiClientV3', () => { test('HttpError#isInvalidTestingRequest', () => { - const res1 = useMockedUrlFetchApp( - 200, - '{"message":"Testing apikey is not allowed"}' - )() + const res1 = useMockedUrlFetchApp(200, '{"message":"Testing apikey is not allowed"}')() const error1 = new HttpError('https://example.com', res1) expect(error1.isInvalidTestingRequest()).toBeTruthy() @@ -29,10 +26,7 @@ describe('BuffettCodeApiClientV3', () => { }) test('request', () => { - const mockFetch = useMockedUrlFetchApp( - 200, - '{"message": "this is a message"}' - ) + const mockFetch = useMockedUrlFetchApp(200, '{"message": "this is a message"}') expect( BuffettCodeApiClientV3['request']('http://example.com', { @@ -51,10 +45,7 @@ describe('BuffettCodeApiClientV3', () => { }) test('request when testing apikey error', () => { - useMockedUrlFetchApp( - 200, - '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}' - ) + useMockedUrlFetchApp(200, '{"message":"Testing Apikey is only allowed to ticker ending with \\"01\\""}') const request = BuffettCodeApiClientV3['request'] expect(() => request('http://example.com')).toThrow(HttpError) @@ -76,9 +67,7 @@ describe('BuffettCodeApiClientV3', () => { request('http://example.com') } catch (e) { expect(e.response.getResponseCode()).toBe(503) - expect(e.response.getContentText()).toBe( - '{"message": "Service Unavailable"}' - ) + expect(e.response.getContentText()).toBe('{"message": "Service Unavailable"}') } }) @@ -90,9 +79,7 @@ describe('BuffettCodeApiClientV3', () => { expect(client.company(ticker)).toEqual(company['data']) 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/v3/company?ticker=${ticker}` - ) + expect(mockFetch.mock.calls[0][0]).toBe(`https://api.buffett-code.com/api/v3/company?ticker=${ticker}`) expect(mockFetch.mock.calls[0][1]).toEqual({ headers: { 'x-api-key': 'foo' }, muteHttpExceptions: true @@ -105,14 +92,10 @@ describe('BuffettCodeApiClientV3', () => { const client = new BuffettCodeApiClientV3('foo') const ticker = '2371' const period = new YearQuarterParam(2018, 1) - expect(client.quarter(ticker, period)).toEqual( - Quarter.fromResponse(quarter) - ) + expect(client.quarter(ticker, period)).toEqual(Quarter.fromResponse(quarter)) 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/v3/quarter?ticker=2371&fy=2018&fq=1' - ) + expect(mockFetch.mock.calls[0][0]).toBe('https://api.buffett-code.com/api/v3/quarter?ticker=2371&fy=2018&fq=1') expect(mockFetch.mock.calls[0][1]).toEqual({ headers: { 'x-api-key': 'foo' }, muteHttpExceptions: true @@ -127,14 +110,10 @@ describe('BuffettCodeApiClientV3', () => { const client = new BuffettCodeApiClientV3('foo') const ticker = '2371' const period = new YearQuarterParam(LY, LQ) - expect(client.quarter(ticker, period)).toEqual( - Quarter.fromResponse(quarter) - ) + expect(client.quarter(ticker, period)).toEqual(Quarter.fromResponse(quarter)) 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/v3/quarter?ticker=2371&fy=LY&fq=LQ' - ) + expect(mockFetch.mock.calls[0][0]).toBe('https://api.buffett-code.com/api/v3/quarter?ticker=2371&fy=LY&fq=LQ') expect(mockFetch.mock.calls[0][1]).toEqual({ headers: { 'x-api-key': 'foo' }, muteHttpExceptions: true @@ -152,13 +131,8 @@ describe('BuffettCodeApiClientV3', () => { const client = new BuffettCodeApiClientV3('foo') const ticker = '2371' - const range = new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2018, 4) - ) - expect(client.bulkQuarter(ticker, range)).toEqual( - Quarter.fromBulkResponse(bulkQuarter) - ) + const range = new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2018, 4)) + expect(client.bulkQuarter(ticker, range)).toEqual(Quarter.fromBulkResponse(bulkQuarter)) expect(mockFetch.mock.calls.length).toBe(1) expect(mockFetch.mock.calls[0].length).toBe(2) expect(mockFetch.mock.calls[0][0]).toBe( @@ -176,9 +150,7 @@ describe('BuffettCodeApiClientV3', () => { const client = new BuffettCodeApiClientV3('foo') const ticker = '2371' const period = new YearQuarterParam(2018, 1) - expect(client.ondemandQuarter(ticker, period)).toEqual( - Quarter.fromResponse(quarter) - ) + expect(client.ondemandQuarter(ticker, period)).toEqual(Quarter.fromResponse(quarter)) expect(mockFetch.mock.calls.length).toBe(1) expect(mockFetch.mock.calls[0].length).toBe(2) expect(mockFetch.mock.calls[0][0]).toBe( @@ -199,9 +171,7 @@ describe('BuffettCodeApiClientV3', () => { expect(client.daily(ticker, date)).toEqual(Daily.fromResponse(daily)) 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/v3/daily?ticker=2371&date=2021-08-11' - ) + expect(mockFetch.mock.calls[0][0]).toBe('https://api.buffett-code.com/api/v3/daily?ticker=2371&date=2021-08-11') expect(mockFetch.mock.calls[0][1]).toEqual({ headers: { 'x-api-key': 'foo' }, muteHttpExceptions: true @@ -220,9 +190,7 @@ describe('BuffettCodeApiClientV3', () => { const client = new BuffettCodeApiClientV3('foo') const ticker = '2371' const range = new DateRange(new Date('2021-08-11'), new Date('2021-08-17')) - expect(client.bulkDaily(ticker, range)).toEqual( - Daily.fromBulkResponse(bulkDaily) - ) + expect(client.bulkDaily(ticker, range)).toEqual(Daily.fromBulkResponse(bulkDaily)) expect(mockFetch.mock.calls.length).toBe(1) expect(mockFetch.mock.calls[0].length).toBe(2) expect(mockFetch.mock.calls[0][0]).toBe( @@ -240,9 +208,7 @@ describe('BuffettCodeApiClientV3', () => { const client = new BuffettCodeApiClientV3('foo') const ticker = '2371' const date = new DateParam(new Date('2021-08-11')) - expect(client.ondemandDaily(ticker, date)).toEqual( - Daily.fromResponse(daily) - ) + expect(client.ondemandDaily(ticker, date)).toEqual(Daily.fromResponse(daily)) expect(mockFetch.mock.calls.length).toBe(1) expect(mockFetch.mock.calls[0].length).toBe(2) expect(mockFetch.mock.calls[0][0]).toBe( diff --git a/src/api/v3/client.ts b/src/api/v3/client.ts index 3f10b68..00a1dce 100644 --- a/src/api/v3/client.ts +++ b/src/api/v3/client.ts @@ -22,11 +22,7 @@ export class BuffettCodeApiClientV3 { 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() - ) { + if (Math.floor(code / 100) === 4 || Math.floor(code / 100) === 5 || error.isInvalidTestingRequest()) { throw error } diff --git a/src/custom-functions/bcode-label.test.ts b/src/custom-functions/bcode-label.test.ts index 4c0bbb7..2196bbd 100644 --- a/src/custom-functions/bcode-label.test.ts +++ b/src/custom-functions/bcode-label.test.ts @@ -2,18 +2,12 @@ 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('~/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') -) +jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) test('bcodeLabel', () => { expect(IndicatorPropertyCache.get()).toBeNull() diff --git a/src/custom-functions/bcode-label.ts b/src/custom-functions/bcode-label.ts index 77dddc9..8d93bca 100644 --- a/src/custom-functions/bcode-label.ts +++ b/src/custom-functions/bcode-label.ts @@ -6,12 +6,8 @@ export function bcodeLabel(propertyName: string): string { throw new Error('<>') } - const isQuarterProperty = CachingQuarterProperty.isQuarterProperty( - propertyName - ) - const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty( - propertyName - ) + const isQuarterProperty = CachingQuarterProperty.isQuarterProperty(propertyName) + const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty(propertyName) if (!isQuarterProperty && !isIndicatorProperty) { throw new Error(`<<指定された項目が見つかりません: ${propertyName}>>`) diff --git a/src/custom-functions/bcode-unit.test.ts b/src/custom-functions/bcode-unit.test.ts index b5ce897..06767c4 100644 --- a/src/custom-functions/bcode-unit.test.ts +++ b/src/custom-functions/bcode-unit.test.ts @@ -2,18 +2,12 @@ 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('~/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') -) +jest.mock('~/services/quarter-property-cache', () => jest.requireActual('~/__mocks__/services/quarter-property-cache')) test('bcodeUnit', () => { expect(IndicatorPropertyCache.get()).toBeNull() diff --git a/src/custom-functions/bcode-unit.ts b/src/custom-functions/bcode-unit.ts index 5acd371..8a1b94e 100644 --- a/src/custom-functions/bcode-unit.ts +++ b/src/custom-functions/bcode-unit.ts @@ -6,12 +6,8 @@ export function bcodeUnit(propertyName: string): string { throw new Error('<>') } - const isQuarterProperty = CachingQuarterProperty.isQuarterProperty( - propertyName - ) - const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty( - propertyName - ) + const isQuarterProperty = CachingQuarterProperty.isQuarterProperty(propertyName) + const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty(propertyName) if (!isQuarterProperty && !isIndicatorProperty) { throw new Error(`<<指定された項目が見つかりません: ${propertyName}>>`) diff --git a/src/custom-functions/bcode.test.ts b/src/custom-functions/bcode.test.ts index 8c1c7a8..219423c 100644 --- a/src/custom-functions/bcode.test.ts +++ b/src/custom-functions/bcode.test.ts @@ -28,4 +28,5 @@ test('isV3Call', () => { expect(isV3Call('', '')).toBeFalsy() expect(isV3Call('2020Q1', 'net_sales')).toBeTruthy() expect(isV3Call('LYLQ', 'net_sales')).toBeTruthy() + expect(isV3Call('2020-09-06', 'market_capital')).toBeTruthy() }) diff --git a/src/custom-functions/bcode.ts b/src/custom-functions/bcode.ts index c6f5b1c..563a976 100644 --- a/src/custom-functions/bcode.ts +++ b/src/custom-functions/bcode.ts @@ -7,20 +7,14 @@ export function castStringAsBoolean(bool: string | boolean): boolean { return typeof bool === 'string' ? bool.toLowerCase() === 'true' : bool } -export function isV3Call( - param1: string | number, - param2: string | number -): boolean { +export function isV3Call(param1: string | number, param2: string | number): boolean { if (param1 == undefined || param2 == undefined) { throw new Error('引数が正しくありません') } else if (typeof param1 === 'number' || typeof param2 === 'number') { return false } else if (param1 === '' || param2 === '') { return false - } else if ( - LyWithOffset.isValidFormat(param1) || - LqWithOffset.isValidFormat(param2) - ) { + } else if (LyWithOffset.isValidFormat(param1) || LqWithOffset.isValidFormat(param2)) { return false } else if (param1.match(/^\d+$/) || param1.match(/^\d+$/)) { return false @@ -46,21 +40,8 @@ export function bcode( param2 = param2.toString() } - return bcodeV3( - ticker, - param1, - param2, - castStringAsBoolean(param3), - castStringAsBoolean(param4) - ) + return bcodeV3(ticker, param1, param2, castStringAsBoolean(param3), castStringAsBoolean(param4)) } else { - return bcodeV2( - ticker, - param1, - param2, - param3.toString(), - castStringAsBoolean(param4), - castStringAsBoolean(param5) - ) + return bcodeV2(ticker, param1, param2, param3.toString(), castStringAsBoolean(param4), castStringAsBoolean(param5)) } } diff --git a/src/custom-functions/error.test.ts b/src/custom-functions/error.test.ts index 90025b6..2652fa6 100644 --- a/src/custom-functions/error.test.ts +++ b/src/custom-functions/error.test.ts @@ -1,8 +1,4 @@ -import { - ApiResponseError, - OndemandApiNotEnabledError, - PropertyNotFoundError -} from '~/custom-functions/error' +import { ApiResponseError, OndemandApiNotEnabledError, PropertyNotFoundError } from '~/custom-functions/error' test('ApiResponseError', () => { const error = new ApiResponseError() diff --git a/src/custom-functions/v2/bcode-indicator.test.ts b/src/custom-functions/v2/bcode-indicator.test.ts index d077b1c..dc214fc 100644 --- a/src/custom-functions/v2/bcode-indicator.test.ts +++ b/src/custom-functions/v2/bcode-indicator.test.ts @@ -4,15 +4,9 @@ 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('~/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') ) diff --git a/src/custom-functions/v2/bcode-quarter.test.ts b/src/custom-functions/v2/bcode-quarter.test.ts index 011c8ef..91f03c8 100644 --- a/src/custom-functions/v2/bcode-quarter.test.ts +++ b/src/custom-functions/v2/bcode-quarter.test.ts @@ -7,21 +7,11 @@ 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') -) +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', () => { @@ -40,9 +30,7 @@ describe('bcodeQuarter', () => { 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(QuarterCache.getData(ticker, yearQuarter)['net_sales']).toBe(12513000000.0) expect(QuarterPropertyCache.get()).not.toBeNull() }) @@ -58,9 +46,7 @@ describe('bcodeQuarter', () => { 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(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 index 691ab26..4544c3f 100644 --- a/src/custom-functions/v2/bcode-quarter.ts +++ b/src/custom-functions/v2/bcode-quarter.ts @@ -1,11 +1,7 @@ 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 { 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' @@ -26,10 +22,7 @@ export function bcodeQuarter( } let quarter - if ( - (period.isLatestYear() && period.isLatestQuarter()) || - !companyService.isOndemandQuarterApiPeriod(period) - ) { + if ((period.isLatestYear() && period.isLatestQuarter()) || !companyService.isOndemandQuarterApiPeriod(period)) { quarter = client.quarter(ticker, period) } else { if (!ondemandApiEnabled) { diff --git a/src/custom-functions/v2/bcode-result.test.ts b/src/custom-functions/v2/bcode-result.test.ts index f71cd1d..c6fae02 100644 --- a/src/custom-functions/v2/bcode-result.test.ts +++ b/src/custom-functions/v2/bcode-result.test.ts @@ -4,35 +4,17 @@ 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(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(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(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.ts b/src/custom-functions/v2/bcode.ts index 2213212..78b3e3a 100644 --- a/src/custom-functions/v2/bcode.ts +++ b/src/custom-functions/v2/bcode.ts @@ -2,29 +2,16 @@ 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 { 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 { 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 { +function validate(ticker: string, fiscalYear: string, fiscalQuarter: string, propertyName: string): void { if (!ticker) { throw new Error('<>') } @@ -34,9 +21,7 @@ function validate( } const isQuarterProperty = QuarterProperty.isQuarterProperty(propertyName) - const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty( - propertyName - ) + const isIndicatorProperty = CachingIndicatorProperty.isIndicatorProperty(propertyName) if (!isQuarterProperty && !isIndicatorProperty) { throw new Error(`<<指定された項目が見つかりません: ${propertyName}>>`) @@ -52,12 +37,7 @@ export function bcode( isRawValue = false, isWithUnits = false ): number | string { - validate( - ticker, - fiscalYear.toString(), - fiscalQuarter.toString(), - propertyName - ) + validate(ticker, fiscalYear.toString(), fiscalQuarter.toString(), propertyName) const setting = Setting.load() if (!setting.token) { @@ -74,19 +54,11 @@ export function bcode( ? LyWithOffset.parse(fiscalYear) : parseInt(fiscalYear.toString(), 10) const fq = - typeof fiscalQuarter === 'string' && - fiscalQuarter.substring(0, 2) === 'LQ' + typeof fiscalQuarter === 'string' && fiscalQuarter.substring(0, 2) === 'LQ' ? LqWithOffset.parse(fiscalQuarter) : parseInt(fiscalQuarter.toString(), 10) - result = bcodeQuarter( - client, - ticker, - fy, - fq, - propertyName, - setting.ondemandApiEnabled - ) + result = bcodeQuarter(client, ticker, fy, fq, propertyName, setting.ondemandApiEnabled) } else { result = bcodeIndicator(client, ticker, propertyName) } @@ -114,9 +86,7 @@ export function bcode( throw new Error(`<<無効なリクエストです。${e.name}: ${e.message}>>`) } else { console.error('システムエラー', e.name, e.message) - throw new Error( - `<<システムエラーが発生しました。${e.name}: ${e.message}>>` - ) + throw new Error(`<<システムエラーが発生しました。${e.name}: ${e.message}>>`) } } else if (e instanceof InvalidLYLQError) { throw new Error('<>') @@ -126,9 +96,7 @@ export function bcode( throw new Error(`<<無効な四半期が指定されています: ${fiscalQuarter}>>`) } else { console.error('未定義のエラー', e.name, e.message) - throw new Error( - `<<未定義のエラーが発生しました。${e.name}: ${e.message}>>` - ) + throw new Error(`<<未定義のエラーが発生しました。${e.name}: ${e.message}>>`) } } } diff --git a/src/custom-functions/v3/bcode-daily.test.ts b/src/custom-functions/v3/bcode-daily.test.ts index 35ddb4f..a0977a7 100644 --- a/src/custom-functions/v3/bcode-daily.test.ts +++ b/src/custom-functions/v3/bcode-daily.test.ts @@ -4,15 +4,9 @@ import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { DateParam } from '~/fiscal-periods/date-param' import { DailyCache } from '~/services/daily-cache' -jest.mock('~/api/v3/client', () => - jest.requireActual('~/__mocks__/api/v3/client') -) -jest.mock('~/services/company-cache', () => - jest.requireActual('~/__mocks__/services/company-cache') -) -jest.mock('~/services/daily-cache', () => - jest.requireActual('~/__mocks__/services/daily-cache') -) +jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) +jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) +jest.mock('~/services/daily-cache', () => jest.requireActual('~/__mocks__/services/daily-cache')) test('bcodeDaily', () => { const ticker = '2371' diff --git a/src/custom-functions/v3/bcode-daily.ts b/src/custom-functions/v3/bcode-daily.ts index e42b502..8859374 100644 --- a/src/custom-functions/v3/bcode-daily.ts +++ b/src/custom-functions/v3/bcode-daily.ts @@ -39,9 +39,7 @@ export function bcodeDaily( const property = daily.columnDescription[propertyName] if (property == undefined) { - throw new PropertyNotFoundError( - `propetyName '${propertyName}' is not found.` - ) + throw new PropertyNotFoundError(`propetyName '${propertyName}' is not found.`) } const value = daily.data[propertyName] diff --git a/src/custom-functions/v3/bcode-quarter.test.ts b/src/custom-functions/v3/bcode-quarter.test.ts index b01d2d4..56f8b6a 100644 --- a/src/custom-functions/v3/bcode-quarter.test.ts +++ b/src/custom-functions/v3/bcode-quarter.test.ts @@ -5,15 +5,9 @@ import { YearQuarter } from '~/fiscal-periods/year-quarter' import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' import { QuarterCache } from '~/services/quarter-cache' -jest.mock('~/api/v3/client', () => - jest.requireActual('~/__mocks__/api/v3/client') -) -jest.mock('~/services/company-cache', () => - jest.requireActual('~/__mocks__/services/company-cache') -) -jest.mock('~/services/quarter-cache', () => - jest.requireActual('~/__mocks__/services/quarter-cache') -) +jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) +jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) +jest.mock('~/services/quarter-cache', () => jest.requireActual('~/__mocks__/services/quarter-cache')) test('bcodeQuarter', () => { const ticker = '2371' @@ -23,13 +17,7 @@ test('bcodeQuarter', () => { expect(QuarterCache.get(ticker, period)).toBeNull() const client = new CachingBuffettCodeApiClientV3('token') - const result = bcodeQuarter( - client, - ticker, - YearQuarterParam.fromYearQuarter(period), - propertyName, - false - ) + const result = bcodeQuarter(client, ticker, YearQuarterParam.fromYearQuarter(period), propertyName, false) expect(result).toEqual(new BcodeResult(propertyName, 12513000000, '円')) expect(QuarterCache.get(ticker, period)).not.toBeNull() diff --git a/src/custom-functions/v3/bcode-quarter.ts b/src/custom-functions/v3/bcode-quarter.ts index eba4eb8..1f92dec 100644 --- a/src/custom-functions/v3/bcode-quarter.ts +++ b/src/custom-functions/v3/bcode-quarter.ts @@ -39,9 +39,7 @@ export function bcodeQuarter( const property = quarter.columnDescription[propertyName] if (property == undefined) { - throw new PropertyNotFoundError( - `propetyName '${propertyName}' is not found.` - ) + throw new PropertyNotFoundError(`propetyName '${propertyName}' is not found.`) } const value = quarter.data[propertyName] diff --git a/src/custom-functions/v3/bcode-result.test.ts b/src/custom-functions/v3/bcode-result.test.ts index 1a62991..e844dea 100644 --- a/src/custom-functions/v3/bcode-result.test.ts +++ b/src/custom-functions/v3/bcode-result.test.ts @@ -1,49 +1,25 @@ import { BcodeResult } from '~/custom-functions/v3/bcode-result' test('format (days)', () => { - expect(new BcodeResult('ccc', 1234.5678, '日').format(false, false)).toBe( - 1234.6 - ) - expect(new BcodeResult('ccc', 1234.5678, '日').format(true, false)).toBe( - 1234.5678 - ) - expect(new BcodeResult('ccc', 1234.5678, '日').format(false, true)).toBe( - '1,234.6日' - ) - expect(new BcodeResult('ccc', 1234.5678, '日').format(true, true)).toBe( - '1,234.5678日' - ) + expect(new BcodeResult('ccc', 1234.5678, '日').format(false, false)).toBe(1234.6) + expect(new BcodeResult('ccc', 1234.5678, '日').format(true, false)).toBe(1234.5678) + expect(new BcodeResult('ccc', 1234.5678, '日').format(false, true)).toBe('1,234.6日') + expect(new BcodeResult('ccc', 1234.5678, '日').format(true, true)).toBe('1,234.5678日') }) test('format (yen)', () => { - 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('', 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円') }) test('format (million-yen)', () => { // using unit-mapping.json - expect( - new BcodeResult('market_capital', 550294097166, '円').format(false, false) - ).toBe(550294) - expect( - new BcodeResult('market_capital', 550294097166, '円').format(true, false) - ).toBe(550294097166) - expect( - new BcodeResult('market_capital', 550294097166, '円').format(false, true) - ).toBe('550,294百万円') - expect( - new BcodeResult('market_capital', 550294097166, '円').format(true, true) - ).toBe('550,294,097,166円') + expect(new BcodeResult('market_capital', 550294097166, '円').format(false, false)).toBe(550294) + expect(new BcodeResult('market_capital', 550294097166, '円').format(true, false)).toBe(550294097166) + expect(new BcodeResult('market_capital', 550294097166, '円').format(false, true)).toBe('550,294百万円') + expect(new BcodeResult('market_capital', 550294097166, '円').format(true, true)).toBe('550,294,097,166円') }) test('format (null)', () => { @@ -61,10 +37,6 @@ test('format (object)', () => { expect(result.format(false, false)).toEqual(JSON.stringify(segmentMember)) expect(result.format(true, false)).toEqual(JSON.stringify(segmentMember)) - expect(result.format(false, true)).toEqual( - JSON.stringify(segmentMember) + 'なし' - ) - expect(result.format(true, true)).toEqual( - JSON.stringify(segmentMember) + 'なし' - ) + expect(result.format(false, true)).toEqual(JSON.stringify(segmentMember) + 'なし') + expect(result.format(true, true)).toEqual(JSON.stringify(segmentMember) + 'なし') }) diff --git a/src/custom-functions/v3/bcode-result.ts b/src/custom-functions/v3/bcode-result.ts index a958cf7..5861649 100644 --- a/src/custom-functions/v3/bcode-result.ts +++ b/src/custom-functions/v3/bcode-result.ts @@ -2,11 +2,7 @@ import * as unitConversion from '~/custom-functions/v3/unit-conversion.js' import { Formatter } from '~/services/formatter' export class BcodeResult { - constructor( - public name: string, - public value: number | string | object | null, - public unit: string - ) {} + constructor(public name: string, public value: number | string | object | null, public unit: string) {} private isMillionYenProperty(): boolean { return unitConversion.millionYen.includes(this.name) diff --git a/src/custom-functions/v3/bcode.ts b/src/custom-functions/v3/bcode.ts index 0f635fe..b9acc96 100644 --- a/src/custom-functions/v3/bcode.ts +++ b/src/custom-functions/v3/bcode.ts @@ -1,19 +1,11 @@ import { HttpError } from '~/api/http-error' import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' -import { - ApiResponseError, - OndemandApiNotEnabledError, - UnsupportedTickerError -} from '~/custom-functions/error' +import { ApiResponseError, OndemandApiNotEnabledError, UnsupportedTickerError } from '~/custom-functions/error' import { bcodeDaily } from '~/custom-functions/v3/bcode-daily' import { bcodeQuarter } from '~/custom-functions/v3/bcode-quarter' import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { DateParam } from '~/fiscal-periods/date-param' -import { - InvalidLYLQError, - InvalidYearError, - InvalidQuarterError -} from '~/fiscal-periods/error' +import { InvalidLYLQError, InvalidYearError, InvalidQuarterError } from '~/fiscal-periods/error' import { PeriodParser } from '~/fiscal-periods/period-parser' import { Setting } from '~/setting' @@ -39,9 +31,7 @@ function handleError(e): void { throw new Error(`<<無効なリクエストです。${e.name}: ${e.message}>>`) } else { console.error('システムエラー', e.name, e.message) - throw new Error( - `<<システムエラーが発生しました。${e.name}: ${e.message}>>` - ) + throw new Error(`<<システムエラーが発生しました。${e.name}: ${e.message}>>`) } } else if (e instanceof InvalidLYLQError) { throw new Error('<<無効なLY・LQが指定されています>>') @@ -88,21 +78,9 @@ export function bcode( const parsedPeriod = PeriodParser.parse(period) let result: BcodeResult if (parsedPeriod instanceof DateParam) { - result = bcodeDaily( - client, - ticker, - parsedPeriod, - propertyName, - setting.ondemandApiEnabled - ) + result = bcodeDaily(client, ticker, parsedPeriod, propertyName, setting.ondemandApiEnabled) } else { - result = bcodeQuarter( - client, - ticker, - parsedPeriod, - propertyName, - setting.ondemandApiEnabled - ) + result = bcodeQuarter(client, ticker, parsedPeriod, propertyName, setting.ondemandApiEnabled) } return result.format(isRawValue, isWithUnits) diff --git a/src/entities/v3/daily.test.ts b/src/entities/v3/daily.test.ts index 1f9d1c3..b9607f8 100644 --- a/src/entities/v3/daily.test.ts +++ b/src/entities/v3/daily.test.ts @@ -8,9 +8,7 @@ test('period', () => { }) test('propertyNames', () => { - expect(daily.propertyNames()).toEqual( - Object.keys(response['column_description']) - ) + expect(daily.propertyNames()).toEqual(Object.keys(response['column_description'])) }) test('labelOf', () => { diff --git a/src/entities/v3/quarter.test.ts b/src/entities/v3/quarter.test.ts index a806aea..8ec3c1c 100644 --- a/src/entities/v3/quarter.test.ts +++ b/src/entities/v3/quarter.test.ts @@ -9,9 +9,8 @@ test('period', () => { }) test('propertyNames', () => { - expect(quarter.propertyNames()).toEqual( - Object.keys(response['column_description']) - ) + expect(quarter.propertyNames()).toEqual(Object.keys(response['data'])) + expect(quarter.propertyNames()).not.toContain('desc_business') }) test('labelOf', () => { diff --git a/src/entities/v3/quarter.ts b/src/entities/v3/quarter.ts index f98031e..d746722 100644 --- a/src/entities/v3/quarter.ts +++ b/src/entities/v3/quarter.ts @@ -7,14 +7,11 @@ export class Quarter implements HasColumnDescription, HasPeriod { } period(): YearQuarter { - return new YearQuarter( - this.data['fiscal_year'], - this.data['fiscal_quarter'] - ) + return new YearQuarter(this.data['fiscal_year'], this.data['fiscal_quarter']) } propertyNames(): string[] { - return Object.keys(this.columnDescription) + return Object.keys(this.data) } labelOf(propertyName: string): string | null { diff --git a/src/fiscal-periods/date-param.test.ts b/src/fiscal-periods/date-param.test.ts index 2cd7f59..314e873 100644 --- a/src/fiscal-periods/date-param.test.ts +++ b/src/fiscal-periods/date-param.test.ts @@ -8,9 +8,7 @@ test('toString', () => { test('toDate', () => { expect(() => new DateParam('latest').toDate()).toThrow(Error) - expect(new DateParam(new Date('2020-09-06')).toDate()).toEqual( - new Date('2020-09-06') - ) + expect(new DateParam(new Date('2020-09-06')).toDate()).toEqual(new Date('2020-09-06')) }) test('isLatest', () => { @@ -19,9 +17,7 @@ test('isLatest', () => { }) test('parse', () => { - expect(DateParam.parse('2020-09-06')).toEqual( - new DateParam(new Date(2020, 9, 6)) - ) + expect(DateParam.parse('2020-09-06')).toEqual(new DateParam(new Date('2020-09-06'))) expect(DateParam.parse('latest')).toEqual(new DateParam('latest')) expect(DateParam.parse('Latest')).toEqual(new DateParam('latest')) expect(() => DateParam.parse('foo')).toThrow(ParseError) diff --git a/src/fiscal-periods/date-param.ts b/src/fiscal-periods/date-param.ts index ac5f530..0ff0792 100644 --- a/src/fiscal-periods/date-param.ts +++ b/src/fiscal-periods/date-param.ts @@ -34,9 +34,6 @@ export class DateParam { throw new ParseError(`Invalid date format: ${str}`) } - const year = parseInt(matches[1], 10) - const month = parseInt(matches[2], 10) - const day = parseInt(matches[3], 10) - return new DateParam(new Date(year, month, day)) + return new DateParam(new Date(str)) } } diff --git a/src/fiscal-periods/date-range.test.ts b/src/fiscal-periods/date-range.test.ts index 591a361..3da179d 100644 --- a/src/fiscal-periods/date-range.test.ts +++ b/src/fiscal-periods/date-range.test.ts @@ -1,19 +1,9 @@ import { DateRange } from '~/fiscal-periods/date-range' test('diff', () => { - expect( - new DateRange(new Date(2020, 9, 6), new Date(2021, 9, 6)).diff() - ).toEqual(365) - expect( - new DateRange(new Date(2020, 9, 6), new Date(2020, 9, 7)).diff() - ).toEqual(1) - expect( - new DateRange(new Date(2020, 9, 6), new Date(2020, 9, 6)).diff() - ).toEqual(0) - expect( - new DateRange(new Date(2020, 9, 6), new Date(2020, 9, 5)).diff() - ).toEqual(-1) - expect( - new DateRange(new Date(2020, 9, 6), new Date(2019, 9, 6)).diff() - ).toEqual(-366) + expect(new DateRange(new Date('2020-09-06'), new Date('2021-09-06')).diff()).toEqual(365) + expect(new DateRange(new Date('2020-09-06'), new Date('2020-09-07')).diff()).toEqual(1) + expect(new DateRange(new Date('2020-09-06'), new Date('2020-09-06')).diff()).toEqual(0) + expect(new DateRange(new Date('2020-09-06'), new Date('2020-09-05')).diff()).toEqual(-1) + expect(new DateRange(new Date('2020-09-06'), new Date('2019-09-06')).diff()).toEqual(-366) }) diff --git a/src/fiscal-periods/date-range.ts b/src/fiscal-periods/date-range.ts index b0ecbae..ab1b58f 100644 --- a/src/fiscal-periods/date-range.ts +++ b/src/fiscal-periods/date-range.ts @@ -4,8 +4,6 @@ export class DateRange { } diff(): number { - return Math.round( - (this.to.getTime() - this.from.getTime()) / (1000 * 60 * 60 * 24) - ) + return Math.round((this.to.getTime() - this.from.getTime()) / (1000 * 60 * 60 * 24)) } } diff --git a/src/fiscal-periods/lq-with-offset.ts b/src/fiscal-periods/lq-with-offset.ts index fd1c612..876fb39 100644 --- a/src/fiscal-periods/lq-with-offset.ts +++ b/src/fiscal-periods/lq-with-offset.ts @@ -5,9 +5,7 @@ export class LqWithOffset { constructor(public offset: number = 0) { if (offset > 0) { - throw new InvalidLYLQError( - `LQ offset must be negative but ${offset} given.` - ) + throw new InvalidLYLQError(`LQ offset must be negative but ${offset} given.`) } } diff --git a/src/fiscal-periods/ly-with-offset.ts b/src/fiscal-periods/ly-with-offset.ts index d3979b4..e2f0eea 100644 --- a/src/fiscal-periods/ly-with-offset.ts +++ b/src/fiscal-periods/ly-with-offset.ts @@ -5,9 +5,7 @@ export class LyWithOffset { constructor(public offset: number = 0) { if (offset > 0) { - throw new InvalidLYLQError( - `LY offset must be negative but ${offset} given.` - ) + throw new InvalidLYLQError(`LY offset must be negative but ${offset} given.`) } } diff --git a/src/fiscal-periods/period-parser.test.ts b/src/fiscal-periods/period-parser.test.ts index 412828e..b784018 100644 --- a/src/fiscal-periods/period-parser.test.ts +++ b/src/fiscal-periods/period-parser.test.ts @@ -13,18 +13,10 @@ test('parse', () => { expect(PeriodParser.parse('2020LQ')).toEqual(new YearQuarterParam(2020, LQ)) expect(PeriodParser.parse('LYQ3')).toEqual(new YearQuarterParam(LY, 3)) expect(PeriodParser.parse('LYLQ')).toEqual(new YearQuarterParam(LY, LQ)) - expect(PeriodParser.parse('LY-1Q4')).toEqual( - new YearQuarterParam(new LyWithOffset(-1), 4) - ) - expect(PeriodParser.parse('2020LQ-1')).toEqual( - new YearQuarterParam(2020, new LqWithOffset(-1)) - ) - expect(PeriodParser.parse('LY-1LQ-1')).toEqual( - new YearQuarterParam(new LyWithOffset(-1), new LqWithOffset(-1)) - ) - expect(PeriodParser.parse('2020-09-06')).toEqual( - new DateParam(new Date(2020, 9, 6)) - ) + expect(PeriodParser.parse('LY-1Q4')).toEqual(new YearQuarterParam(new LyWithOffset(-1), 4)) + expect(PeriodParser.parse('2020LQ-1')).toEqual(new YearQuarterParam(2020, new LqWithOffset(-1))) + expect(PeriodParser.parse('LY-1LQ-1')).toEqual(new YearQuarterParam(new LyWithOffset(-1), new LqWithOffset(-1))) + expect(PeriodParser.parse('2020-09-06')).toEqual(new DateParam(new Date('2020-09-06'))) expect(() => PeriodParser.parse('foo')).toThrow(ParseError) expect(() => PeriodParser.parse('2020/09/06')).toThrow(ParseError) expect(() => PeriodParser.parse('latest')).toThrow(ParseError) diff --git a/src/fiscal-periods/year-quarter-param.test.ts b/src/fiscal-periods/year-quarter-param.test.ts index a1268ec..a36a34e 100644 --- a/src/fiscal-periods/year-quarter-param.test.ts +++ b/src/fiscal-periods/year-quarter-param.test.ts @@ -1,8 +1,4 @@ -import { - InvalidYearError, - InvalidQuarterError, - ParseError -} from '~/fiscal-periods/error' +import { InvalidYearError, InvalidQuarterError, ParseError } from '~/fiscal-periods/error' import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' import { YearQuarter } from '~/fiscal-periods/year-quarter' @@ -38,9 +34,7 @@ test('toYearQuarter', () => { expect(() => new YearQuarterParam(LY, 3).toYearQuarter()).toThrow(Error) expect(() => new YearQuarterParam(2020, LQ).toYearQuarter()).toThrow(Error) expect(() => new YearQuarterParam(LY, LQ).toYearQuarter()).toThrow(Error) - expect(new YearQuarterParam(2020, 3).toYearQuarter()).toEqual( - new YearQuarter(2020, 3) - ) + expect(new YearQuarterParam(2020, 3).toYearQuarter()).toEqual(new YearQuarter(2020, 3)) }) test('isLatestYear', () => { @@ -54,21 +48,13 @@ test('isLatestQuarter', () => { }) test('fromYearQuarter', () => { - expect(YearQuarterParam.fromYearQuarter(new YearQuarter(2018, 1))).toEqual( - new YearQuarterParam(2018, 1) - ) + expect(YearQuarterParam.fromYearQuarter(new YearQuarter(2018, 1))).toEqual(new YearQuarterParam(2018, 1)) }) test('parse', () => { - expect(YearQuarterParam.parse('2020Q3')).toEqual( - new YearQuarterParam(2020, 3) - ) - expect(YearQuarterParam.parse('2020q3')).toEqual( - new YearQuarterParam(2020, 3) - ) - expect(YearQuarterParam.parse('2020LQ')).toEqual( - new YearQuarterParam(2020, LQ) - ) + expect(YearQuarterParam.parse('2020Q3')).toEqual(new YearQuarterParam(2020, 3)) + expect(YearQuarterParam.parse('2020q3')).toEqual(new YearQuarterParam(2020, 3)) + expect(YearQuarterParam.parse('2020LQ')).toEqual(new YearQuarterParam(2020, LQ)) expect(YearQuarterParam.parse('LYQ3')).toEqual(new YearQuarterParam(LY, 3)) expect(YearQuarterParam.parse('LYLQ')).toEqual(new YearQuarterParam(LY, LQ)) expect(YearQuarterParam.parse('lylq')).toEqual(new YearQuarterParam(LY, LQ)) diff --git a/src/fiscal-periods/year-quarter-param.ts b/src/fiscal-periods/year-quarter-param.ts index f6f54a0..7ea85f7 100644 --- a/src/fiscal-periods/year-quarter-param.ts +++ b/src/fiscal-periods/year-quarter-param.ts @@ -1,17 +1,10 @@ -import { - InvalidYearError, - InvalidQuarterError, - ParseError -} from '~/fiscal-periods/error' +import { InvalidYearError, InvalidQuarterError, ParseError } from '~/fiscal-periods/error' import { LqWithOffset } from '~/fiscal-periods/lq-with-offset' import { LyWithOffset } from '~/fiscal-periods/ly-with-offset' import { YearQuarter } from '~/fiscal-periods/year-quarter' export class YearQuarterParam { - constructor( - public year: number | LyWithOffset, - public quarter: number | LqWithOffset - ) { + constructor(public year: number | LyWithOffset, public quarter: number | LqWithOffset) { if (typeof year === 'number' && year < 1) { throw new InvalidYearError(`Invalid year value: ${year}`) } @@ -26,10 +19,7 @@ export class YearQuarterParam { } public toYearQuarter(): YearQuarter { - if ( - this.year instanceof LyWithOffset || - this.quarter instanceof LqWithOffset - ) { + if (this.year instanceof LyWithOffset || this.quarter instanceof LqWithOffset) { throw new Error('This cannot convert to YearQuarter') } else { return new YearQuarter(this.year, this.quarter) @@ -51,14 +41,9 @@ export class YearQuarterParam { throw new ParseError(`Invalid year-quarter format: ${str}`) } - const year = - matches[1].substring(0, 2) === 'LY' - ? LyWithOffset.parse(matches[1]) - : parseInt(matches[1], 10) + const year = matches[1].substring(0, 2) === 'LY' ? LyWithOffset.parse(matches[1]) : parseInt(matches[1], 10) const quarter = - matches[3].substring(0, 2) === 'LQ' - ? LqWithOffset.parse(matches[3]) - : parseInt(matches[3].substring(1), 10) + matches[3].substring(0, 2) === 'LQ' ? LqWithOffset.parse(matches[3]) : parseInt(matches[3].substring(1), 10) return new YearQuarterParam(year, quarter) } diff --git a/src/fiscal-periods/year-quarter-range.test.ts b/src/fiscal-periods/year-quarter-range.test.ts index 7cdb7bf..a7db677 100644 --- a/src/fiscal-periods/year-quarter-range.test.ts +++ b/src/fiscal-periods/year-quarter-range.test.ts @@ -2,72 +2,27 @@ import { YearQuarter } from '~/fiscal-periods/year-quarter' import { YearQuarterRange } from '~/fiscal-periods/year-quarter-range' test('diff', () => { - expect( - new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2018, 1) - ).diff() - ).toBe(0) + expect(new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2018, 1)).diff()).toBe(0) - expect( - new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2018, 2) - ).diff() - ).toBe(1) - expect( - new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2019, 2) - ).diff() - ).toBe(5) - expect( - new YearQuarterRange( - new YearQuarter(2016, 3), - new YearQuarter(2019, 2) - ).diff() - ).toBe(11) + expect(new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2018, 2)).diff()).toBe(1) + expect(new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2019, 2)).diff()).toBe(5) + expect(new YearQuarterRange(new YearQuarter(2016, 3), new YearQuarter(2019, 2)).diff()).toBe(11) - expect( - new YearQuarterRange( - new YearQuarter(2018, 2), - new YearQuarter(2018, 1) - ).diff() - ).toBe(-1) - expect( - new YearQuarterRange( - new YearQuarter(2019, 2), - new YearQuarter(2018, 1) - ).diff() - ).toBe(-5) - expect( - new YearQuarterRange( - new YearQuarter(2019, 2), - new YearQuarter(2016, 3) - ).diff() - ).toBe(-11) + expect(new YearQuarterRange(new YearQuarter(2018, 2), new YearQuarter(2018, 1)).diff()).toBe(-1) + expect(new YearQuarterRange(new YearQuarter(2019, 2), new YearQuarter(2018, 1)).diff()).toBe(-5) + expect(new YearQuarterRange(new YearQuarter(2019, 2), new YearQuarter(2016, 3)).diff()).toBe(-11) }) test('range', () => { - expect( - new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2018, 1) - ).range() - ).toEqual([new YearQuarter(2018, 1)]) + expect(new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2018, 1)).range()).toEqual([ + new YearQuarter(2018, 1) + ]) - expect( - new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2018, 2) - ).range() - ).toEqual([new YearQuarter(2018, 1), new YearQuarter(2018, 2)]) - expect( - new YearQuarterRange( - new YearQuarter(2018, 1), - new YearQuarter(2019, 2) - ).range() - ).toEqual([ + expect(new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2018, 2)).range()).toEqual([ + new YearQuarter(2018, 1), + new YearQuarter(2018, 2) + ]) + expect(new YearQuarterRange(new YearQuarter(2018, 1), new YearQuarter(2019, 2)).range()).toEqual([ new YearQuarter(2018, 1), new YearQuarter(2018, 2), new YearQuarter(2018, 3), @@ -75,12 +30,7 @@ test('range', () => { new YearQuarter(2019, 1), new YearQuarter(2019, 2) ]) - expect( - new YearQuarterRange( - new YearQuarter(2016, 3), - new YearQuarter(2019, 2) - ).range() - ).toEqual([ + expect(new YearQuarterRange(new YearQuarter(2016, 3), new YearQuarter(2019, 2)).range()).toEqual([ new YearQuarter(2016, 3), new YearQuarter(2016, 4), new YearQuarter(2017, 1), @@ -95,18 +45,11 @@ test('range', () => { new YearQuarter(2019, 2) ]) - expect( - new YearQuarterRange( - new YearQuarter(2018, 2), - new YearQuarter(2018, 1) - ).range() - ).toEqual([new YearQuarter(2018, 2), new YearQuarter(2018, 1)]) - expect( - new YearQuarterRange( - new YearQuarter(2019, 2), - new YearQuarter(2018, 1) - ).range() - ).toEqual([ + expect(new YearQuarterRange(new YearQuarter(2018, 2), new YearQuarter(2018, 1)).range()).toEqual([ + new YearQuarter(2018, 2), + new YearQuarter(2018, 1) + ]) + expect(new YearQuarterRange(new YearQuarter(2019, 2), new YearQuarter(2018, 1)).range()).toEqual([ new YearQuarter(2019, 2), new YearQuarter(2019, 1), new YearQuarter(2018, 4), @@ -114,12 +57,7 @@ test('range', () => { new YearQuarter(2018, 2), new YearQuarter(2018, 1) ]) - expect( - new YearQuarterRange( - new YearQuarter(2019, 2), - new YearQuarter(2016, 3) - ).range() - ).toEqual([ + expect(new YearQuarterRange(new YearQuarter(2019, 2), new YearQuarter(2016, 3)).range()).toEqual([ new YearQuarter(2019, 2), new YearQuarter(2019, 1), new YearQuarter(2018, 4), diff --git a/src/fiscal-periods/year-quarter-range.ts b/src/fiscal-periods/year-quarter-range.ts index 36666b9..c33805f 100644 --- a/src/fiscal-periods/year-quarter-range.ts +++ b/src/fiscal-periods/year-quarter-range.ts @@ -6,10 +6,7 @@ export class YearQuarterRange { } diff(): number { - return ( - (this.to.year - this.from.year) * 4 + - (this.to.quarter - this.from.quarter) - ) + return (this.to.year - this.from.year) * 4 + (this.to.quarter - this.from.quarter) } range(): YearQuarter[] { diff --git a/src/services/company-cache.ts b/src/services/company-cache.ts index 3b8f1c1..9f8f8d3 100644 --- a/src/services/company-cache.ts +++ b/src/services/company-cache.ts @@ -19,11 +19,7 @@ export class CompanyCache { return JSON.parse(cached) } - static put( - ticker: string, - company: object, - expirationInSeconds = 21600 - ): void { + static put(ticker: string, company: object, expirationInSeconds = 21600): void { const cache = CacheService.getUserCache() cache.put(this.key(ticker), JSON.stringify(company), expirationInSeconds) } diff --git a/src/services/csv-exporter.test.ts b/src/services/csv-exporter.test.ts index 2f26731..d0325b6 100644 --- a/src/services/csv-exporter.test.ts +++ b/src/services/csv-exporter.test.ts @@ -4,25 +4,27 @@ import { CsvExporter } from '~/services/csv-exporter' 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') -) +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')) -const columnDescription = quarter['column_description'] -const propertyNames = Object.keys(columnDescription) +const propertyNames = Object.keys(quarter['data']) const fiscalYearIndex = propertyNames.indexOf('fiscal_year') const fiscalQuarterIndex = propertyNames.indexOf('fiscal_quarter') const segmentMemberIndex = propertyNames.indexOf('segment_member') +test('format', () => { + expect(CsvExporter.format(null)).toEqual('') + expect(CsvExporter.format('')).toEqual('') + expect(CsvExporter.format('foo')).toEqual('foo') + expect(CsvExporter.format(0)).toBe(0) + expect(CsvExporter.format(123456789)).toBe(123456789) + expect(CsvExporter.format(0.0)).toBe(0.0) + expect(CsvExporter.format(123456789.0)).toBe(123456789.0) + expect(CsvExporter.format({ foo: 'bar' })).toBe('{"foo":"bar"}') +}) + describe('generateData', () => { test('uncached', () => { const ticker = '2371' @@ -36,27 +38,15 @@ describe('generateData', () => { expect(data.length).toBe(propertyNames.length + 1) expect(data[0].length).toBe(3 + 1) expect(data[0]).toEqual(['キー', '項目名', '単位', from]) - expect(data[fiscalYearIndex + 1]).toEqual([ - 'fiscal_year', - '会計年度', - 'なし', - 2018.0 - ]) - expect(data[fiscalQuarterIndex + 1]).toEqual([ - 'fiscal_quarter', - '四半期', - 'なし', - 1.0 - ]) + expect(data[fiscalYearIndex + 1]).toEqual(['fiscal_year', '会計年度', 'なし', 2018.0]) + expect(data[fiscalQuarterIndex + 1]).toEqual(['fiscal_quarter', '四半期', 'なし', 1.0]) expect(data[segmentMemberIndex + 1]).toEqual([ 'segment_member', 'セグメント情報', 'なし', JSON.stringify(quarter['data']['segment_member']) ]) - expect( - QuarterCache.getData(ticker, new YearQuarter(2018, 1))['net_sales'] - ).toBe(12513000000.0) + expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))['net_sales']).toBe(12513000000.0) }) test('cached', () => { @@ -64,35 +54,21 @@ describe('generateData', () => { const from = '2018Q1' const to = '2018Q1' const today = new Date('2020-09-23') - expect( - QuarterCache.getData(ticker, new YearQuarter(2018, 1)) - ).not.toBeNull() + expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))).not.toBeNull() const data = CsvExporter.generateData(ticker, from, to, today) expect(data.length).toBe(propertyNames.length + 1) expect(data[0].length).toBe(3 + 1) expect(data[0]).toEqual(['キー', '項目名', '単位', from]) - expect(data[fiscalYearIndex + 1]).toEqual([ - 'fiscal_year', - '会計年度', - 'なし', - 2018.0 - ]) - expect(data[fiscalQuarterIndex + 1]).toEqual([ - 'fiscal_quarter', - '四半期', - 'なし', - 1.0 - ]) + expect(data[fiscalYearIndex + 1]).toEqual(['fiscal_year', '会計年度', 'なし', 2018.0]) + expect(data[fiscalQuarterIndex + 1]).toEqual(['fiscal_quarter', '四半期', 'なし', 1.0]) expect(data[segmentMemberIndex + 1]).toEqual([ 'segment_member', 'セグメント情報', 'なし', JSON.stringify(quarter['data']['segment_member']) ]) - expect( - QuarterCache.getData(ticker, new YearQuarter(2018, 1))['net_sales'] - ).toBe(12513000000.0) + expect(QuarterCache.getData(ticker, new YearQuarter(2018, 1))['net_sales']).toBe(12513000000.0) }) }) diff --git a/src/services/csv-exporter.ts b/src/services/csv-exporter.ts index b5d34c0..3f7d44c 100644 --- a/src/services/csv-exporter.ts +++ b/src/services/csv-exporter.ts @@ -11,22 +11,17 @@ export class CsvExporter { // } - static format( - value: number | string | object | null - ): number | string | null { - if (typeof value == 'object') { + static format(value: number | string | object | null): number | string { + if (value == undefined) { + value = '' + } else if (typeof value === 'object') { value = JSON.stringify(value) } return value } - static generateData( - ticker, - from: string, - to: string, - today: Date = new Date() - ): object[][] { + static generateData(ticker, from: string, to: string, today: Date = new Date()): object[][] { const fromYearQuarter = YearQuarter.parse(from) const toYearQuarter = YearQuarter.parse(to) const range = new YearQuarterRange(fromYearQuarter, toYearQuarter) @@ -38,18 +33,10 @@ export class CsvExporter { throw new Error('<<サポートされていないtickerです>>') } - const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange( - companyService - ) + const ondemandQuarterApiPeriodRange = new OndemandApiPeriodRange(companyService) - const ondemandQuarterApiPeriods = ondemandQuarterApiPeriodRange.selectOndemandQuarterApiPeriod( - ticker, - range - ) - const quarterApiPeriods = ondemandQuarterApiPeriodRange.filterOndemandQuarterApiPeriod( - ticker, - range - ) + const ondemandQuarterApiPeriods = ondemandQuarterApiPeriodRange.selectOndemandQuarterApiPeriod(ticker, range) + const quarterApiPeriods = ondemandQuarterApiPeriodRange.filterOndemandQuarterApiPeriod(ticker, range) if (ondemandQuarterApiPeriods.length > 0 && !setting.ondemandApiEnabled) { throw new Error( @@ -59,14 +46,10 @@ export class CsvExporter { const quarters = [] quarterApiPeriods.forEach(period => { - quarters.push( - client.quarter(ticker, YearQuarterParam.fromYearQuarter(period)) - ) + quarters.push(client.quarter(ticker, YearQuarterParam.fromYearQuarter(period))) }) ondemandQuarterApiPeriods.forEach(period => { - quarters.push( - client.ondemandQuarter(ticker, YearQuarterParam.fromYearQuarter(period)) - ) + quarters.push(client.ondemandQuarter(ticker, YearQuarterParam.fromYearQuarter(period))) }) if (!quarters.length) { @@ -86,14 +69,10 @@ export class CsvExporter { }) const quarter = quarters[0] - const quarterLabels = sortedQuarters.map(quarter => - quarter.period().toString() - ) + const quarterLabels = sortedQuarters.map(quarter => quarter.period().toString()) const header = [['キー', '項目名', '単位', ...quarterLabels]] const values = quarter.propertyNames().map(name => { - const data = sortedQuarters.map(quarter => - this.format(quarter.data[name]) - ) + const data = sortedQuarters.map(quarter => this.format(quarter.data[name])) return [name, quarter.labelOf(name), quarter.unitOf(name), ...data] }) diff --git a/src/services/daily-cache.test.ts b/src/services/daily-cache.test.ts index 4b0d8c6..57de350 100644 --- a/src/services/daily-cache.test.ts +++ b/src/services/daily-cache.test.ts @@ -7,15 +7,9 @@ test('key', () => { expect(DailyCache.key('6501', new DateParam('latest'))).toBe( `daily-6501-${new Date().toISOString().substring(0, 10)}` ) - expect(DailyCache.key('6501', new Date())).toBe( - `daily-6501-${new Date().toISOString().substring(0, 10)}` - ) - expect(DailyCache.key('6501', new DateParam(new Date('2020-09-06')))).toBe( - `daily-6501-2020-09-06` - ) - expect(DailyCache.key('6501', new Date('2020-09-06'))).toBe( - `daily-6501-2020-09-06` - ) + expect(DailyCache.key('6501', new Date())).toBe(`daily-6501-${new Date().toISOString().substring(0, 10)}`) + expect(DailyCache.key('6501', new DateParam(new Date('2020-09-06')))).toBe(`daily-6501-2020-09-06`) + expect(DailyCache.key('6501', new Date('2020-09-06'))).toBe(`daily-6501-2020-09-06`) }) test('columnDescriptionKey', () => { @@ -39,13 +33,9 @@ test('getData', () => { }) test('getColumnDescription', () => { - getMock.mockReturnValueOnce( - JSON.stringify(dailyFixture['column_description']) - ) + getMock.mockReturnValueOnce(JSON.stringify(dailyFixture['column_description'])) - expect(DailyCache.getColumnDescription()).toEqual( - dailyFixture['column_description'] - ) + expect(DailyCache.getColumnDescription()).toEqual(dailyFixture['column_description']) expect(getMock).toBeCalledTimes(1) expect(getMock).toBeCalledWith('daily-column-description') @@ -55,20 +45,12 @@ test('putData', () => { DailyCache.putData('2371', dailyFixture['data']) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'daily-2371-2020-09-06', - JSON.stringify(dailyFixture['data']), - 21600 - ) + expect(putMock).toBeCalledWith('daily-2371-2020-09-06', JSON.stringify(dailyFixture['data']), 21600) }) test('putColumnDescription', () => { DailyCache.putColumnDescription(dailyFixture['column_description']) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'daily-column-description', - JSON.stringify(dailyFixture['column_description']), - 21600 - ) + expect(putMock).toBeCalledWith('daily-column-description', JSON.stringify(dailyFixture['column_description']), 21600) }) diff --git a/src/services/daily-cache.ts b/src/services/daily-cache.ts index 51660c3..ee40c45 100644 --- a/src/services/daily-cache.ts +++ b/src/services/daily-cache.ts @@ -53,27 +53,16 @@ export class DailyCache { return new Daily(cachedData, cachedColumnDescription) } - static putData( - ticker: string, - data: object, - expirationInSeconds = 21600 - ): void { + static putData(ticker: string, data: object, expirationInSeconds = 21600): void { const cache = CacheService.getUserCache() const date = new Date(data['day']) const key = this.key(ticker, date) cache.put(key, JSON.stringify(data), expirationInSeconds) } - static putColumnDescription( - columnDescription: object, - expirationInSeconds = 21600 - ): void { + static putColumnDescription(columnDescription: object, expirationInSeconds = 21600): void { const cache = CacheService.getUserCache() - cache.put( - this.columnDescriptionKey(), - JSON.stringify(columnDescription), - expirationInSeconds - ) + cache.put(this.columnDescriptionKey(), JSON.stringify(columnDescription), expirationInSeconds) } static put(ticker: string, daily: Daily, expirationInSeconds = 21600): void { diff --git a/src/services/indicator-cache.test.ts b/src/services/indicator-cache.test.ts index 4e81b89..9e67681 100644 --- a/src/services/indicator-cache.test.ts +++ b/src/services/indicator-cache.test.ts @@ -22,9 +22,5 @@ test('put', () => { IndicatorCache.put('2371', indicator) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'indicator-2371', - JSON.stringify(indicator), - 21600 - ) + expect(putMock).toBeCalledWith('indicator-2371', JSON.stringify(indicator), 21600) }) diff --git a/src/services/indicator-cache.ts b/src/services/indicator-cache.ts index 3b9a8cb..ab2dc54 100644 --- a/src/services/indicator-cache.ts +++ b/src/services/indicator-cache.ts @@ -20,11 +20,7 @@ export class IndicatorCache { return JSON.parse(cached) } - static put( - ticker: string, - indicator: object, - expirationInSeconds = 21600 - ): void { + 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 index 2cacbb0..d0ec00e 100644 --- a/src/services/indicator-property-cache.test.ts +++ b/src/services/indicator-property-cache.test.ts @@ -14,9 +14,5 @@ test('put', () => { IndicatorPropertyCache.put(indicatorProperty) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'indicator-property', - JSON.stringify(indicatorProperty), - 21600 - ) + 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 index aec8196..403df9a 100644 --- a/src/services/indicator-property-cache.ts +++ b/src/services/indicator-property-cache.ts @@ -17,10 +17,6 @@ export class IndicatorPropertyCache { static put(indicatorProperty: object, expirationInSeconds = 21600): void { const cache = CacheService.getUserCache() - cache.put( - IndicatorPropertyCache.key, - JSON.stringify(indicatorProperty), - expirationInSeconds - ) + 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 3b1c609..97e7e44 100644 --- a/src/services/quarter-cache.test.ts +++ b/src/services/quarter-cache.test.ts @@ -4,9 +4,7 @@ import { getMock, putMock } from '~/services/cache-test-helper' import { QuarterCache } from '~/services/quarter-cache' test('key', () => { - expect(QuarterCache.key('6501', new YearQuarter(2019, 4))).toBe( - 'quarter-6501-2019Q4' - ) + expect(QuarterCache.key('6501', new YearQuarter(2019, 4))).toBe('quarter-6501-2019Q4') }) const quarter = quarterFixture['2371'][0] @@ -39,20 +37,12 @@ test('putData', () => { QuarterCache.putData('2371', quarter) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'quarter-2371-2018Q1', - JSON.stringify(quarter), - 21600 - ) + expect(putMock).toBeCalledWith('quarter-2371-2018Q1', JSON.stringify(quarter), 21600) }) test('putColumnDescription', () => { QuarterCache.putColumnDescription(columnDescription) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'quarter-column-description', - JSON.stringify(columnDescription), - 21600 - ) + expect(putMock).toBeCalledWith('quarter-column-description', JSON.stringify(columnDescription), 21600) }) diff --git a/src/services/quarter-cache.ts b/src/services/quarter-cache.ts index 1166e8b..cc389f3 100644 --- a/src/services/quarter-cache.ts +++ b/src/services/quarter-cache.ts @@ -47,37 +47,19 @@ export class QuarterCache { return new Quarter(cachedData, cachedColumnDescription) } - static putData( - ticker: string, - quarter: object, - expirationInSeconds = 21600 - ): void { + static putData(ticker: string, quarter: object, expirationInSeconds = 21600): void { const cache = CacheService.getUserCache() - const yearQuarter = new YearQuarter( - quarter['fiscal_year'], - quarter['fiscal_quarter'] - ) + const yearQuarter = new YearQuarter(quarter['fiscal_year'], quarter['fiscal_quarter']) const key = this.key(ticker, yearQuarter) cache.put(key, JSON.stringify(quarter), expirationInSeconds) } - static putColumnDescription( - columnDescription: object, - expirationInSeconds = 21600 - ): void { + static putColumnDescription(columnDescription: object, expirationInSeconds = 21600): void { const cache = CacheService.getUserCache() - cache.put( - this.columnDescriptionKey(), - JSON.stringify(columnDescription), - expirationInSeconds - ) + cache.put(this.columnDescriptionKey(), JSON.stringify(columnDescription), expirationInSeconds) } - static put( - ticker: string, - quarter: Quarter, - expirationInSeconds = 21600 - ): void { + static put(ticker: string, quarter: Quarter, expirationInSeconds = 21600): void { this.putData(ticker, quarter.data, expirationInSeconds) this.putColumnDescription(quarter.columnDescription, expirationInSeconds) } diff --git a/src/services/quarter-property-cache.test.ts b/src/services/quarter-property-cache.test.ts index 3561a27..6c3ef98 100644 --- a/src/services/quarter-property-cache.test.ts +++ b/src/services/quarter-property-cache.test.ts @@ -14,9 +14,5 @@ test('put', () => { QuarterPropertyCache.put(quarterProperty) expect(putMock).toBeCalledTimes(1) - expect(putMock).toBeCalledWith( - 'quarter-property', - JSON.stringify(quarterProperty), - 21600 - ) + expect(putMock).toBeCalledWith('quarter-property', JSON.stringify(quarterProperty), 21600) }) diff --git a/src/setting.test.ts b/src/setting.test.ts index b538ac5..f80c815 100644 --- a/src/setting.test.ts +++ b/src/setting.test.ts @@ -57,10 +57,7 @@ test('save', () => { expect(mockSetProperty.mock.calls.length).toBe(2) expect(mockSetProperty.mock.calls[0]).toEqual([Setting.tokenProperty, 'bar']) - expect(mockSetProperty.mock.calls[1]).toEqual([ - Setting.ondemandApiEnabledProperty, - true - ]) + expect(mockSetProperty.mock.calls[1]).toEqual([Setting.ondemandApiEnabledProperty, true]) }) test('setDefaultToken', () => { diff --git a/src/setting.ts b/src/setting.ts index 10be1f0..4f438ac 100644 --- a/src/setting.ts +++ b/src/setting.ts @@ -40,17 +40,13 @@ export class Setting { public save(): void { const props = PropertiesService.getUserProperties() props.setProperty(Setting.tokenProperty, this._token) - props.setProperty( - Setting.ondemandApiEnabledProperty, - this._ondemandApiEnabled - ) + props.setProperty(Setting.ondemandApiEnabledProperty, this._ondemandApiEnabled) } public static load(): Setting { const props = PropertiesService.getUserProperties() const token = props.getProperty(this.tokenProperty) - const ondemandApiEnabled = - props.getProperty(this.ondemandApiEnabledProperty) == 'true' + const ondemandApiEnabled = props.getProperty(this.ondemandApiEnabledProperty) == 'true' const setting = new Setting(token, ondemandApiEnabled) return setting } diff --git a/src/ui/menu.ts b/src/ui/menu.ts index 8ac88a3..ec80957 100644 --- a/src/ui/menu.ts +++ b/src/ui/menu.ts @@ -24,9 +24,7 @@ export function recalculateCustomFunctionCells(): void { } export function showSettingSidebar(): void { - const html = HtmlService.createHtmlOutputFromFile('setting-sidebar').setTitle( - '設定' - ) + const html = HtmlService.createHtmlOutputFromFile('setting-sidebar').setTitle('設定') SpreadsheetApp.getUi().showSidebar(html) } diff --git a/src/version.ts b/src/version.ts index dd0c1e1..0625d38 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = 'v11' +export const version = 'v12'