Skip to content

Commit

Permalink
Additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariflo committed Mar 8, 2024
1 parent 80a2443 commit 7fd6ace
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import browserEnv from '@ikscodes/browser-env';
import { MagicIncomingWindowMessage, MagicOutgoingWindowMessage, JsonRpcRequestPayload } from '@magic-sdk/types';
import { create } from 'lodash';
import { createViewController, TestViewController } from '../../../factories';
import { JsonRpcResponse } from '../../../../src/core/json-rpc';
import * as storage from '../../../../src/util/storage';
import * as webCryptoUtils from '../../../../src/util/web-crypto';
import * as deviceShareWebCryptoUtils from '../../../../src/util/device-share-web-crypto';
import { SDKEnvironment } from '../../../../src/core/sdk-environment';
import { createModalNotReadyError } from '../../../../src/core/sdk-exceptions';
import { createModalNotReadyError, createResponseTimeoutError } from '../../../../src/core/sdk-exceptions';

/**
* Create a dummy request payload.
Expand Down Expand Up @@ -262,6 +263,24 @@ test('throws MODAL_NOT_READY error when not connected to the internet', async ()
}
});

test('throws RESPONSE_TIMEOUT error if response takes longer than 10 seconds', async () => {
const eventWithRt = { data: { ...responseEvent().data } };
const { handlerSpy, onSpy } = stubViewController(viewController, [
[MagicIncomingWindowMessage.MAGIC_HANDLE_RESPONSE, eventWithRt],
]);

// @ts-ignore protected variable
viewController.responseTimeout = 1;

const payload = requestPayload();

try {
await viewController.post(MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST, payload);
} catch (e) {
expect(e).toEqual(createResponseTimeoutError('eth_accounts', 1));
}
});

test('does not call web crypto api if platform is not web', async () => {
SDKEnvironment.platform = 'react-native';
const eventWithRt = { data: { ...responseEvent().data } };
Expand Down

0 comments on commit 7fd6ace

Please sign in to comment.