Skip to content

Commit

Permalink
fix: fix approvals service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Sep 27, 2024
1 parent a313d32 commit c49fa7a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions apps/extension/src/background/approvals/service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { chains } from "@namada/chains";
import { WrapperTxMsgValue } from "@namada/types";
import { ChainsService } from "background/chains";
import { KeyRingService } from "background/keyring";
Expand Down Expand Up @@ -60,10 +61,11 @@ describe("approvals service", () => {
jest.clearAllMocks();
txStore = new KVStoreMock<PendingTx>("PendingTx");
dataStore = new KVStoreMock<string>("DataStore");
keyRingService = createMockInstance(KeyRingService as any);
keyRingService = createMockInstance(KeyRingService);
const vaultService: jest.Mocked<VaultService> = createMockInstance(
VaultService as any
);
chainService = createMockInstance(ChainsService);
const broadcaster: jest.Mocked<ExtensionBroadcaster> =
createMockInstance(ExtensionBroadcaster);
localStorage = new LocalStorage(new KVStoreMock("LocalStorage"));
Expand Down Expand Up @@ -264,7 +266,7 @@ describe("approvals service", () => {
describe("approveConnection", () => {
it("should approve connection if it's not already approved", async () => {
const interfaceOrigin = "origin";
const chainId = "chainId";
const chainId = chains.namada.chainId;
const tabId = 1;

jest.spyOn(service, "isConnectionApproved").mockResolvedValue(false);
Expand All @@ -281,10 +283,11 @@ describe("approvals service", () => {

expect(service["launchApprovalPopup"]).toHaveBeenCalledWith(
"/approve-connection",
{ interfaceOrigin }
{ interfaceOrigin, chainId }
);
expect(service.isConnectionApproved).toHaveBeenCalledWith(
interfaceOrigin
interfaceOrigin,
chainId
);
await expect(promise).resolves.toBeDefined();
});
Expand Down Expand Up @@ -366,7 +369,7 @@ describe("approvals service", () => {
describe("approveDisconnection", () => {
it("should approve disconnection if there is a connection already approved", async () => {
const interfaceOrigin = "origin";
const chainId = "";
const chainId = chains.namada.chainId;
const tabId = 1;

jest.spyOn(service, "isConnectionApproved").mockResolvedValue(true);
Expand All @@ -386,14 +389,15 @@ describe("approvals service", () => {
{ interfaceOrigin }
);
expect(service.isConnectionApproved).toHaveBeenCalledWith(
interfaceOrigin
interfaceOrigin,
chainId
);
await expect(promise).resolves.toBeDefined();
});

it("should not approve disconnection if it is NOT already approved", async () => {
const interfaceOrigin = "origin";
const chainId = "";
const chainId = "chainId";
jest.spyOn(service, "isConnectionApproved").mockResolvedValue(false);

await expect(
Expand Down Expand Up @@ -559,7 +563,8 @@ describe("approvals service", () => {
describe("isConnectionApproved", () => {
it("should return true if origin is approved", async () => {
const origin = "origin";
const chainId = "chainId";
const chainId = chains.namada.chainId;
jest.spyOn(chainService, "getChain").mockResolvedValue(chains.namada);
jest
.spyOn(localStorage, "getApprovedOrigins")
.mockResolvedValue([origin]);
Expand All @@ -572,6 +577,7 @@ describe("approvals service", () => {
it("should return false if origin is not approved", async () => {
const origin = "origin";
const chainId = "chainId";
jest.spyOn(chainService, "getChain").mockResolvedValue(chains.namada);
jest.spyOn(localStorage, "getApprovedOrigins").mockResolvedValue([]);

await expect(service.isConnectionApproved(origin, chainId)).resolves.toBe(
Expand All @@ -582,6 +588,7 @@ describe("approvals service", () => {
it("should return false if there are no origins in store", async () => {
const origin = "origin";
const chainId = "chainId";
jest.spyOn(chainService, "getChain").mockResolvedValue(chains.namada);
jest
.spyOn(localStorage, "getApprovedOrigins")
.mockResolvedValue(undefined);
Expand Down

0 comments on commit c49fa7a

Please sign in to comment.