Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Typescript coverage to util and lib folders #10284

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/lib/ppom/ppom-storage-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

import { getArrayBufferForBlob } from 'react-native-blob-jsi-helper';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
declare global {
interface FileReader {
_setReadyState(state: number): void;
_result: Uint8Array | null;
_error: string | null;
}
}

if (window.FileReader?.prototype.readAsArrayBuffer) {

Check failure on line 14 in app/lib/ppom/ppom-storage-backend.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Cannot find name 'window'.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.FileReader.prototype.readAsArrayBuffer = function (blob) {

Check failure on line 15 in app/lib/ppom/ppom-storage-backend.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Cannot find name 'window'.

Check failure on line 15 in app/lib/ppom/ppom-storage-backend.ts

View workflow job for this annotation

GitHub Actions / scripts (lint:tsc)

Parameter 'blob' implicitly has an 'any' type.
if (this.readyState === this.LOADING) throw new Error('InvalidStateError');
this._setReadyState(this.LOADING);
this._result = null;
Expand Down
32 changes: 25 additions & 7 deletions app/util/blockaid/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
getBlockaidMetricsParams,
isBlockaidSupportedOnCurrentChain,
getBlockaidTransactionMetricsParams,
TransactionType,
} from '.';
import { TransactionStatus } from '@metamask/transaction-controller';

describe('Blockaid util', () => {
describe('getBlockaidTransactionMetricsParams', () => {
Expand All @@ -27,10 +29,17 @@ describe('Blockaid util', () => {
});

it('returns empty object when transaction id does not match security response id', () => {
const transaction = {
id: 1,
const transaction: TransactionType = {
id: '1',
status: TransactionStatus.approved,
time: 0,
chainId: '0x1',
txParams: {
to: '0x',
from: '0x',
},
currentTransactionSecurityAlertResponse: {
id: 2,
id: '2',
response: {
result_type: ResultType.Malicious,
reason: Reason.notApplicable,
Expand All @@ -47,10 +56,17 @@ describe('Blockaid util', () => {
});

it('returns metrics params object when transaction id matches security response id', () => {
const transaction = {
id: 1,
const transaction: TransactionType = {
id: '1',
status: TransactionStatus.approved,
time: 0,
chainId: '0x1',
txParams: {
to: '0x',
from: '0x',
},
currentTransactionSecurityAlertResponse: {
id: 1,
id: '1',
response: {
result_type: ResultType.Malicious,
reason: Reason.notApplicable,
Expand Down Expand Up @@ -91,7 +107,9 @@ describe('Blockaid util', () => {
});

it('returns empty object when chain id is not in supported chain ids list', () => {
jest.spyOn(NetworkControllerMock, 'selectChainId').mockReturnValue('10');
jest
.spyOn(NetworkControllerMock, 'selectChainId')
.mockReturnValue('0x10');
const result = getBlockaidMetricsParams(undefined);
expect(result).toStrictEqual({});
});
Expand Down
Loading