feat(cart): POST /store/carts/:id (#6274)

Depends on:
- #6262 
- #6273
This commit is contained in:
Oli Juhl
2024-02-14 16:03:02 +01:00
committed by GitHub
parent 6500f18b9b
commit 1ed5f918c3
17 changed files with 378 additions and 49 deletions

View File

@@ -0,0 +1,63 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICartModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
describe("POST /store/carts/:id", () => {
let dbConnection
let appContainer
let shutdownServer
let cartModuleService: ICartModuleService
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
cartModuleService = appContainer.resolve(ModuleRegistrationName.CART)
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})
beforeEach(async () => {
await adminSeeder(dbConnection)
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should create a cart", async () => {
const api = useApi() as any
const cart = await cartModuleService.create({
currency_code: "usd",
})
const response = await api.post(`/store/carts/${cart.id}`, {
email: "tony@stark.com",
})
expect(response.status).toEqual(200)
expect(response.data.cart).toEqual(
expect.objectContaining({
id: cart.id,
currency_code: "usd",
email: "tony@stark.com",
})
)
})
})