Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
octave08 committed Jul 20, 2023
1 parent f5aeb39 commit 77b5206
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/@magic-ext/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface SDKEnvironment {
version: string;
platform: 'web' | 'react-native';
defaultEndpoint: string;
defaultNFTEndpoint: string;
ViewController: ConstructorOf<ViewController>;
configureStorage: () => Promise<typeof localForage>;
bundleId?: string | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/@magic-sdk/provider/test/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createMagicSDKCtor(environment: { [P in keyof SDKEnvironment]?:
platform: 'web',
version: '1.0.0-test',
defaultEndpoint: MAGIC_RELAYER_FULL_URL,
defaultNFTEndponit: MAGIC_NFT_API_URL,
defaultNFTEndpoint: MAGIC_NFT_API_URL,
ViewController: TestViewController,
configureStorage: async () => {
const lf = localForage.createInstance({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable no-new, class-methods-use-this, global-require */

import browserEnv from '@ikscodes/browser-env';
import { MAGIC_RELAYER_FULL_URL, TEST_API_KEY } from '../../../constants';
import { MAGIC_NFT_API_URL, MAGIC_RELAYER_FULL_URL, TEST_API_KEY } from '../../../constants';
import { createMagicSDKCtor } from '../../../factories';
import { AuthModule } from '../../../../src/modules/auth';
import { UserModule } from '../../../../src/modules/user';
Expand All @@ -18,6 +18,7 @@ function assertEncodedQueryParams(parameters: string, expectedParams: any = {})
const defaultExpectedParams = {
API_KEY: TEST_API_KEY,
DOMAIN_ORIGIN: 'null',
nftEndpoint: MAGIC_NFT_API_URL,
host: 'auth.magic.link',
sdk: 'magic-sdk',
version: '1.0.0-test',
Expand Down Expand Up @@ -67,6 +68,15 @@ test('Initialize `MagicSDK` with custom endpoint', () => {
assertModuleInstanceTypes(magic);
});

test('Initialize `MagicSDK` with custom nftEnpoint', () => {
const Ctor = createMagicSDKCtor();
const magic = new Ctor(TEST_API_KEY, { nftEndpoint: 'https://example.com' });

expect(magic.apiKey).toBe(TEST_API_KEY);
assertEncodedQueryParams(magic.parameters, { nftEndpoint: 'https://example.com' });
assertModuleInstanceTypes(magic);
});

test('Initialize `MagicSDK` when `window.location` is missing', () => {
browserEnv.stub('location', undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ test('Generate JSON RPC request payload with method `magic_get_info` and the act
expect(requestPayload.method).toBe('magic_get_info');
expect(requestPayload.params).toEqual([{ walletType: 'metamask' }]);
});

test('Generate JSON RPC request payload with method `magic_get_info`', async () => {
const magic = createMagicSDK();
magic.user.request = jest.fn();

await storage.setItem('mc_active_wallet', 'metamask');

await magic.user.getInfo();

const requestPayload = magic.user.request.mock.calls[0][0];
expect(requestPayload.method).toBe('magic_get_info');
expect(requestPayload.params).toEqual([{ walletType: 'metamask' }]);
});

0 comments on commit 77b5206

Please sign in to comment.