All tests passing
This commit is contained in:
@@ -21,6 +21,7 @@ describe("POST /admin/orders", () => {
|
||||
country_code: "US",
|
||||
province: "CA",
|
||||
postal_code: "93011",
|
||||
phone: "+1 (222) 333 4444",
|
||||
},
|
||||
shipping_address: {
|
||||
first_name: "Virgil",
|
||||
@@ -30,6 +31,7 @@ describe("POST /admin/orders", () => {
|
||||
country_code: "US",
|
||||
province: "CA",
|
||||
postal_code: "93011",
|
||||
phone: "+1 (222) 333 4444",
|
||||
},
|
||||
items: [
|
||||
{
|
||||
@@ -90,6 +92,7 @@ describe("POST /admin/orders", () => {
|
||||
country_code: "US",
|
||||
province: "CA",
|
||||
postal_code: "93011",
|
||||
phone: "+1 (222) 333 4444",
|
||||
},
|
||||
shipping_address: {
|
||||
first_name: "Virgil",
|
||||
@@ -99,6 +102,7 @@ describe("POST /admin/orders", () => {
|
||||
country_code: "US",
|
||||
province: "CA",
|
||||
postal_code: "93011",
|
||||
phone: "+1 (222) 333 4444",
|
||||
},
|
||||
items: [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { ProductServiceMock } from "../../../../../services/__mocks__/product"
|
||||
import {
|
||||
ProductServiceMock,
|
||||
products,
|
||||
} from "../../../../../services/__mocks__/product"
|
||||
|
||||
describe("DELETE /admin/products/:id/options/:optionId", () => {
|
||||
describe("successfully updates an option", () => {
|
||||
@@ -28,6 +31,7 @@ describe("DELETE /admin/products/:id/options/:optionId", () => {
|
||||
option_id: IdMap.getId("option1"),
|
||||
object: "option",
|
||||
deleted: true,
|
||||
product: products.productWithOptions,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -46,7 +46,9 @@ export default async (req, res) => {
|
||||
const productService = req.scope.resolve("productService")
|
||||
const shippingProfileService = req.scope.resolve("shippingProfileService")
|
||||
|
||||
value.thumbnail = value.thumbnail || value.images[0]
|
||||
if (!value.thumbnail && value.images && value.images.length) {
|
||||
value.thumbnail = value.images[0]
|
||||
}
|
||||
let newProduct = await productService.createDraft(value)
|
||||
|
||||
if (variants) {
|
||||
|
||||
@@ -52,8 +52,13 @@ export default async (req, res) => {
|
||||
const productService = req.scope.resolve("productService")
|
||||
const oldProduct = await productService.retrieve(id)
|
||||
|
||||
if (!oldProduct.thumbnail && value.images) {
|
||||
value.thumbnail = value.thumbnail || value.images[0]
|
||||
if (
|
||||
!oldProduct.thumbnail &&
|
||||
!value.thumbnail &&
|
||||
value.images &&
|
||||
value.images.length
|
||||
) {
|
||||
value.thumbnail = value.images[0]
|
||||
}
|
||||
|
||||
const product = await productService.update(oldProduct._id, value)
|
||||
|
||||
@@ -22,6 +22,8 @@ describe("POST /store/carts", () => {
|
||||
it("calls CartService create", () => {
|
||||
expect(CartServiceMock.create).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.create).toHaveBeenCalledWith({
|
||||
email: "",
|
||||
customer_id: "",
|
||||
region_id: IdMap.getId("testRegion"),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,6 +14,7 @@ describe("POST /store/carts/:id", () => {
|
||||
city: "Los Angeles",
|
||||
province: "CA",
|
||||
postal_code: "91092",
|
||||
phone: "+1 (222) 333 4444",
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -73,8 +74,8 @@ describe("POST /store/carts/:id", () => {
|
||||
})
|
||||
|
||||
it("applies promo code", () => {
|
||||
expect(CartServiceMock.applyPromoCode).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.applyPromoCode).toHaveBeenCalledWith(
|
||||
expect(CartServiceMock.applyDiscount).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.applyDiscount).toHaveBeenCalledWith(
|
||||
IdMap.getId("emptyCart"),
|
||||
"TESTCODE"
|
||||
)
|
||||
|
||||
@@ -8,14 +8,13 @@ describe("POST /store/carts/:id/line-items/:line_id", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
const cartId = IdMap.getId("emptyCart")
|
||||
const cartId = IdMap.getId("fr-cart")
|
||||
const lineId = IdMap.getId("existingLine")
|
||||
subject = await request(
|
||||
"POST",
|
||||
`/store/carts/${cartId}/line-items/${lineId}`,
|
||||
{
|
||||
payload: {
|
||||
variant_id: IdMap.getId("can-cover"),
|
||||
quantity: 3,
|
||||
},
|
||||
}
|
||||
@@ -33,9 +32,9 @@ describe("POST /store/carts/:id/line-items/:line_id", () => {
|
||||
it("calls LineItemService generate", () => {
|
||||
expect(LineItemServiceMock.generate).toHaveBeenCalledTimes(1)
|
||||
expect(LineItemServiceMock.generate).toHaveBeenCalledWith(
|
||||
IdMap.getId("can-cover"),
|
||||
3,
|
||||
IdMap.getId("testRegion")
|
||||
IdMap.getId("eur-10-us-12"),
|
||||
IdMap.getId("region-france"),
|
||||
3
|
||||
)
|
||||
})
|
||||
|
||||
@@ -44,25 +43,23 @@ describe("POST /store/carts/:id/line-items/:line_id", () => {
|
||||
})
|
||||
|
||||
it("returns the cart", () => {
|
||||
expect(subject.body.cart._id).toEqual(IdMap.getId("emptyCart"))
|
||||
expect(subject.body.cart._id).toEqual(IdMap.getId("fr-cart"))
|
||||
expect(subject.body.cart.decorated).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("handles unsuccessful line item generation", () => {
|
||||
describe("removes line item on quantity 0", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
const cartId = IdMap.getId("emptyCart")
|
||||
const cartId = IdMap.getId("fr-cart")
|
||||
const lineId = IdMap.getId("existingLine")
|
||||
|
||||
subject = await request(
|
||||
"POST",
|
||||
`/store/carts/${cartId}/line-items/${lineId}`,
|
||||
{
|
||||
payload: {
|
||||
variant_id: IdMap.getId("fail"),
|
||||
quantity: 3,
|
||||
quantity: 0,
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -72,21 +69,21 @@ describe("POST /store/carts/:id/line-items/:line_id", () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("calls LineItemService generate", () => {
|
||||
expect(LineItemServiceMock.generate).toHaveBeenCalledTimes(1)
|
||||
expect(LineItemServiceMock.generate).toHaveBeenCalledWith(
|
||||
IdMap.getId("fail"),
|
||||
3,
|
||||
IdMap.getId("testRegion")
|
||||
it("calls CartService create", () => {
|
||||
expect(CartServiceMock.removeLineItem).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.removeLineItem).toHaveBeenCalledWith(
|
||||
IdMap.getId("fr-cart"),
|
||||
IdMap.getId("existingLine")
|
||||
)
|
||||
})
|
||||
|
||||
it("returns 400", () => {
|
||||
expect(subject.status).toEqual(400)
|
||||
it("returns 200", () => {
|
||||
expect(subject.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("returns error", () => {
|
||||
expect(subject.body.message).toEqual("Doesn't exist")
|
||||
it("returns the cart", () => {
|
||||
expect(subject.body.cart._id).toEqual(IdMap.getId("fr-cart"))
|
||||
expect(subject.body.cart.decorated).toEqual(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,6 +12,9 @@ describe("POST /store/carts/:id/payment-method", () => {
|
||||
subject = await request("POST", `/store/carts/${cartId}/payment-method`, {
|
||||
payload: {
|
||||
provider_id: "default_provider",
|
||||
data: {
|
||||
money_id: "success",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -20,14 +23,6 @@ describe("POST /store/carts/:id/payment-method", () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("calls CartService retrievePaymentSession", () => {
|
||||
expect(CartServiceMock.retrievePaymentSession).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.retrievePaymentSession).toHaveBeenCalledWith(
|
||||
IdMap.getId("cartWithPaySessions"),
|
||||
"default_provider"
|
||||
)
|
||||
})
|
||||
|
||||
it("calls CartService setPaymentMethod", () => {
|
||||
expect(CartServiceMock.setPaymentMethod).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.setPaymentMethod).toHaveBeenCalledWith(
|
||||
@@ -50,50 +45,4 @@ describe("POST /store/carts/:id/payment-method", () => {
|
||||
expect(subject.body.cart.decorated).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("fails when pay session not authorized", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
const cartId = IdMap.getId("cartWithPaySessions")
|
||||
subject = await request("POST", `/store/carts/${cartId}/payment-method`, {
|
||||
payload: {
|
||||
provider_id: "nono",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("calls CartService retrievePaymentSession", () => {
|
||||
expect(CartServiceMock.retrievePaymentSession).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.retrievePaymentSession).toHaveBeenCalledWith(
|
||||
IdMap.getId("cartWithPaySessions"),
|
||||
"nono"
|
||||
)
|
||||
})
|
||||
|
||||
it("calls CartService setPaymentMethod", () => {
|
||||
expect(CartServiceMock.setPaymentMethod).toHaveBeenCalledTimes(1)
|
||||
expect(CartServiceMock.setPaymentMethod).toHaveBeenCalledWith(
|
||||
IdMap.getId("cartWithPaySessions"),
|
||||
{
|
||||
provider_id: "nono",
|
||||
data: {
|
||||
money_id: "fail",
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("returns 400", () => {
|
||||
expect(subject.status).toEqual(400)
|
||||
})
|
||||
|
||||
it("returns the cart", () => {
|
||||
expect(subject.body.message).toEqual("Not allowed")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,6 +9,7 @@ export default async (req, res) => {
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
console.log(error)
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
@@ -23,6 +24,13 @@ export default async (req, res) => {
|
||||
cart = await cartService.retrieve(id)
|
||||
|
||||
const existing = cart.items.find(i => i._id.equals(line_id))
|
||||
if (!existing) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"Could not find the line item"
|
||||
)
|
||||
}
|
||||
|
||||
const lineItem = await lineItemService.generate(
|
||||
existing.content.variant._id,
|
||||
cart.region_id,
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { CustomerServiceMock } from "../../../../../services/__mocks__/customer"
|
||||
|
||||
describe("POST /store/customers/:id/password", () => {
|
||||
describe("successfully updates a customer", () => {
|
||||
let subject
|
||||
beforeAll(async () => {
|
||||
subject = await request(
|
||||
"POST",
|
||||
`/store/customers/${IdMap.getId("lebron")}/password`,
|
||||
{
|
||||
payload: {
|
||||
password: "NewPass",
|
||||
},
|
||||
clientSession: {
|
||||
jwt: {
|
||||
customer_id: IdMap.getId("lebron"),
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("calls CustomerService update", () => {
|
||||
expect(CustomerServiceMock.update).toHaveBeenCalledTimes(1)
|
||||
expect(CustomerServiceMock.update).toHaveBeenCalledWith(
|
||||
IdMap.getId("lebron"),
|
||||
{
|
||||
password: "NewPass",
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("returns product decorated", () => {
|
||||
expect(subject.body.customer.first_name).toEqual("LeBron")
|
||||
expect(subject.body.customer.decorated).toEqual(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("fails if not authenticated", () => {
|
||||
let subject
|
||||
beforeAll(async () => {
|
||||
subject = await request(
|
||||
"POST",
|
||||
`/store/customers/${IdMap.getId("customer1")}/password`,
|
||||
{
|
||||
payload: {
|
||||
first_name: "LeBron",
|
||||
last_name: "James",
|
||||
},
|
||||
clientSession: {
|
||||
jwt: {
|
||||
customer_id: IdMap.getId("lebron"),
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("status code 400", () => {
|
||||
expect(subject.status).toEqual(400)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -12,11 +12,6 @@ describe("POST /store/orders", () => {
|
||||
payload: {
|
||||
cartId: IdMap.getId("fr-cart"),
|
||||
},
|
||||
adminSession: {
|
||||
jwt: {
|
||||
userId: IdMap.getId("admin_user"),
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -25,8 +20,8 @@ describe("POST /store/orders", () => {
|
||||
})
|
||||
|
||||
it("calls service create", () => {
|
||||
expect(OrderServiceMock.create).toHaveBeenCalledTimes(1)
|
||||
expect(OrderServiceMock.create).toHaveBeenCalledWith(carts.frCart)
|
||||
expect(OrderServiceMock.createFromCart).toHaveBeenCalledTimes(1)
|
||||
expect(OrderServiceMock.createFromCart).toHaveBeenCalledWith(carts.frCart)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,8 +16,6 @@ export default async (req, res) => {
|
||||
|
||||
const cart = await cartService.retrieve(value.cartId)
|
||||
let order = await orderService.createFromCart(cart)
|
||||
|
||||
order = await orderService.retrieveByCartId(value.cartId)
|
||||
order = await orderService.decorate(order, [
|
||||
"status",
|
||||
"fulfillment_status",
|
||||
@@ -36,6 +34,7 @@ export default async (req, res) => {
|
||||
|
||||
res.status(200).json({ order })
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
// If something fails it might be because the order has already been created
|
||||
// if it has we find it from the cart id
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
|
||||
+4
-5
@@ -8,11 +8,10 @@ describe("GET /store/shipping-options", () => {
|
||||
let subject
|
||||
|
||||
beforeAll(async () => {
|
||||
subject = await request("GET", `/store/shipping-options`, {
|
||||
payload: {
|
||||
cart_id: IdMap.getId("emptyCart"),
|
||||
},
|
||||
})
|
||||
subject = await request(
|
||||
"GET",
|
||||
`/store/shipping-options/${IdMap.getId("emptyCart")}`
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
Reference in New Issue
Block a user