Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Mar 13, 2024
1 parent 1f6d147 commit 15a21b9
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { Mock, beforeEach, describe, expect, test, vi } from 'vitest';
import {
AppParametersRequest,
AppParametersResponse,
Expand All @@ -15,15 +15,30 @@ describe('AppParameters request handler', () => {
let mockServices: MockServices;
let mockIndexedDb: IndexedDbMock;
let mockCtx: HandlerContext;
let apSubNext: Mock;

beforeEach(() => {
vi.resetAllMocks();

apSubNext = vi.fn();

const mockAppParametersSubscription = {
next: apSubNext,
[Symbol.asyncIterator]: () => mockAppParametersSubscription,
};

mockIndexedDb = {
getAppParams: vi.fn(),
subscribe: (table: string) => {
if (table === 'APP_PARAMETERS') return mockAppParametersSubscription;
throw new Error('Table not supported');
},
};

mockServices = {
getWalletServices: vi.fn(() => Promise.resolve({ indexedDb: mockIndexedDb })),
getWalletServices: vi.fn(() =>
Promise.resolve({ indexedDb: mockIndexedDb }),
) as MockServices['getWalletServices'],
};
mockCtx = createHandlerContext({
service: ViewService,
Expand All @@ -46,9 +61,12 @@ describe('AppParameters request handler', () => {
expect(appParameterResponse.parameters?.equals(testData)).toBeTruthy();
});

test('should fail to get appParameters when idb has none', async () => {
test('should wait for appParameters when idb has none', async () => {
mockIndexedDb.getAppParams?.mockResolvedValue(undefined);
await expect(appParameters(new AppParametersRequest(), mockCtx)).rejects.toThrow();
apSubNext.mockResolvedValueOnce({
value: { value: new AppParametersRequest(), table: 'APP_PARAMETERS' },
});
await expect(appParameters(new AppParametersRequest(), mockCtx)).resolves.toBeTruthy();
});
});

Expand Down

0 comments on commit 15a21b9

Please sign in to comment.