Merge branch 'develop' into fix-cartServiceCreateLostShippingAddress
This commit is contained in:
@@ -211,6 +211,117 @@ describe("/admin/price-lists", () => {
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("given a search query, returns matching results by name", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/price-lists?q=winter", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(err.response.data)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_lists).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "VIP winter sale",
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(response.data.count).toEqual(1)
|
||||
})
|
||||
|
||||
it("given a search query, returns matching results by description", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/price-lists?q=25%", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(err.response.data)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_lists).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "VIP winter sale",
|
||||
description:
|
||||
"Winter sale for VIP customers. 25% off selected items.",
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(response.data.count).toEqual(1)
|
||||
})
|
||||
|
||||
it("given a search query, returns empty list when does not exist", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/price-lists?q=blablabla", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(err.response.data)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_lists).toEqual([])
|
||||
expect(response.data.count).toEqual(0)
|
||||
})
|
||||
|
||||
it("given a search query and a status filter not matching any price list, returns an empty set", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/price-lists?q=vip&status[]=draft", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(err.response.data)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_lists).toEqual([])
|
||||
expect(response.data.count).toEqual(0)
|
||||
})
|
||||
|
||||
it("given a search query and a status filter matching a price list, returns a price list", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/price-lists?q=vip&status[]=active", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(err.response.data)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_lists).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "VIP winter sale",
|
||||
status: "active",
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(response.data.count).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/price-lists/:id", () => {
|
||||
@@ -794,9 +905,17 @@ describe("/admin/price-lists", () => {
|
||||
|
||||
await simplePriceListFactory(dbConnection, {
|
||||
id: "test-list",
|
||||
customer_groups: ["test-group"],
|
||||
prices: [
|
||||
{ variant_id: "test-variant-1", currency_code: "usd", amount: 100 },
|
||||
{ variant_id: "test-variant-4", currency_code: "usd", amount: 100 },
|
||||
{ variant_id: "test-variant-1", currency_code: "usd", amount: 150 },
|
||||
{ variant_id: "test-variant-4", currency_code: "usd", amount: 150 },
|
||||
],
|
||||
})
|
||||
await simplePriceListFactory(dbConnection, {
|
||||
id: "test-list-2",
|
||||
prices: [
|
||||
{ variant_id: "test-variant-1", currency_code: "usd", amount: 200 },
|
||||
{ variant_id: "test-variant-4", currency_code: "usd", amount: 200 },
|
||||
],
|
||||
})
|
||||
} catch (err) {
|
||||
@@ -810,7 +929,7 @@ describe("/admin/price-lists", () => {
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("lists only product 1, 2", async () => {
|
||||
it("lists only product 1, 2 with price list prices", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
@@ -826,8 +945,50 @@ describe("/admin/price-lists", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(2)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({ id: "test-prod-1" }),
|
||||
expect.objectContaining({ id: "test-prod-2" }),
|
||||
expect.objectContaining({
|
||||
id: "test-prod-1",
|
||||
variants: [
|
||||
expect.objectContaining({
|
||||
id: "test-variant-1",
|
||||
prices: [
|
||||
expect.objectContaining({ currency_code: "usd", amount: 100 }),
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 150,
|
||||
price_list_id: "test-list",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-variant-2",
|
||||
prices: [
|
||||
expect.objectContaining({ currency_code: "usd", amount: 100 }),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-prod-2",
|
||||
variants: [
|
||||
expect.objectContaining({
|
||||
id: "test-variant-3",
|
||||
prices: [
|
||||
expect.objectContaining({ currency_code: "usd", amount: 100 }),
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-variant-4",
|
||||
prices: [
|
||||
expect.objectContaining({ currency_code: "usd", amount: 100 }),
|
||||
expect.objectContaining({
|
||||
currency_code: "usd",
|
||||
amount: 150,
|
||||
price_list_id: "test-list",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const productSeeder = require("../../helpers/product-seeder")
|
||||
const { ProductVariant } = require("@medusajs/medusa")
|
||||
const { ProductVariant, ProductOptionValue, MoneyAmount } = require("@medusajs/medusa")
|
||||
const priceListSeeder = require("../../helpers/price-list-seeder")
|
||||
|
||||
jest.setTimeout(50000)
|
||||
@@ -1737,6 +1737,177 @@ describe("/admin/products", () => {
|
||||
expect(variant).toEqual(undefined)
|
||||
})
|
||||
|
||||
it("successfully deletes a product variant and its associated option values", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Validate that the option value exists
|
||||
const optValPre = await dbConnection.manager.findOne(ProductOptionValue, {
|
||||
variant_id: "test-variant_2",
|
||||
})
|
||||
|
||||
expect(optValPre).not.toEqual(undefined)
|
||||
|
||||
// Soft delete the variant
|
||||
const response = await api.delete(
|
||||
"/admin/products/test-product/variants/test-variant_2",
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
// Validate that the option value was deleted
|
||||
const optValPost = await dbConnection.manager.findOne(
|
||||
ProductOptionValue,
|
||||
{
|
||||
variant_id: "test-variant_2",
|
||||
}
|
||||
)
|
||||
|
||||
expect(optValPost).toEqual(undefined)
|
||||
|
||||
// Validate that the option still exists in the DB with deleted_at
|
||||
const optValDeleted = await dbConnection.manager.findOne(ProductOptionValue, {
|
||||
variant_id: "test-variant_2",
|
||||
}, {
|
||||
withDeleted: true,
|
||||
})
|
||||
|
||||
expect(optValDeleted).toEqual(expect.objectContaining({
|
||||
deleted_at: expect.any(Date),
|
||||
variant_id: "test-variant_2",
|
||||
}))
|
||||
})
|
||||
|
||||
it("successfully deletes a product and any option value associated with one of its variants", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Validate that the option value exists
|
||||
const optValPre = await dbConnection.manager.findOne(ProductOptionValue, {
|
||||
variant_id: "test-variant_2",
|
||||
})
|
||||
|
||||
expect(optValPre).not.toEqual(undefined)
|
||||
|
||||
// Soft delete the product
|
||||
const response = await api.delete("/admin/products/test-product", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
// Validate that the option value has been deleted
|
||||
const optValPost = await dbConnection.manager.findOne(
|
||||
ProductOptionValue,
|
||||
{
|
||||
variant_id: "test-variant_2",
|
||||
}
|
||||
)
|
||||
|
||||
expect(optValPost).toEqual(undefined)
|
||||
|
||||
// Validate that the option still exists in the DB with deleted_at
|
||||
const optValDeleted = await dbConnection.manager.findOne(ProductOptionValue, {
|
||||
variant_id: "test-variant_2",
|
||||
}, {
|
||||
withDeleted: true,
|
||||
})
|
||||
|
||||
expect(optValDeleted).toEqual(expect.objectContaining({
|
||||
deleted_at: expect.any(Date),
|
||||
variant_id: "test-variant_2",
|
||||
}))
|
||||
})
|
||||
|
||||
it("successfully deletes a product variant and its associated prices", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Validate that the price exists
|
||||
const pricePre = await dbConnection.manager.findOne(MoneyAmount, {
|
||||
id: "test-price",
|
||||
})
|
||||
|
||||
expect(pricePre).not.toEqual(undefined)
|
||||
|
||||
// Soft delete the variant
|
||||
const response = await api.delete(
|
||||
"/admin/products/test-product/variants/test-variant",
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
// Validate that the price was deleted
|
||||
const pricePost = await dbConnection.manager.findOne(
|
||||
MoneyAmount,
|
||||
{
|
||||
id: "test-price",
|
||||
}
|
||||
)
|
||||
|
||||
expect(pricePost).toEqual(undefined)
|
||||
|
||||
// Validate that the price still exists in the DB with deleted_at
|
||||
const optValDeleted = await dbConnection.manager.findOne(MoneyAmount, {
|
||||
id: "test-price",
|
||||
}, {
|
||||
withDeleted: true,
|
||||
})
|
||||
|
||||
expect(optValDeleted).toEqual(expect.objectContaining({
|
||||
deleted_at: expect.any(Date),
|
||||
id: "test-price",
|
||||
}))
|
||||
})
|
||||
|
||||
it("successfully deletes a product and any prices associated with one of its variants", async () => {
|
||||
const api = useApi()
|
||||
|
||||
// Validate that the price exists
|
||||
const pricePre = await dbConnection.manager.findOne(MoneyAmount, {
|
||||
id: "test-price",
|
||||
})
|
||||
|
||||
expect(pricePre).not.toEqual(undefined)
|
||||
|
||||
// Soft delete the product
|
||||
const response = await api.delete("/admin/products/test-product", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
// Validate that the price has been deleted
|
||||
const pricePost = await dbConnection.manager.findOne(MoneyAmount, {
|
||||
id: "test-price",
|
||||
})
|
||||
|
||||
expect(pricePost).toEqual(undefined)
|
||||
|
||||
// Validate that the price still exists in the DB with deleted_at
|
||||
const optValDeleted = await dbConnection.manager.findOne(MoneyAmount, {
|
||||
id: "test-price",
|
||||
}, {
|
||||
withDeleted: true,
|
||||
})
|
||||
|
||||
expect(optValDeleted).toEqual(expect.objectContaining({
|
||||
deleted_at: expect.any(Date),
|
||||
id: "test-price",
|
||||
}))
|
||||
})
|
||||
|
||||
it("successfully creates product with soft-deleted product handle and deletes it again", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user