This repository was archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Features/company #99
Merged
Merged
Features/company #99
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
842fa2e
update argument
t2h5 72899fd
add company entity
t2h5 e551dcf
update client
t2h5 14c5d90
add company intent
t2h5 6f9eca5
fix test
t2h5 56cb878
Update src/main.ts
t2h5 7270cca
fix v3 bcode
t2h5 020c0f8
fix test
t2h5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' | ||
| import { bcodeCompany } from '~/custom-functions/v3/bcode-company' | ||
| import { BcodeResult } from '~/custom-functions/v3/bcode-result' | ||
|
|
||
| jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client')) | ||
| jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache')) | ||
|
|
||
| test('bcodeCompany', () => { | ||
| const ticker = '2371' | ||
| const propertyName = 'company_name' | ||
|
|
||
| const client = new CachingBuffettCodeApiClientV3('token') | ||
| const result = bcodeCompany(client, ticker, propertyName) | ||
|
|
||
| expect(result).toEqual(new BcodeResult(propertyName, 'カカクコム', 'なし')) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { BuffettCodeApiClientV3 } from '~/api/v3/client' | ||
| import { PropertyNotFoundError } from '~/custom-functions/error' | ||
| import { BcodeResult } from '~/custom-functions/v3/bcode-result' | ||
|
|
||
| export function bcodeCompany(client: BuffettCodeApiClientV3, ticker: string, propertyName: string): BcodeResult { | ||
| const company = client.company(ticker) | ||
|
|
||
| const property = company.columnDescription[propertyName] | ||
| if (property == undefined) { | ||
| throw new PropertyNotFoundError(`propetyName '${propertyName}' is not found.`) | ||
| } | ||
|
|
||
| const value = company.data[propertyName] | ||
| const unit = company.unitOf(propertyName) | ||
|
|
||
| return new BcodeResult(propertyName, value, unit) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as response from '~/__mocks__/fixtures/v3/company' | ||
| import { Company } from '~/entities/v3/company' | ||
|
|
||
| const company = Company.fromResponse(response) | ||
|
|
||
| test('propertyName', () => { | ||
| expect(company.propertyNames()).toEqual(Object.keys(response['column_description'])) | ||
| }) | ||
|
|
||
| test('labelOf', () => { | ||
| expect(company.labelOf('company_name')).toEqual('会社名') | ||
| expect(company.labelOf('priority_market')).toEqual('優先市場') | ||
| }) | ||
|
|
||
| test('unitOf', () => { | ||
| expect(company.unitOf('company_name')).toEqual('なし') | ||
| expect(company.unitOf('priority_market')).toEqual('なし') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { HasColumnDescription } from '~/entities/v3/interface' | ||
|
|
||
| export class Company implements HasColumnDescription { | ||
| constructor(readonly data: object, readonly columnDescription: object) { | ||
| // noop | ||
| } | ||
|
|
||
| propertyNames(): string[] { | ||
| return Object.keys(this.data) | ||
| } | ||
|
|
||
| labelOf(propertyName: string): string | null { | ||
| const desc = this.columnDescriptionOf(propertyName) | ||
| if (desc) { | ||
| return desc['name_jp'] | ||
| } else { | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| unitOf(propertyName: string): string | null { | ||
| const desc = this.columnDescriptionOf(propertyName) | ||
| if (desc) { | ||
| return desc['unit'] | ||
| } else { | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| private columnDescriptionOf(propertyName: string): string | null { | ||
| return this.columnDescription[propertyName] | ||
| } | ||
|
|
||
| static fromResponse(response: object): Company { | ||
| return new Company(response['data'], response['column_description']) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,47 @@ | ||
| import * as companyFixture from '~/__mocks__/fixtures/v3/company' | ||
| import { Company } from '~/entities/v3/company' | ||
| import { getMock, putMock } from '~/services/cache-test-helper' | ||
| import { CompanyCache } from '~/services/company-cache' | ||
|
|
||
| const company = companyFixture['data'] | ||
| const company = Company.fromResponse(companyFixture) | ||
|
|
||
| test('key', () => { | ||
| expect(CompanyCache.key('2371')).toBe('company-2371') | ||
| }) | ||
|
|
||
| test('columnDescriptionKey', () => { | ||
| expect(CompanyCache.columnDescriptionKey()).toBe('company-column-description') | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('get', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. すみません、 大元は
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正してみました
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
| getMock.mockReturnValueOnce(JSON.stringify(company)) | ||
| expect(CompanyCache.get('2371')).toEqual(company) | ||
| expect(CompanyCache.get('2371')).toBeNull() | ||
| describe('get', () => { | ||
| test('returns data if cache exists', () => { | ||
| getMock.mockReturnValueOnce(JSON.stringify(company.data)) | ||
| getMock.mockReturnValueOnce(JSON.stringify(company.columnDescription)) | ||
| expect(CompanyCache.get('2371')).toEqual(company) | ||
|
|
||
| expect(getMock).toBeCalledTimes(2) | ||
| expect(getMock).nthCalledWith(1, 'company-2371') | ||
| expect(getMock).nthCalledWith(2, 'company-column-description') | ||
| }) | ||
|
|
||
| test('returns null if cache does not exist', () => { | ||
| getMock.mockReturnValue(null) | ||
| expect(CompanyCache.get('2371')).toBeNull() | ||
|
|
||
| expect(getMock).toBeCalledTimes(2) | ||
| expect(getMock).nthCalledWith(1, 'company-2371') | ||
| expect(getMock).nthCalledWith(2, 'company-2371') | ||
| expect(getMock).toBeCalledTimes(2) | ||
| expect(getMock).nthCalledWith(1, 'company-2371') | ||
| expect(getMock).nthCalledWith(2, 'company-column-description') | ||
| }) | ||
| }) | ||
|
|
||
| test('put', () => { | ||
| CompanyCache.put('2371', company) | ||
|
|
||
| expect(putMock).toBeCalledTimes(1) | ||
| expect(putMock).toBeCalledWith('company-2371', JSON.stringify(company), 21600) | ||
| expect(putMock).toBeCalledTimes(2) | ||
| expect(putMock).toBeCalledWith('company-2371', JSON.stringify(company.data), 21600) | ||
| expect(putMock).toBeCalledWith('company-column-description', JSON.stringify(company.columnDescription), 21600) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.