forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerchants.service.spec.ts
More file actions
88 lines (76 loc) · 2.41 KB
/
Copy pathmerchants.service.spec.ts
File metadata and controls
88 lines (76 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { BadRequestException } from "@nestjs/common";
import { MerchantsService } from "./merchants.service";
import { PrismaService } from "../prisma/prisma.service";
import { StellarValidator } from "../stellar/utils/stellar.validator";
describe("MerchantsService", () => {
const merchantId = "merchant-1";
const payoutWallet = StellarValidator.generateKeypair().publicKey;
const merchant = {
id: merchantId,
name: "Acme Studio",
stellarPublicKey: StellarValidator.generateKeypair().publicKey,
businessEmail: "billing@acme.test",
preferredAsset: "USDC",
payoutWallet,
webhookUrl: null,
createdAt: new Date(),
updatedAt: new Date(),
};
const prisma = {
merchant: {
findUniqueOrThrow: jest.fn(),
update: jest.fn(),
},
};
let service: MerchantsService;
beforeEach(() => {
jest.clearAllMocks();
prisma.merchant.findUniqueOrThrow.mockResolvedValue(merchant);
prisma.merchant.update.mockResolvedValue(merchant);
service = new MerchantsService(prisma as unknown as PrismaService);
});
it("returns the merchant profile", async () => {
await expect(service.findProfile(merchantId)).resolves.toEqual(merchant);
expect(prisma.merchant.findUniqueOrThrow).toHaveBeenCalledWith({
where: { id: merchantId },
});
});
it("creates or replaces profile setup data", async () => {
await service.upsertProfile(merchantId, {
name: "Acme Studio",
businessEmail: "billing@acme.test",
preferredAsset: "usdc",
payoutWallet,
});
expect(prisma.merchant.update).toHaveBeenCalledWith({
where: { id: merchantId },
data: {
name: "Acme Studio",
businessEmail: "billing@acme.test",
preferredAsset: "USDC",
payoutWallet,
},
});
});
it("updates partial profile setup data", async () => {
await service.updateProfile(merchantId, {
preferredAsset: "XLM",
payoutWallet,
});
expect(prisma.merchant.update).toHaveBeenCalledWith({
where: { id: merchantId },
data: {
preferredAsset: "XLM",
payoutWallet,
},
});
});
it("rejects invalid Stellar payout wallets before saving", async () => {
await expect(
service.updateProfile(merchantId, {
payoutWallet: "not-a-stellar-key",
}),
).rejects.toBeInstanceOf(BadRequestException);
expect(prisma.merchant.update).not.toHaveBeenCalled();
});
});