|
1
|
import { IPaymentModuleService } from "@medusajs/framework/types" |
|
2
|
|
|
3
|
import { moduleIntegrationTestRunner } from "@medusajs/test-utils" |
|
4
|
import { Modules } from "@medusajs/framework/utils" |
|
5
|
|
|
6
|
jest.setTimeout(30000) |
|
7
|
|
|
8
|
moduleIntegrationTestRunner<IPaymentModuleService>({ |
|
9
|
moduleName: Modules.PAYMENT, |
|
10
|
moduleOptions: { |
|
11
|
cloud: { |
|
12
|
api_key: "test", |
|
13
|
environment_handle: "test", |
|
14
|
webhook_secret: "test", |
|
15
|
endpoint: "test", |
|
16
|
payment_accounts: ["default", "eu"], |
|
17
|
}, |
|
18
|
}, |
|
19
|
testSuite: ({ service }) => { |
|
20
|
describe("Payment Module Service", () => { |
|
21
|
describe("providers", () => { |
|
22
|
it("should load the system provider and a medusa payments provider per payment account", async () => { |
|
23
|
const paymentProviders = await service.listPaymentProviders() |
|
24
|
|
|
25
|
expect(paymentProviders).toHaveLength(3) |
|
26
|
expect(paymentProviders).toEqual( |
|
27
|
expect.arrayContaining([ |
|
28
|
expect.objectContaining({ |
|
29
|
id: "pp_system_default", |
|
30
|
}), |
|
31
|
expect.objectContaining({ |
|
32
|
id: "pp_medusa-payments_default", |
|
33
|
}), |
|
34
|
expect.objectContaining({ |
|
35
|
id: "pp_medusa-payments_eu", |
|
36
|
}), |
|
37
|
]) |
|
38
|
) |
|
39
|
}) |
|
40
|
|
|
41
|
it("should create a payment session successfully", async () => { |
|
42
|
const paymentCollection = await service.createPaymentCollections({ |
|
43
|
currency_code: "USD", |
|
44
|
amount: 200, |
|
45
|
}) |
|
46
|
|
|
47
|
const paymentSession = await service.createPaymentSession( |
|
48
|
paymentCollection.id, |
|
49
|
{ |
|
50
|
provider_id: "pp_system_default", |
|
51
|
amount: 200, |
|
52
|
currency_code: "USD", |
|
53
|
data: {}, |
|
54
|
} |
|
55
|
) |
|
56
|
}) |
|
57
|
|
|
58
|
it("should load payment plugins", async () => { |
|
59
|
let error = await service |
|
60
|
.createPaymentCollections([ |
|
61
|
{ |
|
62
|
amount: 200, |
|
63
|
} as any, |
|
64
|
]) |
|
65
|
.catch((e) => e) |
|
66
|
|
|
67
|
expect(error.message).toContain( |
|
68
|
"Value for PaymentCollection.currency_code is required, 'undefined' found" |
|
69
|
) |
|
70
|
}) |
|
71
|
|
|
72
|
it("should create a payment collection successfully", async () => { |
|
73
|
const [createdPaymentCollection] = |
|
74
|
await service.createPaymentCollections([ |
|
75
|
{ currency_code: "USD", amount: 200 }, |
|
76
|
]) |
|
77
|
|
|
78
|
expect(createdPaymentCollection).toEqual( |
|
79
|
expect.objectContaining({ |
|
80
|
id: expect.any(String), |
|
81
|
status: "not_paid", |
|
82
|
payment_providers: [], |
|
83
|
payment_sessions: [], |
|
84
|
payments: [], |
|
85
|
currency_code: "usd", |
|
86
|
amount: 200, |
|
87
|
}) |
|
88
|
) |
|
89
|
}) |
|
90
|
}) |
|
91
|
}) |
|
92
|
}, |
|
93
|
}) |
|
94
|
|
|
95
|
moduleIntegrationTestRunner<IPaymentModuleService>({ |
|
96
|
moduleName: Modules.PAYMENT, |
|
97
|
moduleOptions: {}, |
|
98
|
testSuite: ({ service }) => |
|
99
|
describe("providers", () => { |
|
100
|
it("should not load the medusa payments provider if the cloud options are not provided", async () => { |
|
101
|
const paymentProviders = await service.listPaymentProviders() |
|
102
|
expect(paymentProviders).toHaveLength(1) |
|
103
|
expect(paymentProviders[0].id).toBe("pp_system_default") |
|
104
|
}) |
|
105
|
}), |
|
106
|
}) |
|
107
|
|
|
108
|
moduleIntegrationTestRunner<IPaymentModuleService>({ |
|
109
|
moduleName: Modules.PAYMENT, |
|
110
|
moduleOptions: { |
|
111
|
cloud: { |
|
112
|
api_key: "test", |
|
113
|
environment_handle: "test", |
|
114
|
webhook_secret: "test", |
|
115
|
endpoint: "test", |
|
116
|
}, |
|
117
|
}, |
|
118
|
testSuite: ({ service }) => |
|
119
|
describe("providers", () => { |
|
120
|
it("should not load the medusa payments provider if there are no payment accounts", async () => { |
|
121
|
const paymentProviders = await service.listPaymentProviders() |
|
122
|
expect(paymentProviders).toHaveLength(1) |
|
123
|
expect(paymentProviders[0].id).toBe("pp_system_default") |
|
124
|
}) |
|
125
|
}), |
|
126
|
}) |