-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cart): Partial module service implementation (#6012)
Awaiting #6000 #6008 **What** - CRUD for Address in Cart Module service - Tests for CRUD Carts + Address **Not** - Line items, shipping methods, tax lines, adjustment lines
- Loading branch information
1 parent
8472460
commit 192bc33
Showing
16 changed files
with
433 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@medusajs/inventory": patch | ||
"@medusajs/stock-location": patch | ||
"@medusajs/types": patch | ||
--- | ||
|
||
feat(cart): Partial module service implementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
packages/cart/integration-tests/__tests__/services/cart-module/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
import { ICartModuleService } from "@medusajs/types" | ||
import { SqlEntityManager } from "@mikro-orm/postgresql" | ||
import { initialize } from "../../../../src/initialize" | ||
import { DB_URL, MikroOrmWrapper } from "../../../utils" | ||
|
||
jest.setTimeout(30000) | ||
|
||
describe("Cart Module Service", () => { | ||
let service: ICartModuleService | ||
let repositoryManager: SqlEntityManager | ||
|
||
beforeEach(async () => { | ||
await MikroOrmWrapper.setupDatabase() | ||
repositoryManager = await MikroOrmWrapper.forkManager() | ||
|
||
service = await initialize({ | ||
database: { | ||
clientUrl: DB_URL, | ||
schema: process.env.MEDUSA_CART_DB_SCHEMA, | ||
}, | ||
}) | ||
}) | ||
|
||
afterEach(async () => { | ||
await MikroOrmWrapper.clearDatabase() | ||
}) | ||
|
||
describe("create", () => { | ||
it("should throw an error when required params are not passed", async () => { | ||
const error = await service | ||
.create([ | ||
{ | ||
email: "test@email.com", | ||
} as any, | ||
]) | ||
.catch((e) => e) | ||
|
||
expect(error.message).toContain( | ||
"Value for Cart.currency_code is required, 'undefined' found" | ||
) | ||
}) | ||
|
||
it("should create a cart successfully", async () => { | ||
const [createdCart] = await service.create([ | ||
{ | ||
currency_code: "eur", | ||
}, | ||
]) | ||
|
||
const [cart] = await service.list({ id: [createdCart.id] }) | ||
|
||
expect(cart).toEqual( | ||
expect.objectContaining({ | ||
id: createdCart.id, | ||
currency_code: "eur", | ||
}) | ||
) | ||
}) | ||
|
||
it("should create a cart with billing + shipping address successfully", async () => { | ||
const [createdCart] = await service.create([ | ||
{ | ||
currency_code: "eur", | ||
billing_address: { | ||
first_name: "John", | ||
last_name: "Doe", | ||
}, | ||
shipping_address: { | ||
first_name: "John", | ||
last_name: "Doe", | ||
}, | ||
}, | ||
]) | ||
|
||
const [cart] = await service.list( | ||
{ id: [createdCart.id] }, | ||
{ relations: ["billing_address", "shipping_address"] } | ||
) | ||
|
||
expect(cart).toEqual( | ||
expect.objectContaining({ | ||
id: createdCart.id, | ||
currency_code: "eur", | ||
billing_address: expect.objectContaining({ | ||
first_name: "John", | ||
last_name: "Doe", | ||
}), | ||
shipping_address: expect.objectContaining({ | ||
first_name: "John", | ||
last_name: "Doe", | ||
}), | ||
}) | ||
) | ||
}) | ||
|
||
it("should create a cart with billing id + shipping id successfully", async () => { | ||
const [createdAddress] = await service.createAddresses([ | ||
{ | ||
first_name: "John", | ||
last_name: "Doe", | ||
}, | ||
]) | ||
|
||
const [createdCart] = await service.create([ | ||
{ | ||
currency_code: "eur", | ||
billing_address_id: createdAddress.id, | ||
shipping_address_id: createdAddress.id, | ||
}, | ||
]) | ||
|
||
expect(createdCart).toEqual( | ||
expect.objectContaining({ | ||
id: createdCart.id, | ||
currency_code: "eur", | ||
billing_address: expect.objectContaining({ | ||
id: createdAddress.id, | ||
first_name: "John", | ||
last_name: "Doe", | ||
}), | ||
shipping_address: expect.objectContaining({ | ||
id: createdAddress.id, | ||
first_name: "John", | ||
last_name: "Doe", | ||
}), | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe("update", () => { | ||
it("should throw an error if cart does not exist", async () => { | ||
const error = await service | ||
.update([ | ||
{ | ||
id: "none-existing", | ||
}, | ||
]) | ||
.catch((e) => e) | ||
|
||
expect(error.message).toContain('Cart with id "none-existing" not found') | ||
}) | ||
|
||
it("should update a cart successfully", async () => { | ||
const [createdCart] = await service.create([ | ||
{ | ||
currency_code: "eur", | ||
}, | ||
]) | ||
|
||
const [updatedCart] = await service.update([ | ||
{ | ||
id: createdCart.id, | ||
email: "test@email.com", | ||
}, | ||
]) | ||
|
||
const [cart] = await service.list({ id: [createdCart.id] }) | ||
|
||
expect(cart).toEqual( | ||
expect.objectContaining({ | ||
id: createdCart.id, | ||
currency_code: "eur", | ||
email: updatedCart.email, | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe("delete", () => { | ||
it("should delete a cart successfully", async () => { | ||
const [createdCart] = await service.create([ | ||
{ | ||
currency_code: "eur", | ||
}, | ||
]) | ||
|
||
await service.delete([createdCart.id]) | ||
|
||
const carts = await service.list({ id: [createdCart.id] }) | ||
|
||
expect(carts.length).toEqual(0) | ||
}) | ||
}) | ||
|
||
describe("createAddresses", () => { | ||
it("should create an address successfully", async () => { | ||
const [createdAddress] = await service.createAddresses([ | ||
{ | ||
first_name: "John", | ||
}, | ||
]) | ||
|
||
const [address] = await service.listAddresses({ | ||
id: [createdAddress.id!], | ||
}) | ||
|
||
expect(address).toEqual( | ||
expect.objectContaining({ | ||
id: createdAddress.id, | ||
first_name: "John", | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe("updateAddresses", () => { | ||
it("should update an address successfully", async () => { | ||
const [createdAddress] = await service.createAddresses([ | ||
{ | ||
first_name: "John", | ||
}, | ||
]) | ||
|
||
const [updatedAddress] = await service.updateAddresses([ | ||
{ id: createdAddress.id!, first_name: "Jane" }, | ||
]) | ||
|
||
expect(updatedAddress).toEqual( | ||
expect.objectContaining({ | ||
id: createdAddress.id, | ||
first_name: "Jane", | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe("deleteAddresses", () => { | ||
it("should delete an address successfully", async () => { | ||
const [createdAddress] = await service.createAddresses([ | ||
{ | ||
first_name: "John", | ||
}, | ||
]) | ||
|
||
await service.deleteAddresses([createdAddress.id!]) | ||
|
||
const [address] = await service.listAddresses({ | ||
id: [createdAddress.id!], | ||
}) | ||
|
||
expect(address).toBe(undefined) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
192bc33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
medusa-dashboard – ./packages/admin-next/dashboard
medusa-dashboard-git-develop-medusajs.vercel.app
medusa-dashboard-medusajs.vercel.app
medusa-dashboard.vercel.app
admin-preview.medusajs.com