Skip to content

Commit

Permalink
test: add tests for unhappy path
Browse files Browse the repository at this point in the history
  • Loading branch information
avasisht23 committed Nov 14, 2023
1 parent f810aea commit f05b469
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions packages/signers/src/magic/__tests__/signer.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import * as AASignersModule from "@alchemy/aa-signers";
import { Magic } from "magic-sdk";
import { MagicSigner } from "../signer.js";

describe("Magic Signer Tests", () => {
it("should correctly error when signing message if not authenticated", async () => {
const signer = await givenSigner(false);

const signMessage = signer.signMessage("test");
await expect(signMessage).rejects.toThrowErrorMatchingInlineSnapshot(
'"Not authenticated"'
);
});

it("should correctly authenticate", async () => {
const spy = vi.spyOn(AASignersModule, "MagicSigner");
givenSigner();
expect(spy.mock.calls).toMatchInlineSnapshot("[]");
});

it("should correctly get address", async () => {
it("should correctly get address if authenticated", async () => {
const signer = await givenSigner();

const address = await signer.getAddress();
Expand All @@ -27,11 +11,20 @@ describe("Magic Signer Tests", () => {
);
});

it("should correctly get auth details", async () => {
it("should correctly fail to get address if unauthenticated", async () => {
const signer = await givenSigner(false);

const address = signer.getAddress();
await expect(address).rejects.toThrowErrorMatchingInlineSnapshot(
'"Not authenticated"'
);
});

it("should correctly get auth details if authenticated", async () => {
const signer = await givenSigner();

const address = await signer.getAuthDetails();
expect(address).toMatchInlineSnapshot(`
const details = await signer.getAuthDetails();
expect(details).toMatchInlineSnapshot(`
{
"email": "test",
"isMfaEnabled": false,
Expand All @@ -43,13 +36,31 @@ describe("Magic Signer Tests", () => {
`);
});

it("should correctly fail to get auth details if unauthenticated", async () => {
const signer = await givenSigner(false);

const details = signer.getAuthDetails();
await expect(details).rejects.toThrowErrorMatchingInlineSnapshot(
'"Not authenticated"'
);
});

it("should correctly sign message if authenticated", async () => {
const signer = await givenSigner();

const signMessage = await signer.signMessage("test");
expect(signMessage).toMatchInlineSnapshot('"0xtest"');
});

it("should correctly fail to sign message if unauthenticated", async () => {
const signer = await givenSigner(false);

const signMessage = signer.signMessage("test");
await expect(signMessage).rejects.toThrowErrorMatchingInlineSnapshot(
'"Not authenticated"'
);
});

it("should correctly sign typed data if authenticated", async () => {
const signer = await givenSigner();

Expand Down

0 comments on commit f05b469

Please sign in to comment.