chore(integration-tests): Fixed merge conflict
This commit is contained in:
@@ -331,12 +331,15 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.discounts).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "fixed-discount",
|
||||
code: "fixed100",
|
||||
}),
|
||||
])
|
||||
expect(response.data.discounts).toHaveLength(1)
|
||||
expect(response.data.discounts).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "fixed-discount",
|
||||
code: "fixed100",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("fails when listing invalid discount types", async () => {
|
||||
@@ -394,12 +397,15 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.discounts).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "dynamic-discount",
|
||||
code: "Dyn100",
|
||||
}),
|
||||
])
|
||||
expect(response.data.discounts).toHaveLength(1)
|
||||
expect(response.data.discounts).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "dynamic-discount",
|
||||
code: "Dyn100",
|
||||
})
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("lists disabled discounts ", async () => {
|
||||
@@ -416,12 +422,15 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.discounts).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "disabled-discount",
|
||||
code: "Dis100",
|
||||
}),
|
||||
])
|
||||
expect(response.data.discounts).toHaveLength(1)
|
||||
expect(response.data.discounts).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "disabled-discount",
|
||||
code: "Dis100",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -609,16 +618,19 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.discount.rule.conditions).toEqual([
|
||||
expect.objectContaining({
|
||||
type: "products",
|
||||
operator: "in",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
type: "product_types",
|
||||
operator: "not_in",
|
||||
}),
|
||||
])
|
||||
expect(response.data.discount.rule.conditions).toHaveLength(2)
|
||||
expect(response.data.discount.rule.conditions).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type: "products",
|
||||
operator: "in",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
type: "product_types",
|
||||
operator: "not_in",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
const createdRule = response.data.discount.rule
|
||||
const condsToUpdate = createdRule.conditions[0]
|
||||
@@ -1468,6 +1480,70 @@ describe("/admin/discounts", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/discounts/:id", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await dbConnection.manager.insert(DiscountRule, {
|
||||
id: "test-discount-rule",
|
||||
description: "Test discount rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
})
|
||||
await dbConnection.manager.insert(Discount, {
|
||||
id: "test-discount",
|
||||
code: "TESTING",
|
||||
rule_id: "test-discount-rule",
|
||||
is_dynamic: false,
|
||||
is_disabled: false,
|
||||
ends_at: new Date(),
|
||||
usage_limit: 10,
|
||||
valid_duration: "P1D",
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("Removes ends_at, valid_duration and usage_limit when fields are updated with null", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await api
|
||||
.post(
|
||||
"/admin/discounts/test-discount",
|
||||
{
|
||||
ends_at: null,
|
||||
valid_duration: null,
|
||||
usage_limit: null,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
const resultingDiscount = await api.get(
|
||||
"/admin/discounts/test-discount",
|
||||
{ headers: { Authorization: "Bearer test_token" } }
|
||||
)
|
||||
|
||||
expect(resultingDiscount.status).toEqual(200)
|
||||
expect(resultingDiscount.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
ends_at: null,
|
||||
valid_duration: null,
|
||||
usage_limit: null,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("testing for soft-deletion + uniqueness on discount codes", () => {
|
||||
let manager
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -653,11 +653,14 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(updateData.order.claims[0].shipping_methods).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-method",
|
||||
}),
|
||||
])
|
||||
expect(updateData.order.claims[0].shipping_methods).toHaveLength(1)
|
||||
expect(updateData.order.claims[0].shipping_methods).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-method",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("updates claim items", async () => {
|
||||
@@ -807,19 +810,21 @@ describe("/admin/orders", () => {
|
||||
claim = updateData.order.claims[0]
|
||||
|
||||
expect(claim.claim_items.length).toEqual(1)
|
||||
expect(claim.claim_items).toEqual([
|
||||
expect.objectContaining({
|
||||
id: claim.claim_items[0].id,
|
||||
reason: "production_failure",
|
||||
note: "Something new",
|
||||
images: [],
|
||||
// tags: expect.arrayContaining([
|
||||
// expect.objectContaining({ value: "completely" }),
|
||||
// expect.objectContaining({ value: "new" }),
|
||||
// expect.objectContaining({ value: "tags" }),
|
||||
// ]),
|
||||
}),
|
||||
])
|
||||
expect(claim.claim_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: claim.claim_items[0].id,
|
||||
reason: "production_failure",
|
||||
note: "Something new",
|
||||
images: [],
|
||||
// tags: expect.arrayContaining([
|
||||
// expect.objectContaining({ value: "completely" }),
|
||||
// expect.objectContaining({ value: "new" }),
|
||||
// expect.objectContaining({ value: "tags" }),
|
||||
// ]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("fulfills a claim", async () => {
|
||||
@@ -872,27 +877,34 @@ describe("/admin/orders", () => {
|
||||
}
|
||||
)
|
||||
expect(fulRes.status).toEqual(200)
|
||||
expect(fulRes.data.order.claims).toEqual([
|
||||
expect.objectContaining({
|
||||
id: cid,
|
||||
order_id: "test-order",
|
||||
fulfillment_status: "fulfilled",
|
||||
}),
|
||||
])
|
||||
expect(fulRes.data.order.claims).toHaveLength(1)
|
||||
expect(fulRes.data.order.claims).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: cid,
|
||||
order_id: "test-order",
|
||||
fulfillment_status: "fulfilled",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
const fid = fulRes.data.order.claims[0].fulfillments[0].id
|
||||
const iid = fulRes.data.order.claims[0].additional_items[0].id
|
||||
expect(fulRes.data.order.claims[0].fulfillments).toEqual([
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
{
|
||||
fulfillment_id: fid,
|
||||
item_id: iid,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
|
||||
expect(fulRes.data.order.claims[0].fulfillments).toHaveLength(1)
|
||||
expect(fulRes.data.order.claims[0].fulfillments).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
items: [
|
||||
{
|
||||
fulfillment_id: fid,
|
||||
item_id: iid,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a claim on a claim additional item", async () => {
|
||||
@@ -1288,14 +1300,17 @@ describe("/admin/orders", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.order.returns[0].refund_amount).toEqual(7200)
|
||||
expect(response.data.order.returns[0].items).toEqual([
|
||||
expect.objectContaining({
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
note: "TOO SMALL",
|
||||
}),
|
||||
])
|
||||
expect(response.data.order.returns[0].items).toHaveLength(1)
|
||||
expect(response.data.order.returns[0].items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason_id: rrId,
|
||||
note: "TOO SMALL",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("increases inventory_quantity when return is received", async () => {
|
||||
@@ -1385,28 +1400,31 @@ describe("/admin/orders", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect(response.data.orders).toHaveLength(6)
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("lists all orders with a fulfillment status = fulfilled and payment status = captured", async () => {
|
||||
@@ -1424,14 +1442,17 @@ describe("/admin/orders", () => {
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
expect(response.data.orders).toHaveLength(2)
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("fails to lists all orders with an invalid status", async () => {
|
||||
@@ -1467,12 +1488,15 @@ describe("/admin/orders", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
email: "test@email.com",
|
||||
}),
|
||||
])
|
||||
expect(response.data.orders).toHaveLength(1)
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
email: "test@email.com",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("list all orders with matching shipping_address first name", async () => {
|
||||
@@ -1513,27 +1537,30 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
expect(response.data.orders).toHaveLength(6)
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("successfully lists no orders with greater than", async () => {
|
||||
@@ -1565,27 +1592,30 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
expect(response.data.orders).toHaveLength(6)
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("successfully lists no orders with less than", async () => {
|
||||
@@ -1617,27 +1647,30 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
expect(response.data.orders).toHaveLength(6)
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-c",
|
||||
}),
|
||||
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-s",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-f",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-order-w-r",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "discount-order",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it.each([
|
||||
@@ -1826,11 +1859,14 @@ describe("/admin/orders", () => {
|
||||
const cart = response.data.cart
|
||||
const items = cart.items
|
||||
const [returnItem] = items.filter((i) => i.is_return)
|
||||
expect(returnItem.adjustments).toEqual([
|
||||
expect.objectContaining({
|
||||
amount: -800,
|
||||
}),
|
||||
])
|
||||
expect(returnItem.adjustments).toHaveLength(1)
|
||||
expect(returnItem.adjustments).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
amount: -800,
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(cart.total).toBe(7200)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -353,10 +353,13 @@ describe("/admin/price-lists", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.price_lists.length).toEqual(2)
|
||||
expect(response.data.price_lists).toEqual([
|
||||
expect.objectContaining({ id: "test-list-cgroup-1" }),
|
||||
expect.objectContaining({ id: "test-list-cgroup-2" }),
|
||||
])
|
||||
expect(response.data.price_lists).toHaveLength(2)
|
||||
expect(response.data.price_lists).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: "test-list-cgroup-1" }),
|
||||
expect.objectContaining({ id: "test-list-cgroup-2" }),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1137,52 +1140,55 @@ 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",
|
||||
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",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(2)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
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",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("lists only product 2", async () => {
|
||||
@@ -1200,9 +1206,12 @@ describe("/admin/price-lists", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({ id: "test-prod-2" }),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: "test-prod-2" }),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("lists products using free text search", async () => {
|
||||
@@ -1220,12 +1229,15 @@ describe("/admin/price-lists", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-prod-1",
|
||||
title: "MedusaHeadphones",
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-prod-1",
|
||||
title: "MedusaHeadphones",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -160,16 +160,19 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
status: "proposed",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
status: "published",
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(2)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
status: "proposed",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
status: "published",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
for (const notExpect of notExpected) {
|
||||
expect(response.data.products).toEqual(
|
||||
@@ -199,16 +202,19 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
status: "proposed",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
status: "published",
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(2)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
status: "proposed",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_2",
|
||||
status: "published",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
for (const notExpect of notExpected) {
|
||||
expect(response.data.products).toEqual(
|
||||
@@ -232,11 +238,14 @@ describe("/admin/products", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_4",
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_4",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("returns a list of products with free text query and limit", async () => {
|
||||
@@ -317,11 +326,14 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_4",
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_4",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("returns a list of products in collection", async () => {
|
||||
@@ -343,16 +355,19 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_3",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(2)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_1",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_3",
|
||||
collection_id: "test-collection1",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
for (const notExpect of notExpected) {
|
||||
expect(response.data.products).toEqual(
|
||||
@@ -426,13 +441,16 @@ describe("/admin/products", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_3",
|
||||
collection_id: "test-collection1",
|
||||
tags: [expect.objectContaining({ id: "tag4" })],
|
||||
}),
|
||||
])
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-product_filtering_3",
|
||||
collection_id: "test-collection1",
|
||||
tags: [expect.objectContaining({ id: "tag4" })],
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
for (const notExpect of notExpectedCollections) {
|
||||
expect(response.data.products).toEqual(
|
||||
|
||||
@@ -157,17 +157,20 @@ describe("/admin/regions", () => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.data.regions).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-region-updated-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-region",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-region-updated",
|
||||
}),
|
||||
])
|
||||
expect(response.data.regions).toHaveLength(3)
|
||||
expect(response.data.regions).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-region-updated-1",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-region",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-region-updated",
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
@@ -184,14 +187,17 @@ describe("/admin/regions", () => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.data.regions).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-region",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-region-updated",
|
||||
}),
|
||||
])
|
||||
expect(response.data.regions).toHaveLength(2)
|
||||
expect(response.data.regions).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-region",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-region-updated",
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -350,20 +350,23 @@ describe("/admin/return-reasons", () => {
|
||||
|
||||
expect(nested_response.status).toEqual(200)
|
||||
|
||||
expect(nested_response.data.return_reasons).toEqual([
|
||||
expect.objectContaining({
|
||||
label: "Wrong size",
|
||||
description: "Use this if the size was too big",
|
||||
value: "wrong_size",
|
||||
return_reason_children: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
label: "Too Big",
|
||||
description: "Use this if the size was too big",
|
||||
value: "too_big",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
expect(nested_response.data.return_reasons).toHaveLength(1)
|
||||
expect(nested_response.data.return_reasons).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
label: "Wrong size",
|
||||
description: "Use this if the size was too big",
|
||||
value: "wrong_size",
|
||||
return_reason_children: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
label: "Too Big",
|
||||
description: "Use this if the size was too big",
|
||||
value: "too_big",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("list return reasons", async () => {
|
||||
@@ -396,11 +399,14 @@ describe("/admin/return-reasons", () => {
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.return_reasons).toEqual([
|
||||
expect.objectContaining({
|
||||
value: "too_big",
|
||||
}),
|
||||
])
|
||||
expect(response.data.return_reasons).toHaveLength(1)
|
||||
expect(response.data.return_reasons).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
value: "too_big",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -783,11 +783,13 @@ describe("sales channels", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.orders.length).toEqual(1)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: order.id,
|
||||
}),
|
||||
])
|
||||
expect(response.data.orders).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: order.id,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,6 +8,17 @@ const orderSeeder = require("../../helpers/order-seeder")
|
||||
const swapSeeder = require("../../helpers/swap-seeder")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
|
||||
const {
|
||||
simpleProductFactory,
|
||||
simpleCartFactory,
|
||||
simpleDiscountFactory,
|
||||
simpleRegionFactory,
|
||||
simpleShippingOptionFactory,
|
||||
} = require("../../factories")
|
||||
const {
|
||||
simpleCustomerFactory,
|
||||
} = require("../../factories/simple-customer-factory")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("/admin/swaps", () => {
|
||||
@@ -136,4 +147,208 @@ describe("/admin/swaps", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Complete swap flow", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("completes swap and ensures difference due", async () => {
|
||||
// ********* FACTORIES *********
|
||||
const prodA = await simpleProductFactory(dbConnection, {
|
||||
id: "prod-a",
|
||||
variants: [
|
||||
{ id: "prod-a-var", prices: [{ amount: 1000, currency: "dkk" }] },
|
||||
],
|
||||
})
|
||||
|
||||
await simpleProductFactory(dbConnection, {
|
||||
id: "prod-b",
|
||||
variants: [
|
||||
{ id: "prod-b-var", prices: [{ amount: 1000, currency: "dkk" }] },
|
||||
],
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
id: "test-region",
|
||||
currency_code: "dkk",
|
||||
})
|
||||
|
||||
await simpleDiscountFactory(dbConnection, {
|
||||
id: "test-discount",
|
||||
regions: ["test-region"],
|
||||
code: "TEST",
|
||||
rule: {
|
||||
type: "percentage",
|
||||
value: "10",
|
||||
allocation: "total",
|
||||
conditions: [
|
||||
{
|
||||
type: "products",
|
||||
operator: "in",
|
||||
products: [prodA.id],
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
await simpleCustomerFactory(dbConnection, {
|
||||
id: "test-customer",
|
||||
email: "test@customer.com",
|
||||
})
|
||||
|
||||
const so = await simpleShippingOptionFactory(dbConnection, {
|
||||
region_id: "test-region",
|
||||
})
|
||||
|
||||
await simpleCartFactory(dbConnection, {
|
||||
customer: "test-customer",
|
||||
id: "cart-test",
|
||||
line_items: [
|
||||
{
|
||||
id: "line-item",
|
||||
variant_id: "prod-a-var",
|
||||
cart_id: "cart-test",
|
||||
unit_price: 1000,
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
region: "test-region",
|
||||
shipping_address: {
|
||||
address_1: "test",
|
||||
country_code: "us",
|
||||
first_name: "chris",
|
||||
last_name: "rock",
|
||||
postal_code: "101",
|
||||
},
|
||||
})
|
||||
|
||||
const api = useApi()
|
||||
|
||||
// ********* PREPARE CART *********
|
||||
|
||||
try {
|
||||
await api.post("/store/carts/cart-test", {
|
||||
discounts: [{ code: "TEST" }],
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
await api.post("/store/carts/cart-test/shipping-methods", {
|
||||
option_id: so.id,
|
||||
data: {},
|
||||
})
|
||||
await api.post("/store/carts/cart-test/payment-sessions")
|
||||
const TEST = await api.post("/store/carts/cart-test/payment-session", {
|
||||
provider_id: "test-pay",
|
||||
})
|
||||
|
||||
console.log("Testing, ", TEST.data.cart.items[0])
|
||||
|
||||
// ********* COMPLETE CART *********
|
||||
const completedOrder = await api.post("/store/carts/cart-test/complete")
|
||||
|
||||
// ********* PREPARE ORDER *********
|
||||
const orderId = completedOrder.data.data.id
|
||||
const fulfilledOrder = await api.post(
|
||||
`/admin/orders/${orderId}/fulfillment`,
|
||||
{
|
||||
items: [{ item_id: "line-item", quantity: 1 }],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const fulfillmentId = fulfilledOrder.data.order.fulfillments[0].id
|
||||
|
||||
await api.post(
|
||||
`/admin/orders/${orderId}/shipment`,
|
||||
{
|
||||
fulfillment_id: fulfillmentId,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
await api.post(
|
||||
`/admin/orders/${orderId}/capture`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// ********* CREATE SWAP *********
|
||||
const createSwap = await api.post(
|
||||
`/admin/orders/${completedOrder.data.data.id}/swaps`,
|
||||
{
|
||||
return_items: [
|
||||
{
|
||||
item_id: "line-item",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
additional_items: [{ variant_id: "prod-b-var", quantity: 1 }],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
let swap = createSwap.data.order.swaps[0]
|
||||
|
||||
// ********* PREPARE SWAP CART *********
|
||||
await api.post(`/store/carts/${swap.cart_id}/shipping-methods`, {
|
||||
option_id: so.id,
|
||||
data: {},
|
||||
})
|
||||
|
||||
await api.post(`/store/carts/${swap.cart_id}/payment-sessions`)
|
||||
await api.post(`/store/carts/${swap.cart_id}/payment-session`, {
|
||||
provider_id: "test-pay",
|
||||
})
|
||||
|
||||
// ********* COMPLETE SWAP CART *********
|
||||
await api.post(`/store/carts/${swap.cart_id}/complete`)
|
||||
|
||||
swap = await api
|
||||
.get(`/admin/swaps/${swap.id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
const swapCart = await api.get(
|
||||
`/store/carts/${swap.data.swap.cart_id}`,
|
||||
{}
|
||||
)
|
||||
|
||||
// ********* VALIDATE *********
|
||||
expect(swap.data.swap.difference_due).toBe(swapCart.data.cart.total)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user