Skip to content

Commit

Permalink
fix: deepsource 'any'
Browse files Browse the repository at this point in the history
  • Loading branch information
sherzod-bakhodirov committed Dec 16, 2024
1 parent 612f130 commit a255c10
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/@magic-ext/kadena/test/spec/kadena.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('signTransaction - Sends params as payload', () => {
magic.kadena.signTransaction(params);

const requestPayload = magic.kadena.request.mock.calls[0][0];
expect(requestPayload.method).toBe(KadenaPayloadMethod.KadenaSignTransaction as any);
expect(requestPayload.method).toBe(KadenaPayloadMethod.KadenaSignTransaction);
expect(requestPayload.params).toEqual([{ hash: '0x123' }]);
});

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 @@ -67,7 +67,7 @@ export function createMagicSDKTestMode(environment: { [P in keyof SDKEnvironment
return new Ctor(TEST_API_KEY, { testMode: true });
}

export function createMagicSDKWithExtension(environment: { [P in keyof SDKEnvironment]?: any } = {}, extensions:any[] = []) {
export function createMagicSDKWithExtension(environment: { [P in keyof SDKEnvironment]?: any } = {}, extensions:unknown[] = []) {
const Ctor = createMagicSDKCtor(environment);
return new Ctor(TEST_API_KEY, { extensions });
}
2 changes: 1 addition & 1 deletion packages/@magic-sdk/provider/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function restoreSDKEnvironmentConstants() {
jest.unmock('../src/core/sdk-environment');
}

export function mockLocalForage(FAKE_STORE: { [key: string]: any } = {}) {
export function mockLocalForage(FAKE_STORE: Record<string, any> = {}) {
jest.spyOn(storage, 'getItem').mockImplementation((key: string) => FAKE_STORE[key]);
jest.spyOn(storage, 'setItem').mockImplementation(async (key: string, value: any) => {
FAKE_STORE[key] = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ function stubViewController(viewController: any, events: [MagicIncomingWindowMes
return { handlerSpy, onSpy, postSpy };
}

let createJwtStub: jest.SpyInstance<Promise<string | undefined>, [], any>;
let createJwtStub: jest.SpyInstance<Promise<string | undefined>>;
let getDecryptedDeviceShareStub: jest.SpyInstance<Promise<string | undefined>>;;
let clearDeviceSharesStub: jest.SpyInstance<Promise<void>, [], any>;
let clearDeviceSharesStub: jest.SpyInstance<Promise<void>>;
const FAKE_JWT_TOKEN = 'hot tokens';
const FAKE_DEVICE_SHARE = 'fake device share';
const FAKE_RT = 'will freshen';
const FAKE_INJECTED_JWT = 'fake injected jwt';
let FAKE_STORE: {[key: string]: any} = {};
let FAKE_STORE: Record<string, any> = {};

let viewController: TestViewController;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ test('If no parameters are given & platform target is "web", URL search string a
const magic = createMagicSDK({ platform: 'web' });
magic.auth.request = jest.fn();

jest.spyOn(window.history, 'replaceState').mockImplementation(() => {});
jest.spyOn(window.history, 'replaceState').mockImplementation(() => { });

jest.spyOn(window, 'location', 'get').mockReturnValue({
search: '?magic_credential=asdf',
origin: 'http://example.com',
pathname: '/hello/world',
} as any);
} as unknown as Location);

await magic.auth.loginWithCredential();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getDecryptedDeviceShare,
} from '../../../src/util/device-share-web-crypto';

let FAKE_STORE = {};
let FAKE_STORE: Record<string, any> = {};
const FAKE_NETWORK_HASH = 'network_hash';

const FAKE_PLAINTEXT_SHARE = `AQICAHg1y7j1UY7sfTib6h9cN2Kh7v0WhCRwQxEPhGAQ2m5OgQGrJvUP6MKiuj9yD96y6B4eAAABPzCCATsGCSqGSIb3DQEHBqCCASwwggEoAgEAMIIBIQYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAy6tbGg/6//2IJs9xUCARCAgfOY3knm1i2kGjLXQFoqEjOeLr/UGwHQ+AW1y20UoCX3ght68egu06Hg54JF/mCGgSDt7R7dFSOuGvapE9OEyFYz4f1+tpWb5PPaLReBRTTTfw/8Xgsfzl6iXACsLKqyXEeWci+/vOWDLqu73E0uy5StyN5InZLwHCJe4l+KMEr5C7JZvobQh4NVBT5SqgQXmLGXGGH/2ydkq8zkgVGDT9jQlqqpUH83UMFQwHSwbJRRyYLxBwQKTO0AODfqk5OnWRA+BoDC8HMFyQUb4nS+BgDlgTgL7Kg/H/Echr+SlQKJdWJnvf3BjSBwO8z5kVpxRo5xwG4=`;
Expand All @@ -21,12 +21,12 @@ const FAKE_ENCRYPTION_KEY = 'fake encryption key';
const FAKE_IV = new Uint8Array(JSON.parse('[24,252,88,58,36,159,217,125,152,115,39,254]'));

beforeAll(() => {
jest.spyOn(storage, 'getItem').mockImplementation(async (key: string) => (FAKE_STORE as any)[key]);
jest.spyOn(storage, 'getItem').mockImplementation(async (key: string) => FAKE_STORE[key]);
jest.spyOn(storage, 'setItem').mockImplementation(async (key: string, value: any) => {
(FAKE_STORE as any)[key] = value;
FAKE_STORE[key] = value;
});
jest.spyOn(storage, 'removeItem').mockImplementation(async (key: string) => {
(FAKE_STORE as any)[key] = null;
FAKE_STORE[key] = null;
});
jest.spyOn(storage, 'iterate').mockImplementation(async (callback) => {
await callback('value1', `${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`, 1);
Expand Down Expand Up @@ -64,16 +64,16 @@ test('encryptAndPersistDeviceShare should persist encrypted device share when st
};

await encryptAndPersistDeviceShare(FAKE_PLAINTEXT_SHARE, FAKE_NETWORK_HASH);
expect((FAKE_STORE as any).ds_network_hash).toEqual(FAKE_ENCRYPTED_DEVICE_SHARE);
expect(FAKE_STORE.ds_network_hash).toEqual(FAKE_ENCRYPTED_DEVICE_SHARE);
});

test('encryptAndPersistDeviceShare should persist encrypted device share when store has existing iv and encryption key', async () => {
(window as any).crypto.subtle = {
encrypt: () => Promise.resolve(base64ToArrayBuffer(FAKE_ENCRYPTED_DEVICE_SHARE)),
};

(FAKE_STORE as any)[INITIALIZATION_VECTOR_KEY] = FAKE_IV;
(FAKE_STORE as any)[ENCRYPTION_KEY_KEY] = FAKE_ENCRYPTION_KEY;
FAKE_STORE[INITIALIZATION_VECTOR_KEY] = FAKE_IV;
FAKE_STORE[ENCRYPTION_KEY_KEY] = FAKE_ENCRYPTION_KEY;

await encryptAndPersistDeviceShare(FAKE_PLAINTEXT_SHARE, FAKE_NETWORK_HASH);
expect((FAKE_STORE as any).ds_network_hash).toEqual(FAKE_ENCRYPTED_DEVICE_SHARE);
Expand All @@ -86,7 +86,7 @@ test('getDecryptedDeviceShare should return undefined if no existing iv string f
decrypt: () => Promise.resolve(base64ToArrayBuffer(FAKE_ENCRYPTED_DEVICE_SHARE)),
};

(FAKE_STORE as any)[INITIALIZATION_VECTOR_KEY] = null;
FAKE_STORE[INITIALIZATION_VECTOR_KEY] = null;
const res = await getDecryptedDeviceShare(FAKE_NETWORK_HASH);
expect(res).toEqual(undefined);
});
Expand All @@ -96,9 +96,9 @@ test('getDecryptedDeviceShare should return undefined if store has existing iv a
decrypt: () => Promise.resolve(base64ToArrayBuffer(FAKE_DECRYPTED_DEVICE_SHARE)),
};

(FAKE_STORE as any)[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`] = null;
(FAKE_STORE as any)[INITIALIZATION_VECTOR_KEY] = FAKE_IV;
(FAKE_STORE as any)[ENCRYPTION_KEY_KEY] = FAKE_ENCRYPTION_KEY;
FAKE_STORE[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`] = null;
FAKE_STORE[INITIALIZATION_VECTOR_KEY] = FAKE_IV;
FAKE_STORE[ENCRYPTION_KEY_KEY] = FAKE_ENCRYPTION_KEY;

const res = await getDecryptedDeviceShare(FAKE_NETWORK_HASH);

Expand All @@ -110,9 +110,9 @@ test('getDecryptedDeviceShare returns decrypted device share if iv encryption ke
decrypt: () => Promise.resolve(base64ToArrayBuffer(FAKE_DECRYPTED_DEVICE_SHARE)),
};

(FAKE_STORE as any)[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`] = FAKE_ENCRYPTED_DEVICE_SHARE;
(FAKE_STORE as any)[INITIALIZATION_VECTOR_KEY] = FAKE_IV;
(FAKE_STORE as any)[ENCRYPTION_KEY_KEY] = FAKE_ENCRYPTION_KEY;
FAKE_STORE[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`] = FAKE_ENCRYPTED_DEVICE_SHARE;
FAKE_STORE[INITIALIZATION_VECTOR_KEY] = FAKE_IV;
FAKE_STORE[ENCRYPTION_KEY_KEY] = FAKE_ENCRYPTION_KEY;

const res = await getDecryptedDeviceShare(FAKE_NETWORK_HASH);
expect(res).toEqual(FAKE_DECRYPTED_DEVICE_SHARE);
Expand All @@ -125,9 +125,9 @@ test('clearDeviceShares should successfully clear device shares', async () => {
decrypt: () => Promise.resolve(base64ToArrayBuffer(FAKE_DECRYPTED_DEVICE_SHARE)),
};

(FAKE_STORE as any)[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`] = FAKE_ENCRYPTED_DEVICE_SHARE;
FAKE_STORE[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`] = FAKE_ENCRYPTED_DEVICE_SHARE;

await clearDeviceShares();

expect((FAKE_STORE as any)[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`]).toEqual(null);
expect(FAKE_STORE[`${DEVICE_SHARE_KEY}_${FAKE_NETWORK_HASH}`]).toEqual(null);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TypedEmitter } from '../../../../src/util/events';

type DefaultEvents<TResult> = {
done: (result: TResult) => void;
error: (reason: any) => void;
error: (reason: unknown) => void;
settled: () => void;
};

Expand Down Expand Up @@ -62,7 +62,7 @@ test('Attaches `Promise` methods to `TypedEmitter` results', () => {
const p = createPromiEvent(resolve => resolve(true))[emitterMethod]('done', () => {});

promiseMethods.forEach(promiseMethod => {
expect(typeof (p as any)[promiseMethod] === 'function').toBe(true);
expect(typeof (p as Record<string, any>)[promiseMethod] === 'function').toBe(true);
});

emitterStub.mockReset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as storage from '../../../src/util/storage';
import { clearKeys, createJwt, STORE_KEY_PRIVATE_KEY, STORE_KEY_PUBLIC_JWK } from '../../../src/util/web-crypto';
import { TextEncoder } from 'util';

let FAKE_STORE: { [key: string]: any } = {};
let FAKE_STORE: Record<string, any> = {};

beforeAll(() => {
jest.spyOn(storage, 'getItem').mockImplementation(async (key: string) => FAKE_STORE[key]);
Expand Down
12 changes: 6 additions & 6 deletions packages/magic-sdk/test/spec/iframe-controller/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test('Appends header with style, appends body with iframe, and resolves iframe',

jest.spyOn(global, 'addEventListener').mockImplementation(jest.fn());
jest.spyOn(global, 'removeEventListener').mockImplementation(jest.fn());
jest.spyOn(document, 'querySelectorAll').mockReturnValue({ length: 0 } as any);
jest.spyOn(document, 'querySelectorAll').mockReturnValue({ length: 0 } as unknown as NodeListOf<Element>);
jest.spyOn(document, 'createElement').mockImplementation(createElementStub);
jest.spyOn(document, 'readyState', 'get').mockReturnValue('complete');
jest.spyOn(document.body, 'appendChild').mockImplementation(appendChildStub);
Expand All @@ -64,7 +64,7 @@ test('Displays warning in console upon duplicate iframes', async () => {

jest.spyOn(global, 'addEventListener').mockImplementation(jest.fn());
jest.spyOn(global, 'removeEventListener').mockImplementation(jest.fn());
jest.spyOn(document, 'querySelectorAll').mockReturnValue([{ src: ENCODED_QUERY_PARAMS }] as any);
jest.spyOn(document, 'querySelectorAll').mockReturnValue([{ src: ENCODED_QUERY_PARAMS }] as unknown as NodeListOf<Element>);
jest.spyOn(document, 'createElement').mockImplementation(createElementStub);
jest.spyOn(document, 'readyState', 'get').mockReturnValue('complete');
jest.spyOn(document.body, 'appendChild').mockImplementation(appendChildStub);
Expand All @@ -81,7 +81,7 @@ test('Waits until `document` is loaded/ready', async () => {

jest.spyOn(global, 'addEventListener').mockImplementation(jest.fn());
jest.spyOn(global, 'removeEventListener').mockImplementation(jest.fn());
jest.spyOn(document, 'querySelectorAll').mockReturnValue({ length: 0 } as any);
jest.spyOn(document, 'querySelectorAll').mockReturnValue({ length: 0 } as unknown as NodeListOf<Element>);
jest.spyOn(document, 'createElement').mockImplementation(createElementStub);
jest.spyOn(document, 'readyState', 'get').mockReturnValue('loading');
jest.spyOn(document.body, 'appendChild').mockImplementation(appendChildStub);
Expand All @@ -97,7 +97,7 @@ test('Assumes the iframe is not yet initialized if `src` is `undefined`', async

jest.spyOn(global, 'addEventListener').mockImplementation(jest.fn());
jest.spyOn(global, 'removeEventListener').mockImplementation(jest.fn());
jest.spyOn(document, 'querySelectorAll').mockReturnValue({ length: 0 } as any);
jest.spyOn(document, 'querySelectorAll').mockReturnValue({ length: 0 } as unknown as NodeListOf<Element>);
jest.spyOn(document, 'createElement').mockImplementation(createElementStub);
jest.spyOn(document, 'readyState', 'get').mockReturnValue('complete');
jest.spyOn(document.body, 'appendChild').mockImplementation(appendChildStub);
Expand Down Expand Up @@ -187,7 +187,7 @@ test('Executes events where `messageHandlers` size is > 0', done => {
});

test('Ignores events where `messageHandlers` size is === 0', done => {
jest.spyOn(global, 'location', 'get').mockImplementation(() => new URL(MAGIC_RELAYER_FULL_URL) as any);
jest.spyOn(global, 'location', 'get').mockImplementation(() => new URL(MAGIC_RELAYER_FULL_URL) as unknown as Location);

const viewController = createIframeController();
(viewController as any).endpoint = ''; // Force `event.origin` and `this.endpoint` to be equivalent
Expand All @@ -201,7 +201,7 @@ test('Ignores events where `messageHandlers` size is === 0', done => {
});

test('Ignores events where `event.origin` and `this.endpoint` are not equivalent', done => {
jest.spyOn(global, 'location', 'get').mockImplementation(() => new URL(MAGIC_RELAYER_FULL_URL) as any);
jest.spyOn(global, 'location', 'get').mockImplementation(() => new URL(MAGIC_RELAYER_FULL_URL) as unknown as Location);

const viewController = createIframeController();
(viewController as any).messageHandlers = { size: 0 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ test('Saves the current `document.activeElement`', async () => {
};

const overlay = createIframeController();
const mockElement = document.createElement('div');

jest.spyOn(document, 'activeElement', 'get').mockReturnValue('qwertyqwerty' as any);
jest.spyOn(document, 'activeElement', 'get').mockReturnValue(mockElement);

expect((overlay as any).activeElement).toBe(null);

await (overlay as any).showOverlay();

expect((overlay as any).activeElement).toBe('qwertyqwerty');
expect((overlay as any).activeElement).toBe(mockElement);
});

0 comments on commit a255c10

Please sign in to comment.