1 import { IAuthModuleService } from "@medusajs/types"
2
3 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
4 import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
5 import jwt from "jsonwebtoken"
6 import {
7 adminHeaders,
8 createAdminUser,
9 generatePublishableKey,
10 generateStoreHeaders,
11 } from "../../../../helpers/create-admin-user"
12
13 jest.setTimeout(50000)
14
15 const env = {}
16
17 medusaIntegrationTestRunner({
18 env,
19 testSuite: ({ dbConnection, getContainer, api, dbUtils }) => {
20 describe("POST /store/customers", () => {
21 let appContainer
22 let storeHeaders
23
24 beforeAll(async () => {
25 appContainer = getContainer()
26 await createAdminUser(dbConnection, adminHeaders, appContainer)
27 const publishableKey = await generatePublishableKey(appContainer)
28 storeHeaders = generateStoreHeaders({ publishableKey })
29
30 await dbUtils.snapshot()
31 })
32
33 // TODO: Reenable once the customer authentication is fixed, and use the HTTP endpoints instead.
34 it.skip("should create a customer", async () => {
35 const authService: IAuthModuleService = appContainer.resolve(
36 Modules.AUTH
37 )
38 const { http } = appContainer.resolve(
39 ContainerRegistrationKeys.CONFIG_MODULE
40 ).projectConfig
41 const authIdentity = await authService.createAuthIdentities({
42 provider_identities: [
43 {
44 entity_id: "store_user",
45 provider: "emailpass",
46 },
47 ],
48 })
49
50 const token = jwt.sign(authIdentity, http.jwtSecret)
51
52 const response = await api.post(
53 `/store/customers`,
54 {
55 first_name: "John",
56 last_name: "Doe",
57 email: "john@me.com",
58 },
59 {
60 headers: {
61 authorization: `Bearer ${token}`,
62 ...storeHeaders.headers,
63 },
64 }
65 )
66
67 expect(response.status).toEqual(200)
68 expect(response.data.customer).toEqual(
69 expect.objectContaining({
70 id: expect.any(String),
71 first_name: "John",
72 last_name: "Doe",
73 email: "john@me.com",
74 })
75 )
76 })
77 })
78 },
79 })