|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { setWalletBackupContent } from "../wallet.js"; |
| 3 | +import { FakeUser } from "../../__tests__/fake-user.js"; |
| 4 | +import { EventFactory } from "applesauce-factory"; |
| 5 | +import { WalletBlueprint } from "../../blueprints/wallet.js"; |
| 6 | +import { generateSecretKey } from "nostr-tools"; |
| 7 | +import { WALLET_BACKUP_KIND } from "../../helpers/wallet.js"; |
| 8 | +import { unixNow } from "applesauce-core/helpers"; |
| 9 | + |
| 10 | +const user = new FakeUser(); |
| 11 | +const factory = new EventFactory({ signer: user }); |
| 12 | + |
| 13 | +describe("setWalletBackupContent", () => { |
| 14 | + it("should throw if kind is not wallet kind", async () => { |
| 15 | + const note = user.note(); |
| 16 | + |
| 17 | + await expect( |
| 18 | + setWalletBackupContent(note)( |
| 19 | + { kind: WALLET_BACKUP_KIND, tags: [], created_at: unixNow(), content: "" }, |
| 20 | + factory.context, |
| 21 | + ), |
| 22 | + ).rejects.toThrow(); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should throw if pubkey does not match", async () => { |
| 26 | + const wallet = await factory.sign(await factory.create(WalletBlueprint, generateSecretKey(), [])); |
| 27 | + const user2 = new FakeUser(); |
| 28 | + |
| 29 | + await expect( |
| 30 | + setWalletBackupContent(wallet)( |
| 31 | + { kind: WALLET_BACKUP_KIND, tags: [], created_at: unixNow(), content: "" }, |
| 32 | + { signer: user2 }, |
| 33 | + ), |
| 34 | + ).rejects.toThrow(); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should copy the content of the wallet event", async () => { |
| 38 | + const wallet = await factory.sign(await factory.create(WalletBlueprint, generateSecretKey(), [])); |
| 39 | + |
| 40 | + expect( |
| 41 | + await setWalletBackupContent(wallet)( |
| 42 | + { kind: WALLET_BACKUP_KIND, tags: [], created_at: unixNow(), content: "" }, |
| 43 | + factory.context, |
| 44 | + ), |
| 45 | + ).toEqual(expect.objectContaining({ content: wallet.content })); |
| 46 | + }); |
| 47 | +}); |
0 commit comments