|
1
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils" |
|
2
|
import { |
|
3
|
adminHeaders, |
|
4
|
createAdminUser, |
|
5
|
} from "../../../../helpers/create-admin-user" |
|
6
|
|
|
7
|
jest.setTimeout(30000) |
|
8
|
|
|
9
|
medusaIntegrationTestRunner({ |
|
10
|
testSuite: ({ dbConnection, getContainer, api, dbUtils }) => { |
|
11
|
beforeAll(async () => { |
|
12
|
const appContainer = getContainer() |
|
13
|
await createAdminUser(dbConnection, adminHeaders, appContainer) |
|
14
|
|
|
15
|
await dbUtils.snapshot() |
|
16
|
}) |
|
17
|
|
|
18
|
describe("Admin - Shipping Profiles", () => { |
|
19
|
it("should test the entire lifecycle of a shipping profile", async () => { |
|
20
|
const payload = { |
|
21
|
name: "test-profile-2023", |
|
22
|
type: "custom", |
|
23
|
} |
|
24
|
|
|
25
|
// Create |
|
26
|
const { |
|
27
|
data: { shipping_profile }, |
|
28
|
status, |
|
29
|
} = await api.post("/admin/shipping-profiles", payload, adminHeaders) |
|
30
|
|
|
31
|
expect(status).toEqual(200) |
|
32
|
expect(shipping_profile).toEqual( |
|
33
|
expect.objectContaining({ |
|
34
|
id: expect.any(String), |
|
35
|
created_at: expect.any(String), |
|
36
|
updated_at: expect.any(String), |
|
37
|
...payload, |
|
38
|
}) |
|
39
|
) |
|
40
|
|
|
41
|
// List |
|
42
|
const { |
|
43
|
data: { shipping_profiles }, |
|
44
|
} = await api.get("/admin/shipping-profiles", adminHeaders) |
|
45
|
|
|
46
|
expect(shipping_profiles.length).toEqual(1) |
|
47
|
|
|
48
|
// Retrieve |
|
49
|
const { |
|
50
|
data: { shipping_profile: retrievedProfile }, |
|
51
|
} = await api.get( |
|
52
|
`/admin/shipping-profiles/${shipping_profile.id}`, |
|
53
|
adminHeaders |
|
54
|
) |
|
55
|
|
|
56
|
expect(status).toEqual(200) |
|
57
|
expect(retrievedProfile).toEqual( |
|
58
|
expect.objectContaining({ |
|
59
|
id: shipping_profile.id, |
|
60
|
updated_at: expect.any(String), |
|
61
|
created_at: expect.any(String), |
|
62
|
}) |
|
63
|
) |
|
64
|
|
|
65
|
// update |
|
66
|
const { |
|
67
|
data: { shipping_profile: updatedProfile }, |
|
68
|
} = await api.post( |
|
69
|
`/admin/shipping-profiles/${shipping_profile.id}`, |
|
70
|
{ |
|
71
|
name: "test-profile-updated", |
|
72
|
type: "express", |
|
73
|
metadata: { |
|
74
|
my_new_key: "my_new_value", |
|
75
|
}, |
|
76
|
}, |
|
77
|
adminHeaders |
|
78
|
) |
|
79
|
|
|
80
|
expect(status).toEqual(200) |
|
81
|
expect(updatedProfile).toEqual( |
|
82
|
expect.objectContaining({ |
|
83
|
id: shipping_profile.id, |
|
84
|
name: "test-profile-updated", |
|
85
|
type: "express", |
|
86
|
metadata: { |
|
87
|
my_new_key: "my_new_value", |
|
88
|
}, |
|
89
|
updated_at: expect.any(String), |
|
90
|
created_at: expect.any(String), |
|
91
|
}) |
|
92
|
) |
|
93
|
|
|
94
|
// Delete |
|
95
|
const { data } = await api.delete( |
|
96
|
`/admin/shipping-profiles/${shipping_profile.id}`, |
|
97
|
adminHeaders |
|
98
|
) |
|
99
|
|
|
100
|
expect(data).toEqual({ |
|
101
|
id: retrievedProfile.id, |
|
102
|
object: "shipping_profile", |
|
103
|
deleted: true, |
|
104
|
}) |
|
105
|
|
|
106
|
await api |
|
107
|
.get(`/admin/shipping-profiles/${shipping_profile.id}`, adminHeaders) |
|
108
|
.catch((err) => { |
|
109
|
expect(err.response.status).toEqual(404) |
|
110
|
}) |
|
111
|
}) |
|
112
|
}) |
|
113
|
|
|
114
|
// TODO: Associate products with shipping profiles |
|
115
|
}, |
|
116
|
}) |