1 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
2 import { createAdminUser } from "../../../../helpers/create-admin-user"
3
4 jest.setTimeout(50000)
5
6 const env = {}
7 const adminHeaders = {
8 headers: { "x-medusa-access-token": "test_token" },
9 }
10
11 medusaIntegrationTestRunner({
12 env,
13 testSuite: ({ dbConnection, api, getContainer, dbUtils }) => {
14 describe("Currency - Admin", () => {
15 let container
16
17 beforeAll(async () => {
18 container = getContainer()
19 await createAdminUser(dbConnection, adminHeaders, container)
20
21 await dbUtils.snapshot()
22 })
23
24 it("should correctly retrieve and list currencies", async () => {
25 const listResp = await api.get("/admin/currencies", adminHeaders)
26
27 expect(listResp.data.currencies).toEqual(
28 expect.arrayContaining([
29 expect.objectContaining({
30 code: "aud",
31 }),
32 expect.objectContaining({
33 code: "cad",
34 }),
35 ])
36 )
37
38 const retrieveResp = await api.get(
39 `/admin/currencies/aud`,
40 adminHeaders
41 )
42 expect(retrieveResp.data.currency).toEqual(
43 listResp.data.currencies.find((c) => c.code === "aud")
44 )
45 })
46
47 it("should correctly list currencies in the correct order", async () => {
48 const listResp = await api.get(
49 "/admin/currencies?order=-code",
50 adminHeaders
51 )
52
53 const first = listResp.data.currencies.shift()
54 expect(first).toEqual(
55 expect.objectContaining({ code: "zwl", name: "Zimbabwean Dollar" })
56 )
57 })
58
59 it("should allow for searching of currencies", async () => {
60 const listResp = await api.get(
61 "/admin/currencies?q=zimbabwean",
62 adminHeaders
63 )
64
65 expect(listResp.data.currencies).toEqual(
66 expect.arrayContaining([
67 expect.objectContaining({ code: "zwl", name: "Zimbabwean Dollar" }),
68 ])
69 )
70 })
71 })
72 },
73 })