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

test(api): api package test + few adjustments #518

Merged
merged 9 commits into from
Jul 20, 2022
Merged

Conversation

sogunshola
Copy link
Contributor


name: API package test

New Pull Request

Checklist

  • I am not disclosing a vulnerability.
  • My code is conform the code style
  • I have made corresponding changes to the documentation
  • I have updated Typescript definitions when needed

Issue Description

Related issue: #FILL_THIS_OUT

Solution Description

@changeset-bot
Copy link

changeset-bot bot commented Jul 20, 2022

🦋 Changeset detected

Latest commit: 3d68a63

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moralisweb3/api Major
@moralisweb3/evm-api Major
@moralisweb3/integration Major
@moralisweb3/core Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sogunshola sogunshola requested review from ErnoW and b4rtaz July 20, 2022 07:15
@@ -0,0 +1,27 @@
/* eslint-disable no-console */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this test should be in the packages/integration package.

}
}

const mockServer = setupServer(mockEndpointWeights, mockGetContractEvents);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not the best way how it could be tested. We already have integration tests, so I think we don't need a next integration test package. You can here mock responses by jest.spyOn(axios, 'request') instead using the msw server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good suggestion. on it

@sogunshola sogunshola requested a review from b4rtaz July 20, 2022 10:27
Comment on lines 110 to 111
const callSpy = jest.fn(async () => await resolver.next());
const result = await callSpy();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is unnecessary. jest.fn() should be used only in case, when you need to test some logic inside a testing class/function.

};
}[];

export class MockApi extends ApiModule {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not the best way to test ApiResolver. Tests should be small as possible. Here you want to test ApiResolver, but you have additionally config/modules etc. If you had an error in modules, you will get an error in ApiResolver tests. That is wrong.

I recommend move this test to packages/api/src/Resolver.test.ts, and test only ApiResolver without modules.

@sogunshola sogunshola requested a review from b4rtaz July 20, 2022 12:23
@sogunshola sogunshola merged commit 0194cb9 into alpha Jul 20, 2022
@sogunshola sogunshola deleted the test/api-package branch July 20, 2022 12:57
@github-actions github-actions bot mentioned this pull request Aug 10, 2022
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.

2 participants