Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine de Chevigné committed Feb 26, 2025
1 parent 8d73e5c commit fdfd2b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions run/tests/api/demo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ describe(`POST ${BASE_URL}/migrateExplorer`, () => {

describe(`POST ${BASE_URL}/explorers`, () => {
mockAxiosGet.mockResolvedValueOnce({ data: 'export default { "1": "ethereum" }' });
ProviderConnector.mockImplementationOnce(() => ({
fetchNetworkId: jest.fn().mockResolvedValueOnce(1)
}));

it('Should return an error if trying to create an explorer for a forbidden network id', (done) => {
ProviderConnector.mockImplementationOnce(() => ({
fetchNetworkId: jest.fn().mockResolvedValueOnce(1)
}));

request.post(`${BASE_URL}/explorers`)
.send({ name: 'demo', rpcServer: 'rpc.demo', nativeToken: 'token' })
.expect(400)
Expand Down Expand Up @@ -356,6 +357,9 @@ describe(`POST ${BASE_URL}/explorers`, () => {
jest.spyOn(db, 'getUserById').mockResolvedValueOnce({ id: 123 });
jest.spyOn(db, 'getStripePlan').mockResolvedValueOnce({ id: 1 });
jest.spyOn(db, 'createExplorerFromOptions').mockResolvedValueOnce(null);
ProviderConnector.mockImplementationOnce(() => ({
fetchNetworkId: jest.fn().mockResolvedValueOnce(1)
}));

request.post(`${BASE_URL}/explorers`)
.send({ name: 'demo', rpcServer: 'rpc.demo', nativeToken: 'token' })
Expand All @@ -369,6 +373,9 @@ describe(`POST ${BASE_URL}/explorers`, () => {
it('Should return an error if the plan is invalid', (done) => {
jest.spyOn(db, 'getUserById').mockResolvedValueOnce({ id: 123 });
jest.spyOn(db, 'getStripePlan').mockResolvedValueOnce(null);
ProviderConnector.mockImplementationOnce(() => ({
fetchNetworkId: jest.fn().mockResolvedValueOnce(1)
}));

request.post(`${BASE_URL}/explorers`)
.send({ name: 'demo', rpcServer: 'rpc.demo', nativeToken: 'token' })
Expand Down Expand Up @@ -402,7 +409,7 @@ describe(`POST ${BASE_URL}/explorers`, () => {
jest.spyOn(db, 'getStripePlan').mockResolvedValueOnce({ id: 1 });
jest.spyOn(db, 'createExplorerFromOptions').mockResolvedValueOnce({ id: 1, slug: 'slug' });
ProviderConnector.mockImplementationOnce(() => ({
fetchNetworkId: jest.fn().mockResolvedValueOnce(54321)
fetchNetworkId: jest.fn().mockResolvedValueOnce(31337)
}));

request.post(`${BASE_URL}/explorers`)
Expand All @@ -418,6 +425,9 @@ describe(`POST ${BASE_URL}/explorers`, () => {
jest.spyOn(db, 'getUserById').mockResolvedValueOnce({ id: 123 });
jest.spyOn(db, 'getStripePlan').mockResolvedValueOnce({ id: 1 });
jest.spyOn(db, 'createExplorerFromOptions').mockResolvedValueOnce({ id: 1, slug: 'slug' });
ProviderConnector.mockImplementationOnce(() => ({
fetchNetworkId: jest.fn().mockResolvedValueOnce(1)
}));
mockGetCount.mockResolvedValueOnce(0);

request.post(`${BASE_URL}/explorers`)
Expand Down
2 changes: 1 addition & 1 deletion run/tests/mocks/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ jest.mock('../../../lib/env', () => ({
maxBlockNumberDiff: jest.fn(() => 10),
getOpsgenieApiKey: jest.fn(() => 'a'),
getCounterNamespace: jest.fn(() => 'dev'),
whitelistedNetworkIdsForDemo: jest.fn(() => '31337,54321'),
whitelistedNetworkIdsForDemo: jest.fn(() => '31337,99999'),
maxDemoExplorersForNetwork: jest.fn(() => 3),
}));

0 comments on commit fdfd2b5

Please sign in to comment.