Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ZerionBalancesSchema tests #1637

Merged
merged 2 commits into from
Jun 11, 2024
Merged

Conversation

hectorgomezv
Copy link
Member

Changes

  • Adds ZerionBalances entity schema unit tests.
  • Changes nullable() by nullish().default(null) for several fields in the ZerionBalance schema, following the Zerion API documentation.

@hectorgomezv hectorgomezv self-assigned this Jun 11, 2024
@hectorgomezv hectorgomezv requested a review from a team as a code owner June 11, 2024 08:09
@@ -19,41 +19,41 @@ export type ZerionBalance = z.infer<typeof ZerionBalanceSchema>;

export type ZerionBalances = z.infer<typeof ZerionBalancesSchema>;

const ZerionImplementationSchema = z.object({
export const ZerionImplementationSchema = z.object({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schemas in this file are exported to test them on the ad hoc tests.

const fiatBalance = value ? getNumberString(value) : null;
const fiatConversion = getNumberString(zb.attributes.price);
const fiatConversion = price ? getNumberString(price) : null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attributes.price is not marked as required in the Zerion API docs, so I've changed this to reflect the possibility of the field being undefined.

@coveralls
Copy link

coveralls commented Jun 11, 2024

Pull Request Test Coverage Report for Build 9461883835

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.05%) to 92.759%

Files with Coverage Reduction New Missed Lines %
src/domain/safe/safe.repository.ts 1 99.05%
src/datasources/transaction-api/transaction-api.service.ts 1 99.53%
src/routes/transactions/entities/tests/human-description.builder.ts 1 80.0%
Totals Coverage Status
Change from base Build 9460927247: 0.05%
Covered Lines: 7128
Relevant Lines: 7388

💛 - Coveralls

it('should not allow an invalid type value', () => {
const zerionBalance = zerionBalanceBuilder().build();
// @ts-expect-error - type is expected to be a 'positions' literal
zerionBalance.type = 'invalid';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding an unknown literal here if it throws?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in efadc24

chain_id: z.string(),
address: z.string().nullable(),
address: z.string().nullish().default(null),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use AddressSchema here (and add a test for checksumming).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in efadc24

Comment on lines +83 to +84
// @ts-expect-error - id is expected to be a string
zerionBalance.id = faker.number.int();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was initially going to suggest we move this into the builder but this is a much more future-proof method of overwriting the values that we should consider doing elsewhere in schema tests - if the type changes to match that expected, TypeScript will complain. (If we casted it inside the with of a builder, it wouldn't.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes perfect sense to me! 👍🏻

@coveralls
Copy link

coveralls commented Jun 11, 2024

Pull Request Test Coverage Report for Build 9468416367

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 3 files are covered.
  • 5 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.07%) to 92.639%

Files with Coverage Reduction New Missed Lines %
src/domain/safe/safe.repository.ts 1 99.05%
src/datasources/transaction-api/transaction-api.service.ts 1 99.53%
src/routes/transactions/entities/tests/human-description.builder.ts 3 60.0%
Totals Coverage Status
Change from base Build 9460927247: -0.07%
Covered Lines: 7127
Relevant Lines: 7390

💛 - Coveralls

@hectorgomezv hectorgomezv merged commit af28c7f into main Jun 11, 2024
16 checks passed
@hectorgomezv hectorgomezv deleted the add-zerion-balances-schema-tests branch June 11, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants