|
1
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils" |
|
2
|
import { |
|
3
|
ICartModuleService, |
|
4
|
ICustomerModuleService, |
|
5
|
IPaymentModuleService, |
|
6
|
IRegionModuleService, |
|
7
|
ISalesChannelModuleService, |
|
8
|
} from "@medusajs/types" |
|
9
|
import { Modules } from "@medusajs/utils" |
|
10
|
|
|
11
|
jest.setTimeout(50000) |
|
12
|
|
|
13
|
const env = {} |
|
14
|
|
|
15
|
medusaIntegrationTestRunner({ |
|
16
|
env, |
|
17
|
testSuite: ({ dbConnection, getContainer, api }) => { |
|
18
|
describe("Cart links", () => { |
|
19
|
let appContainer |
|
20
|
let cartModuleService: ICartModuleService |
|
21
|
let regionModule: IRegionModuleService |
|
22
|
let customerModule: ICustomerModuleService |
|
23
|
let scModuleService: ISalesChannelModuleService |
|
24
|
let paymentModuleService: IPaymentModuleService |
|
25
|
let remoteQuery, remoteLink |
|
26
|
|
|
27
|
beforeAll(async () => { |
|
28
|
appContainer = getContainer() |
|
29
|
cartModuleService = appContainer.resolve(Modules.CART) |
|
30
|
regionModule = appContainer.resolve(Modules.REGION) |
|
31
|
customerModule = appContainer.resolve(Modules.CUSTOMER) |
|
32
|
scModuleService = appContainer.resolve(Modules.SALES_CHANNEL) |
|
33
|
regionModule = appContainer.resolve(Modules.REGION) |
|
34
|
paymentModuleService = appContainer.resolve(Modules.PAYMENT) |
|
35
|
remoteQuery = appContainer.resolve("remoteQuery") |
|
36
|
remoteLink = appContainer.resolve("remoteLink") |
|
37
|
}) |
|
38
|
|
|
39
|
it("should query carts, sales channels, customers, regions with remote query", async () => { |
|
40
|
const region = await regionModule.createRegions({ |
|
41
|
name: "Region", |
|
42
|
currency_code: "usd", |
|
43
|
}) |
|
44
|
|
|
45
|
const customer = await customerModule.createCustomers({ |
|
46
|
email: "tony@stark.com", |
|
47
|
}) |
|
48
|
|
|
49
|
const salesChannel = await scModuleService.createSalesChannels({ |
|
50
|
name: "Webshop", |
|
51
|
}) |
|
52
|
|
|
53
|
const cart = await cartModuleService.createCarts({ |
|
54
|
email: "tony@stark.com", |
|
55
|
currency_code: "usd", |
|
56
|
region_id: region.id, |
|
57
|
sales_channel_id: salesChannel.id, |
|
58
|
customer_id: customer.id, |
|
59
|
}) |
|
60
|
|
|
61
|
const paymentCollection = |
|
62
|
await paymentModuleService.createPaymentCollections({ |
|
63
|
currency_code: "usd", |
|
64
|
region_id: region.id, |
|
65
|
amount: 1000, |
|
66
|
}) |
|
67
|
|
|
68
|
await remoteLink.create([ |
|
69
|
{ |
|
70
|
[Modules.CART]: { |
|
71
|
cart_id: cart.id, |
|
72
|
}, |
|
73
|
[Modules.PAYMENT]: { |
|
74
|
payment_collection_id: paymentCollection.id, |
|
75
|
}, |
|
76
|
}, |
|
77
|
]) |
|
78
|
|
|
79
|
const carts = await remoteQuery({ |
|
80
|
cart: { |
|
81
|
fields: ["id"], |
|
82
|
region: { |
|
83
|
fields: ["id"], |
|
84
|
}, |
|
85
|
customer: { |
|
86
|
fields: ["id"], |
|
87
|
}, |
|
88
|
sales_channel: { |
|
89
|
fields: ["id"], |
|
90
|
}, |
|
91
|
payment_collection: { |
|
92
|
fields: ["id"], |
|
93
|
payment_sessions: { |
|
94
|
fields: ["id"], |
|
95
|
}, |
|
96
|
}, |
|
97
|
}, |
|
98
|
}) |
|
99
|
|
|
100
|
const salesChannels = await remoteQuery({ |
|
101
|
sales_channel: { |
|
102
|
fields: ["id"], |
|
103
|
carts: { |
|
104
|
fields: ["id"], |
|
105
|
}, |
|
106
|
}, |
|
107
|
}) |
|
108
|
|
|
109
|
const customers = await remoteQuery({ |
|
110
|
customer: { |
|
111
|
fields: ["id"], |
|
112
|
carts: { |
|
113
|
fields: ["id"], |
|
114
|
}, |
|
115
|
}, |
|
116
|
}) |
|
117
|
|
|
118
|
const regions = await remoteQuery({ |
|
119
|
region: { |
|
120
|
fields: ["id"], |
|
121
|
carts: { |
|
122
|
fields: ["id"], |
|
123
|
}, |
|
124
|
}, |
|
125
|
}) |
|
126
|
|
|
127
|
const paymentCollections = await remoteQuery({ |
|
128
|
payment_collection: { |
|
129
|
fields: ["id"], |
|
130
|
cart: { |
|
131
|
fields: ["id"], |
|
132
|
}, |
|
133
|
}, |
|
134
|
}) |
|
135
|
|
|
136
|
expect(carts).toEqual( |
|
137
|
expect.arrayContaining([ |
|
138
|
expect.objectContaining({ |
|
139
|
id: cart.id, |
|
140
|
customer: expect.objectContaining({ id: customer.id }), |
|
141
|
sales_channel: expect.objectContaining({ id: salesChannel.id }), |
|
142
|
region: expect.objectContaining({ id: region.id }), |
|
143
|
payment_collection: expect.objectContaining({ |
|
144
|
id: paymentCollection.id, |
|
145
|
payment_sessions: expect.arrayContaining([]), |
|
146
|
}), |
|
147
|
}), |
|
148
|
]) |
|
149
|
) |
|
150
|
|
|
151
|
expect(salesChannels).toEqual( |
|
152
|
expect.arrayContaining([ |
|
153
|
expect.objectContaining({ |
|
154
|
id: salesChannel.id, |
|
155
|
carts: expect.arrayContaining([ |
|
156
|
expect.objectContaining({ id: cart.id }), |
|
157
|
]), |
|
158
|
}), |
|
159
|
]) |
|
160
|
) |
|
161
|
|
|
162
|
expect(customers).toEqual( |
|
163
|
expect.arrayContaining([ |
|
164
|
expect.objectContaining({ |
|
165
|
id: customer.id, |
|
166
|
carts: expect.arrayContaining([ |
|
167
|
expect.objectContaining({ id: cart.id }), |
|
168
|
]), |
|
169
|
}), |
|
170
|
]) |
|
171
|
) |
|
172
|
|
|
173
|
expect(regions).toEqual( |
|
174
|
expect.arrayContaining([ |
|
175
|
expect.objectContaining({ |
|
176
|
id: region.id, |
|
177
|
carts: expect.arrayContaining([ |
|
178
|
expect.objectContaining({ id: cart.id }), |
|
179
|
]), |
|
180
|
}), |
|
181
|
]) |
|
182
|
) |
|
183
|
|
|
184
|
expect(paymentCollections).toEqual( |
|
185
|
expect.arrayContaining([ |
|
186
|
expect.objectContaining({ |
|
187
|
id: paymentCollection.id, |
|
188
|
cart: expect.objectContaining({ id: cart.id }), |
|
189
|
}), |
|
190
|
]) |
|
191
|
) |
|
192
|
}) |
|
193
|
}) |
|
194
|
}, |
|
195
|
}) |