|
1
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils" |
|
2
|
import { IStoreModuleService } from "@medusajs/types" |
|
3
|
import { Modules } from "@medusajs/utils" |
|
4
|
import { createAdminUser } from "../../../../helpers/create-admin-user" |
|
5
|
|
|
6
|
jest.setTimeout(50000) |
|
7
|
|
|
8
|
const env = {} |
|
9
|
const adminHeaders = { |
|
10
|
headers: { "x-medusa-access-token": "test_token" }, |
|
11
|
} |
|
12
|
|
|
13
|
medusaIntegrationTestRunner({ |
|
14
|
env, |
|
15
|
testSuite: ({ dbConnection, getContainer, api, dbUtils }) => { |
|
16
|
describe("Store - Admin", () => { |
|
17
|
let appContainer |
|
18
|
let service: IStoreModuleService |
|
19
|
|
|
20
|
beforeAll(async () => { |
|
21
|
appContainer = getContainer() |
|
22
|
service = appContainer.resolve(Modules.STORE) |
|
23
|
}) |
|
24
|
|
|
25
|
beforeAll(async () => { |
|
26
|
await createAdminUser(dbConnection, adminHeaders, appContainer) |
|
27
|
|
|
28
|
await dbUtils.snapshot() |
|
29
|
}) |
|
30
|
|
|
31
|
it("should correctly implement the entire lifecycle of a store", async () => { |
|
32
|
const createdStore = await service.createStores({ |
|
33
|
name: "Test store", |
|
34
|
supported_currencies: [{ currency_code: "usd", is_default: true }], |
|
35
|
}) |
|
36
|
|
|
37
|
expect(createdStore).toEqual( |
|
38
|
expect.objectContaining({ |
|
39
|
id: createdStore.id, |
|
40
|
supported_currencies: [ |
|
41
|
expect.objectContaining({ |
|
42
|
currency_code: "usd", |
|
43
|
is_default: true, |
|
44
|
}), |
|
45
|
], |
|
46
|
name: "Test store", |
|
47
|
}) |
|
48
|
) |
|
49
|
|
|
50
|
const updated = await api.post( |
|
51
|
`/admin/stores/${createdStore.id}`, |
|
52
|
{ |
|
53
|
name: "Updated store", |
|
54
|
}, |
|
55
|
adminHeaders |
|
56
|
) |
|
57
|
|
|
58
|
expect(updated.status).toEqual(200) |
|
59
|
expect(updated.data.store).toEqual( |
|
60
|
expect.objectContaining({ |
|
61
|
id: createdStore.id, |
|
62
|
name: "Updated store", |
|
63
|
}) |
|
64
|
) |
|
65
|
|
|
66
|
await service.deleteStores(createdStore.id) |
|
67
|
const listedStores = await api.get( |
|
68
|
`/admin/stores?id=${createdStore.id}`, |
|
69
|
adminHeaders |
|
70
|
) |
|
71
|
expect(listedStores.data.stores).toHaveLength(0) |
|
72
|
}) |
|
73
|
}) |
|
74
|
}, |
|
75
|
}) |