Skip to content

Commit

Permalink
Pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Sep 18, 2024
1 parent 5eeef57 commit 41a4609
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 51 deletions.
44 changes: 22 additions & 22 deletions packages/portfolio/src/adapters/dullahan-api/api-maker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: {},
},
})
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: {
['wrong']: [200, 'data'],
},
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('portfolioApiMaker', () => {
},
})

const resultTokenActivityUpdates = await api.tokenActivity(
const resultTokenActivity = await api.tokenActivity(
tokenActivityMocks.api.request,
Portfolio.Token.ActivityWindow.OneDay,
)
Expand All @@ -289,7 +289,7 @@ describe('portfolioApiMaker', () => {
},
})

expect(resultTokenActivityUpdates).toEqual({
expect(resultTokenActivity).toEqual({
tag: 'left',
error: {
status: -3,
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -352,7 +352,7 @@ describe('portfolioApiMaker', () => {
await expect(api.tokenInfos(mockTokenIdsWithCache)).resolves.toEqual({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -373,7 +373,7 @@ describe('portfolioApiMaker', () => {
).resolves.toEqual({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -396,7 +396,7 @@ describe('portfolioApiMaker', () => {
).resolves.toEqual({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -419,7 +419,7 @@ describe('portfolioApiMaker', () => {
).resolves.toEqual({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -445,7 +445,7 @@ describe('portfolioApiMaker', () => {
).resolves.toEqual({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -471,7 +471,7 @@ describe('portfolioApiMaker', () => {
).resolves.toEqual({
tag: 'left',
value: {
status: 500,
status: Api.HttpStatusCode.InternalServerError,
message: 'Internal Server Error',
responseData: {},
},
Expand All @@ -492,7 +492,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenMocks.nftCryptoKitty.traits,
},
})
Expand All @@ -519,7 +519,7 @@ describe('portfolioApiMaker', () => {
expect(result).toEqual({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenMocks.nftCryptoKitty.traits,
},
})
Expand All @@ -529,7 +529,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenMocks.nftCryptoKitty.info,
},
})
Expand All @@ -556,7 +556,7 @@ describe('portfolioApiMaker', () => {
expect(result).toEqual({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenMocks.nftCryptoKitty.info,
},
})
Expand Down Expand Up @@ -593,7 +593,7 @@ describe('portfolioApiMaker', () => {
expect(result).toEqual({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenActivityMocks.api.responseDataOnly,
},
})
Expand Down Expand Up @@ -628,7 +628,7 @@ describe('portfolioApiMaker', () => {
expect(result).toEqual({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenHistoryMocks.api.responseDataOnly,
},
})
Expand All @@ -638,7 +638,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: 0,
},
})
Expand Down Expand Up @@ -678,7 +678,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: {
...tokenDiscoveryMocks.nftCryptoKitty,
supply: undefined,
Expand Down Expand Up @@ -706,7 +706,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenDiscoveryMocks.nftCryptoKitty,
},
})
Expand All @@ -717,7 +717,7 @@ describe('portfolioApiMaker', () => {
expect(right).toEqual({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: tokenDiscoveryMocks.nftCryptoKitty,
},
})
Expand All @@ -727,7 +727,7 @@ describe('portfolioApiMaker', () => {
mockRequest.mockResolvedValue({
tag: 'right',
value: {
status: 200,
status: Api.HttpStatusCode.Ok,
data: {},
},
})
Expand Down
11 changes: 6 additions & 5 deletions packages/portfolio/src/adapters/dullahan-api/api-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
toDullahanRequest,
toProcessedMediaRequest,
toSecondaryTokenInfos,
toTokenActivityUpdates,
toTokenHistoryUpdates,
toTokenActivity,
toTokenHistory,
} from './transformers'
import {
DullahanApiCachedIdsRequest,
Expand Down Expand Up @@ -269,7 +269,7 @@ export const portfolioApiMaker = ({
return firstError

try {
const transformedResponseData = toTokenActivityUpdates(activities)
const transformedResponseData = toTokenActivity(activities)

const transformedResponse: Api.Response<Portfolio.Api.TokenActivityResponse> =
freeze(
Expand Down Expand Up @@ -311,8 +311,9 @@ export const portfolioApiMaker = ({
})

if (isRight(response)) {
const history: Portfolio.Token.History | undefined =
toTokenHistoryUpdates(response.value.data)
const history: Portfolio.Token.History | undefined = toTokenHistory(
response.value.data,
)

if (!history) {
return freeze(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const apiResponseSuccessDataOnly: Readonly<DullahanApiTokenActivityResponse> = {
[tokenInfoMocks.ftNameless.id]: [Api.HttpStatusCode.Ok, ftNameless],
}

export const duallahanTokenActivityUpdatesMocks = {
export const duallahanTokenActivityMocks = {
primaryETH,
rnftWhatever,
ftNoTicker,
Expand Down
22 changes: 11 additions & 11 deletions packages/portfolio/src/adapters/dullahan-api/transformers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
toDullahanRequest,
toProcessedMediaRequest,
toSecondaryTokenInfos,
toTokenActivityUpdates,
toTokenHistoryUpdates,
toTokenActivity,
toTokenHistory,
} from './transformers'
import {Portfolio, Api} from '@yoroi/types'

Expand All @@ -13,7 +13,7 @@ import {
DullahanApiTokenHistoryResponse,
} from './types'
import {tokenActivityMocks} from '../token-activity.mocks'
import {duallahanTokenActivityUpdatesMocks} from './token-activity.mocks'
import {duallahanTokenActivityMocks} from './token-activity.mocks'
import {tokenHistoryMocks} from '../token-history.mocks'

describe('transformers', () => {
Expand Down Expand Up @@ -112,36 +112,36 @@ describe('transformers', () => {
})
})

describe('toTokenActivityUpdates', () => {
it('should return an empty object if apiTokenActivityUpdates response is empty', () => {
describe('toTokenActivity', () => {
it('should return an empty object if apiTokenActivity response is empty', () => {
const apiTokenInfosResponse: DullahanApiTokenActivityResponse = {}

expect(toTokenActivityUpdates(apiTokenInfosResponse)).toEqual({})
expect(toTokenActivity(apiTokenInfosResponse)).toEqual({})
})

it('should return the data and deal with empty records', () => {
const responseWithEmptyRecords = {
...duallahanTokenActivityUpdatesMocks.api.responseSuccessDataOnly,
...duallahanTokenActivityMocks.api.responseSuccessDataOnly,
'token.4': undefined,
'token.5': [Api.HttpStatusCode.InternalServerError, 'Not found'],
} as any
const result = toTokenActivityUpdates(responseWithEmptyRecords)
const result = toTokenActivity(responseWithEmptyRecords)

expect(result).toEqual(tokenActivityMocks.api.responseDataOnly)
})
})

describe('toTokenHistoryUpdates', () => {
describe('toTokenHistory', () => {
it('should return undefined if apiTokenHistory response is malformed', () => {
expect(
toTokenHistoryUpdates({
toTokenHistory({
whatever: false,
} as unknown as DullahanApiTokenHistoryResponse),
).toEqual(undefined)
})

it('should return the data', () => {
const result = toTokenHistoryUpdates(
const result = toTokenHistory(
tokenHistoryMocks.ftNamelessRaw as unknown as DullahanApiTokenHistoryResponse,
)

Expand Down
12 changes: 5 additions & 7 deletions packages/portfolio/src/adapters/dullahan-api/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export const toSecondaryTokenInfos = (
)
}

export const toTokenActivityUpdates = (
export const toTokenActivity = (
apiTokenActivityResponse: Readonly<DullahanApiTokenActivityResponse>,
) => {
const tokenActivityUpdates: Record<
Portfolio.Token.Id,
Portfolio.Token.Activity
> = {}
const toTokenActivity: Record<Portfolio.Token.Id, Portfolio.Token.Activity> =

Check warning on line 56 in packages/portfolio/src/adapters/dullahan-api/transformers.ts

View workflow job for this annotation

GitHub Actions / check

'toTokenActivity' is already declared in the upper scope on line 53 column 14
{}

return freeze(
Object.entries(apiTokenActivityResponse).reduce(
Expand Down Expand Up @@ -84,13 +82,13 @@ export const toTokenActivityUpdates = (

return acc
},
tokenActivityUpdates,
toTokenActivity,
),
true,
)
}

export const toTokenHistoryUpdates = (
export const toTokenHistory = (
apiTokenHistoryResponse: Readonly<DullahanApiTokenHistoryResponse>,
) => {
if (!TokenHistoryResponseSchema.safeParse(apiTokenHistoryResponse).success)
Expand Down
8 changes: 3 additions & 5 deletions packages/portfolio/src/adapters/token-activity.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Api, Portfolio} from '@yoroi/types'
import {freeze} from 'immer'
import {BigNumber} from 'bignumber.js'
import {tokenInfoMocks} from './token-info.mocks'
import {duallahanTokenActivityUpdatesMocks} from './dullahan-api/token-activity.mocks'
import {duallahanTokenActivityMocks} from './dullahan-api/token-activity.mocks'

const primaryETH: Portfolio.Token.Activity = {
price: {
Expand Down Expand Up @@ -58,16 +58,14 @@ const apiResponseSuccessDataOnly = {
const apiResponseTokenActivity: Readonly<
Record<
'success' | 'error',
Api.Response<
typeof duallahanTokenActivityUpdatesMocks.api.responseSuccessDataOnly
>
Api.Response<typeof duallahanTokenActivityMocks.api.responseSuccessDataOnly>
>
> = {
success: {
tag: 'right',
value: {
status: 200,
data: duallahanTokenActivityUpdatesMocks.api.responseSuccessDataOnly,
data: duallahanTokenActivityMocks.api.responseSuccessDataOnly,
},
},
error: {
Expand Down

0 comments on commit 41a4609

Please sign in to comment.