Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Nov 26, 2024
1 parent a00c6ad commit b8490e6
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions apps/extension/src/background/approvals/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,12 @@ describe("approvals service", () => {
it("should approve connection if it's not already approved", async () => {
const interfaceOrigin = "origin";
const tabId = 1;
const chainId = "chain-id";

jest.spyOn(service, "isConnectionApproved").mockResolvedValue(false);
jest.spyOn(service as any, "launchApprovalPopup");
service["resolverMap"] = {};

const promise = service.approveConnection(interfaceOrigin, chainId);
const promise = service.approveConnection(interfaceOrigin);
await new Promise<void>((r) =>
setTimeout(() => {
r();
Expand All @@ -283,18 +282,17 @@ describe("approvals service", () => {
);
expect(service.isConnectionApproved).toHaveBeenCalledWith(
interfaceOrigin,
chainId
undefined
);
await expect(promise).resolves.toBeDefined();
});

it("should not approve connection if it was already approved", async () => {
const interfaceOrigin = "origin";
const chainId = "chain-id";
jest.spyOn(service, "isConnectionApproved").mockResolvedValue(true);

await expect(
service.approveConnection(interfaceOrigin, chainId)
service.approveConnection(interfaceOrigin)
).resolves.toBeUndefined();
});
});
Expand Down Expand Up @@ -355,14 +353,13 @@ describe("approvals service", () => {
describe("approveDisconnection", () => {
it("should approve disconnection if there is a connection already approved", async () => {
const interfaceOrigin = "origin";
const chainId = "chain-id";
const tabId = 1;

jest.spyOn(service, "isConnectionApproved").mockResolvedValue(true);
jest.spyOn(service as any, "launchApprovalPopup");
service["resolverMap"] = {};

const promise = service.approveDisconnection(interfaceOrigin, chainId);
const promise = service.approveDisconnection(interfaceOrigin);
await new Promise<void>((r) =>
setTimeout(() => {
r();
Expand All @@ -376,18 +373,17 @@ describe("approvals service", () => {
);
expect(service.isConnectionApproved).toHaveBeenCalledWith(
interfaceOrigin,
chainId
undefined
);
await expect(promise).resolves.toBeDefined();
});

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

await expect(
service.approveDisconnection(interfaceOrigin, chainId)
service.approveDisconnection(interfaceOrigin)
).resolves.toBeUndefined();
});
});
Expand Down Expand Up @@ -547,36 +543,27 @@ describe("approvals service", () => {
describe("isConnectionApproved", () => {
it("should return true if origin is approved", async () => {
const origin = "origin";
const chainId = "chain-id";
jest
.spyOn(localStorage, "getApprovedOrigins")
.mockResolvedValue([origin]);

await expect(service.isConnectionApproved(origin, chainId)).resolves.toBe(
true
);
await expect(service.isConnectionApproved(origin)).resolves.toBe(true);
});

it("should return false if origin is not approved", async () => {
const origin = "origin";
const chainId = "chain-id";
jest.spyOn(localStorage, "getApprovedOrigins").mockResolvedValue([]);

await expect(service.isConnectionApproved(origin, chainId)).resolves.toBe(
false
);
await expect(service.isConnectionApproved(origin)).resolves.toBe(false);
});

it("should return false if there are no origins in store", async () => {
const origin = "origin";
const chainId = "chain-id";
jest
.spyOn(localStorage, "getApprovedOrigins")
.mockResolvedValue(undefined);

await expect(service.isConnectionApproved(origin, chainId)).resolves.toBe(
false
);
await expect(service.isConnectionApproved(origin)).resolves.toBe(false);
});
});
});

0 comments on commit b8490e6

Please sign in to comment.