chore(integration): throw errors on catch blocks (#2091)

Why:
Suppressing errors and not failing the execution will lead to misleading errors of the following tests.

Fixes CORE-461
This commit is contained in:
Carlos R. L. Rodrigues
2022-08-25 03:36:24 -03:00
committed by GitHub
parent 5a964e6439
commit ffd6234356
50 changed files with 1038 additions and 1619 deletions

View File

@@ -18,11 +18,7 @@ describe("/admin/auth", () => {
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd })
try {
await adminSeeder(dbConnection)
} catch (e) {
throw e
}
await adminSeeder(dbConnection)
})
afterAll(async () => {

View File

@@ -25,13 +25,8 @@ describe("/admin/collections", () => {
describe("/admin/collections/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
})
afterEach(async () => {
@@ -128,13 +123,8 @@ describe("/admin/collections", () => {
describe("/admin/collections", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -27,13 +27,8 @@ describe("/admin/customer-groups", () => {
describe("POST /admin/customer-groups", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -88,13 +83,8 @@ describe("/admin/customer-groups", () => {
describe("DELETE /admin/customer-groups", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -195,13 +185,8 @@ describe("/admin/customer-groups", () => {
describe("GET /admin/customer-groups/{id}/customers", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -242,13 +227,8 @@ describe("/admin/customer-groups", () => {
describe("POST /admin/customer-groups/{id}/customers/batch", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -418,13 +398,8 @@ describe("/admin/customer-groups", () => {
describe("POST /admin/customer-groups/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -500,13 +475,8 @@ describe("/admin/customer-groups", () => {
describe("GET /admin/customer-groups", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -559,13 +529,8 @@ describe("/admin/customer-groups", () => {
describe("GET /admin/customer-groups/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -641,13 +606,8 @@ describe("/admin/customer-groups", () => {
describe("DELETE /admin/customer-groups/{id}/batch", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -28,13 +28,8 @@ describe("/admin/customers", () => {
describe("GET /admin/customers", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -164,12 +159,7 @@ describe("/admin/customers", () => {
describe("POST /admin/customers", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -213,13 +203,8 @@ describe("/admin/customers", () => {
describe("POST /admin/customers/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {
@@ -368,13 +353,8 @@ describe("/admin/customers", () => {
describe("GET /admin/customers/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -427,13 +427,8 @@ describe("/admin/discounts", () => {
describe("POST /admin/discounts", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await discountSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await discountSeeder(dbConnection)
})
afterEach(async () => {
@@ -2150,11 +2145,7 @@ describe("/admin/discounts", () => {
describe("GET /admin/discounts/:id/conditions/:condition_id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
const prod = await simpleProductFactory(dbConnection, {
type: "pants",

View File

@@ -28,13 +28,8 @@ describe("/admin/draft-orders", () => {
describe("POST /admin/draft-orders", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection)
})
afterEach(async () => {
@@ -359,7 +354,7 @@ describe("/admin/draft-orders", () => {
const payload = {
email: "oli@test.dk",
shipping_address: "oli-shipping",
discounts: [{ code: "TEST" }, { code: "free-shipping"}],
discounts: [{ code: "TEST" }, { code: "free-shipping" }],
items: [
{
variant_id: "test-variant",
@@ -426,7 +421,7 @@ describe("/admin/draft-orders", () => {
}),
expect.objectContaining({
code: "free-shipping",
})
}),
])
)
})
@@ -524,12 +519,8 @@ describe("/admin/draft-orders", () => {
})
describe("GET /admin/draft-orders", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection)
} catch (err) {
throw err
}
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection)
})
afterEach(async () => {
@@ -605,13 +596,8 @@ describe("/admin/draft-orders", () => {
describe("DELETE /admin/draft-orders/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection)
})
afterEach(async () => {
@@ -644,12 +630,8 @@ describe("/admin/draft-orders", () => {
describe("POST /admin/draft-orders/:id/line-items/:line_id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection, { status: "open" })
} catch (err) {
throw err
}
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection, { status: "open" })
})
afterEach(async () => {
@@ -733,12 +715,8 @@ describe("/admin/draft-orders", () => {
describe("POST /admin/draft-orders/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection, { status: "open" })
} catch (err) {
throw err
}
await adminSeeder(dbConnection)
await draftOrderSeeder(dbConnection, { status: "open" })
})
afterEach(async () => {

View File

@@ -28,32 +28,28 @@ describe("/admin/gift-cards", () => {
describe("GET /admin/gift-cards", () => {
beforeEach(async () => {
const manager = dbConnection.manager
try {
await adminSeeder(dbConnection)
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await manager.insert(GiftCard, {
id: "gift_test",
code: "GC_TEST",
value: 20000,
balance: 20000,
region_id: "test-region",
})
await manager.insert(GiftCard, {
id: "another_gift_test",
code: "CARD_TEST",
value: 200000,
balance: 200000,
region_id: "test-region",
})
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await manager.insert(GiftCard, {
id: "gift_test",
code: "GC_TEST",
value: 20000,
balance: 20000,
region_id: "test-region",
})
await manager.insert(GiftCard, {
id: "another_gift_test",
code: "CARD_TEST",
value: 200000,
balance: 200000,
region_id: "test-region",
})
})
afterEach(async () => {
@@ -136,25 +132,21 @@ describe("/admin/gift-cards", () => {
describe("POST /admin/gift-cards", () => {
beforeEach(async () => {
const manager = dbConnection.manager
try {
await adminSeeder(dbConnection)
await manager.insert(Region, {
id: "region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await manager.insert(GiftCard, {
id: "gift_test",
code: "GC_TEST",
value: 20000,
balance: 20000,
region_id: "region",
})
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await manager.insert(Region, {
id: "region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await manager.insert(GiftCard, {
id: "gift_test",
code: "GC_TEST",
value: 20000,
balance: 20000,
region_id: "region",
})
})
afterEach(async () => {

View File

@@ -36,13 +36,10 @@ describe("/admin/notes", () => {
describe("GET /admin/notes/:id", () => {
beforeEach(async () => {
const manager = dbConnection.manager
try {
await adminSeeder(dbConnection)
await manager.insert(Note, note)
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
await manager.insert(Note, note)
})
afterEach(async () => {
@@ -73,11 +70,7 @@ describe("/admin/notes", () => {
describe("POST /admin/notes", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -121,19 +114,16 @@ describe("/admin/notes", () => {
describe("GET /admin/notes", () => {
beforeEach(async () => {
const manager = dbConnection.manager
try {
await adminSeeder(dbConnection)
await manager.insert(Note, { ...note, id: "note1" })
await manager.insert(Note, { ...note, id: "note2" })
await manager.insert(Note, {
...note,
id: "note3",
resource_id: "resource2",
})
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
await manager.insert(Note, { ...note, id: "note1" })
await manager.insert(Note, { ...note, id: "note2" })
await manager.insert(Note, {
...note,
id: "note3",
resource_id: "resource2",
})
})
afterEach(async () => {
@@ -178,13 +168,10 @@ describe("/admin/notes", () => {
describe("POST /admin/notes/:id", () => {
beforeEach(async () => {
const manager = dbConnection.manager
try {
await adminSeeder(dbConnection)
await manager.insert(Note, note)
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
await manager.insert(Note, note)
})
afterEach(async () => {
@@ -226,13 +213,10 @@ describe("/admin/notes", () => {
describe("DELETE /admin/notes/:id", () => {
beforeEach(async () => {
const manager = dbConnection.manager
try {
await adminSeeder(dbConnection)
await manager.insert(Note, note)
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
await manager.insert(Note, note)
})
afterEach(async () => {

View File

@@ -44,13 +44,8 @@ describe("/admin/orders", () => {
describe("GET /admin/orders", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
})
afterEach(async () => {
@@ -129,14 +124,9 @@ describe("/admin/orders", () => {
describe("GET /admin/orders", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
const manager = dbConnection.manager
@@ -276,14 +266,9 @@ describe("/admin/orders", () => {
describe("POST /admin/orders/:id/swaps", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await claimSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await claimSeeder(dbConnection)
})
afterEach(async () => {
@@ -318,14 +303,9 @@ describe("/admin/orders", () => {
describe("POST /admin/orders/:id/claims", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await claimSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await claimSeeder(dbConnection)
})
afterEach(async () => {
@@ -1216,14 +1196,9 @@ describe("/admin/orders", () => {
describe("POST /admin/orders/:id/claims", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
})
afterEach(async () => {
@@ -1272,21 +1247,16 @@ describe("/admin/orders", () => {
describe("POST /admin/orders/:id/return", () => {
let rrId
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
const created = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
})
const result = await dbConnection.manager.save(created)
const created = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
})
const result = await dbConnection.manager.save(created)
rrId = result.id
} catch (err) {
console.log(err)
throw err
}
rrId = result.id
})
afterEach(async () => {
@@ -1392,17 +1362,12 @@ describe("/admin/orders", () => {
describe("GET /admin/orders", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
// Manually insert date for filtering
const createdAt = new Date("26 January 1997 12:00 UTC")
await orderSeeder(dbConnection, {
created_at: createdAt.toISOString(),
})
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
// Manually insert date for filtering
const createdAt = new Date("26 January 1997 12:00 UTC")
await orderSeeder(dbConnection, {
created_at: createdAt.toISOString(),
})
})
afterEach(async () => {
@@ -1521,16 +1486,18 @@ describe("/admin/orders", () => {
expect(response.status).toEqual(200)
expect(response.data.count).toEqual(2)
expect(response.data.orders).toEqual(expect.arrayContaining([
expect.objectContaining({
id: "test-order",
shipping_address: expect.objectContaining({ first_name: "lebron" }),
}),
expect.objectContaining({
id: "discount-order",
shipping_address: expect.objectContaining({ first_name: "lebron" }),
}),
]))
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-order",
shipping_address: expect.objectContaining({ first_name: "lebron" }),
}),
expect.objectContaining({
id: "discount-order",
shipping_address: expect.objectContaining({ first_name: "lebron" }),
}),
])
)
})
it("successfully lists orders with greater than", async () => {
@@ -1727,14 +1694,9 @@ describe("/admin/orders", () => {
describe("POST /admin/orders/:id/swaps", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
})
afterEach(async () => {
@@ -2137,33 +2099,29 @@ describe("/admin/orders", () => {
})
it("Only allows canceling swap after canceling fulfillments", async () => {
try {
const swap_id = "swap-w-f"
const swap_id = "swap-w-f"
const swap = await callGet({
path: `/admin/swaps/${swap_id}`,
get: "swap",
})
const swap = await callGet({
path: `/admin/swaps/${swap_id}`,
get: "swap",
})
const { order_id } = swap
const { order_id } = swap
const expectCancelToReturn = partial(expectPostCallToReturn, {
path: `/admin/orders/${order_id}/swaps/${swap_id}/cancel`,
})
const expectCancelToReturn = partial(expectPostCallToReturn, {
path: `/admin/orders/${order_id}/swaps/${swap_id}/cancel`,
})
await expectCancelToReturn({ code: 400 })
await expectCancelToReturn({ code: 400 })
await expectAllPostCallsToReturn({
code: 200,
col: swap.fulfillments,
pathf: (f) =>
`/admin/orders/${order_id}/swaps/${swap_id}/fulfillments/${f.id}/cancel`,
})
await expectAllPostCallsToReturn({
code: 200,
col: swap.fulfillments,
pathf: (f) =>
`/admin/orders/${order_id}/swaps/${swap_id}/fulfillments/${f.id}/cancel`,
})
await expectCancelToReturn({ code: 200 })
} catch (e) {
console.log(e)
}
await expectCancelToReturn({ code: 200 })
})
it("Only allows canceling swap after canceling return", async () => {

View File

@@ -37,14 +37,9 @@ describe("/admin/price-lists", () => {
describe("POST /admin/price-list", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
await productSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
await productSeeder(dbConnection)
})
afterEach(async () => {
@@ -116,14 +111,9 @@ describe("/admin/price-lists", () => {
describe("GET /admin/price-lists", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -372,15 +362,10 @@ describe("/admin/price-lists", () => {
describe("POST /admin/price-lists/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await customerSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -659,14 +644,9 @@ describe("/admin/price-lists", () => {
describe("POST /admin/price-lists/:id/prices/batch", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -949,14 +929,9 @@ describe("/admin/price-lists", () => {
describe("DELETE /admin/price-lists/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -1001,14 +976,9 @@ describe("/admin/price-lists", () => {
describe("tests cascade on delete", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -1045,14 +1015,9 @@ describe("/admin/price-lists", () => {
describe("DELETE /admin/price-lists/:id/prices/batch", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
await productSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -1102,59 +1067,54 @@ describe("/admin/price-lists", () => {
describe("GET /admin/price-lists/:id/products", () => {
let tag
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await adminSeeder(dbConnection)
await simpleProductFactory(
dbConnection,
{
id: "test-prod-1",
title: "MedusaHeadphones",
variants: [{ id: "test-variant-1" }, { id: "test-variant-2" }],
},
1
)
await simpleProductFactory(
dbConnection,
{
id: "test-prod-1",
title: "MedusaHeadphones",
variants: [{ id: "test-variant-1" }, { id: "test-variant-2" }],
},
1
)
const prod = await simpleProductFactory(
dbConnection,
{
id: "test-prod-2",
tags: ["test-tag"],
variants: [{ id: "test-variant-3" }, { id: "test-variant-4" }],
},
2
)
const prod = await simpleProductFactory(
dbConnection,
{
id: "test-prod-2",
tags: ["test-tag"],
variants: [{ id: "test-variant-3" }, { id: "test-variant-4" }],
},
2
)
tag = prod.tags[0].id
tag = prod.tags[0].id
await simpleProductFactory(
dbConnection,
{
id: "test-prod-3",
variants: [{ id: "test-variant-5" }],
},
3
)
await simpleProductFactory(
dbConnection,
{
id: "test-prod-3",
variants: [{ id: "test-variant-5" }],
},
3
)
await simplePriceListFactory(dbConnection, {
id: "test-list",
customer_groups: ["test-group"],
prices: [
{ 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) {
console.log(err)
throw err
}
await simplePriceListFactory(dbConnection, {
id: "test-list",
customer_groups: ["test-group"],
prices: [
{ 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 },
],
})
})
afterEach(async () => {
@@ -1278,61 +1238,56 @@ describe("/admin/price-lists", () => {
}
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await adminSeeder(dbConnection)
product1 = await simpleProductFactory(
dbConnection,
{
id: "test-prod-1",
title: "some product",
variants: [
{
id: `simple-test-variant-${Math.random() * 1000}`,
title: "Test",
prices: [{ currency: "usd", amount: 100 }],
},
{
id: `simple-test-variant-${Math.random() * 1000}`,
title: "Test 2",
prices: [{ currency: "usd", amount: 200 }],
},
],
},
1
)
product2 = await simpleProductFactory(
dbConnection,
{
id: "test-prod-2",
title: "some product 2",
},
2
)
await simplePriceListFactory(dbConnection, {
id: "test-list",
customer_groups: ["test-group"],
prices: [
...product1.variants.map((variant, i) => ({
id: getCustomPriceIdFromVariant(variant.id, i),
variant_id: variant.id,
currency_code: "usd",
amount: (i + 1) * 150,
})),
...product2.variants.map((variant, i) => ({
id: getCustomPriceIdFromVariant(variant.id, i),
variant_id: variant.id,
currency_code: "usd",
amount: (i + 1) * 150,
})),
product1 = await simpleProductFactory(
dbConnection,
{
id: "test-prod-1",
title: "some product",
variants: [
{
id: `simple-test-variant-${Math.random() * 1000}`,
title: "Test",
prices: [{ currency: "usd", amount: 100 }],
},
{
id: `simple-test-variant-${Math.random() * 1000}`,
title: "Test 2",
prices: [{ currency: "usd", amount: 200 }],
},
],
})
} catch (err) {
console.log(err)
throw err
}
},
1
)
product2 = await simpleProductFactory(
dbConnection,
{
id: "test-prod-2",
title: "some product 2",
},
2
)
await simplePriceListFactory(dbConnection, {
id: "test-list",
customer_groups: ["test-group"],
prices: [
...product1.variants.map((variant, i) => ({
id: getCustomPriceIdFromVariant(variant.id, i),
variant_id: variant.id,
currency_code: "usd",
amount: (i + 1) * 150,
})),
...product2.variants.map((variant, i) => ({
id: getCustomPriceIdFromVariant(variant.id, i),
variant_id: variant.id,
currency_code: "usd",
amount: (i + 1) * 150,
})),
],
})
})
afterEach(async () => {

View File

@@ -28,13 +28,8 @@ describe("/admin/product-tags", () => {
describe("GET /admin/product-tags", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -28,13 +28,8 @@ describe("/admin/product-types", () => {
describe("GET /admin/product-types", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -62,10 +57,7 @@ describe("/admin/product-types", () => {
updated_at: expect.any(String),
}
expect(res.data.product_types).toMatchSnapshot([
typeMatch,
typeMatch,
])
expect(res.data.product_types).toMatchSnapshot([typeMatch, typeMatch])
})
it("returns a list of product types matching free text search param", async () => {
@@ -90,13 +82,11 @@ describe("/admin/product-types", () => {
// The value of the type should match the search param
expect(res.data.product_types.map((pt) => pt.value)).toEqual([
"test-type-new"
"test-type-new",
])
// Should only return one type as there is only one match to the search param
expect(res.data.product_types).toMatchSnapshot([
typeMatch
])
expect(res.data.product_types).toMatchSnapshot([typeMatch])
})
})
})

View File

@@ -34,13 +34,8 @@ describe("/admin/products", () => {
describe("GET /admin/products", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -852,13 +847,8 @@ describe("/admin/products", () => {
describe("POST /admin/products", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -1427,13 +1417,8 @@ describe("/admin/products", () => {
describe("GET /admin/products/:id/variants", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -1481,14 +1466,9 @@ describe("/admin/products", () => {
describe("updates a variant's default prices (ignores prices associated with a Price List)", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
await priceListSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
await priceListSeeder(dbConnection)
})
afterEach(async () => {
@@ -1757,13 +1737,8 @@ describe("/admin/products", () => {
describe("testing for soft-deletion + uniqueness on handles, collection and variant properties", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -2256,13 +2231,8 @@ describe("/admin/products", () => {
describe("GET /admin/products/tag-usage", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -27,23 +27,18 @@ describe("/admin/regions", () => {
describe("Remove region from country on delete", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
const manager = dbConnection.manager
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await adminSeeder(dbConnection)
const manager = dbConnection.manager
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
)
} catch (err) {
console.log(err)
throw err
}
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
)
})
afterEach(async () => {
@@ -203,23 +198,18 @@ describe("/admin/regions", () => {
describe("DELETE /admin/regions/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
const manager = dbConnection.manager
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await adminSeeder(dbConnection)
const manager = dbConnection.manager
await manager.insert(Region, {
id: "test-region",
name: "Test Region",
currency_code: "usd",
tax_rate: 0,
})
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
)
} catch (err) {
console.log(err)
throw err
}
await manager.query(
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
)
})
afterEach(async () => {

View File

@@ -27,12 +27,7 @@ describe("/admin/return-reasons", () => {
describe("POST /admin/return-reasons", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -31,20 +31,15 @@ describe("/admin/returns", () => {
let rrId
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
const created = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
})
const resultRR = await dbConnection.manager.save(created)
rrId = resultRR.id
} catch (err) {
console.log(err)
throw err
}
const created = dbConnection.manager.create(ReturnReason, {
value: "too_big",
label: "Too Big",
})
const resultRR = await dbConnection.manager.save(created)
rrId = resultRR.id
})
afterEach(async () => {
@@ -231,9 +226,9 @@ describe("/admin/returns", () => {
},
],
return_shipping: {
option_id: "test-option",
price: 0,
}
option_id: "test-option",
price: 0,
},
},
{
headers: {

View File

@@ -52,15 +52,11 @@ describe("sales channels", () => {
let salesChannel
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
} catch (e) {
console.error(e)
}
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
})
afterEach(async () => {
@@ -92,19 +88,15 @@ describe("sales channels", () => {
let salesChannel2
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
salesChannel1 = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
salesChannel2 = await simpleSalesChannelFactory(dbConnection, {
name: "test name 2",
description: "test description 2",
})
} catch (e) {
console.error(e)
}
await adminSeeder(dbConnection)
salesChannel1 = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
salesChannel2 = await simpleSalesChannelFactory(dbConnection, {
name: "test name 2",
description: "test description 2",
})
})
afterEach(async () => {
@@ -207,15 +199,11 @@ describe("sales channels", () => {
let sc
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
sc = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
} catch (err) {
console.log(err)
}
await adminSeeder(dbConnection)
sc = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
})
afterEach(async () => {
@@ -256,11 +244,7 @@ describe("sales channels", () => {
describe("POST /admin/sales-channels", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
} catch (e) {
console.error(e)
}
await adminSeeder(dbConnection)
})
afterEach(async () => {
@@ -324,21 +308,17 @@ describe("sales channels", () => {
let salesChannel
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
await simpleSalesChannelFactory(dbConnection, {
name: "Default channel",
id: "test-channel",
is_default: true,
})
} catch (e) {
console.error(e)
}
await simpleSalesChannelFactory(dbConnection, {
name: "Default channel",
id: "test-channel",
is_default: true,
})
})
afterEach(async () => {
@@ -454,18 +434,14 @@ describe("sales channels", () => {
describe("GET /admin/orders/:id", () => {
let order
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await adminSeeder(dbConnection)
order = await simpleOrderFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
} catch (err) {
console.log(err)
}
order = await simpleOrderFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
})
afterEach(async () => {
@@ -495,18 +471,14 @@ describe("sales channels", () => {
describe("GET /admin/orders?expand=sales_channels", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await adminSeeder(dbConnection)
await simpleOrderFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
} catch (err) {
console.log(err)
}
await simpleOrderFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
})
afterEach(async () => {
@@ -537,24 +509,20 @@ describe("sales channels", () => {
describe("GET /admin/product/:id", () => {
let product
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await adminSeeder(dbConnection)
product = await simpleProductFactory(dbConnection, {
sales_channels: [
{
name: "webshop",
description: "Webshop sales channel",
},
{
name: "amazon",
description: "Amazon sales channel",
},
],
})
} catch (err) {
console.log(err)
}
product = await simpleProductFactory(dbConnection, {
sales_channels: [
{
name: "webshop",
description: "Webshop sales channel",
},
{
name: "amazon",
description: "Amazon sales channel",
},
],
})
})
afterEach(async () => {
@@ -589,24 +557,20 @@ describe("sales channels", () => {
describe("GET /admin/products?expand[]=sales_channels", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await adminSeeder(dbConnection)
await simpleProductFactory(dbConnection, {
sales_channels: [
{
name: "webshop",
description: "Webshop sales channel",
},
{
name: "amazon",
description: "Amazon sales channel",
},
],
})
} catch (err) {
console.log(err)
}
await simpleProductFactory(dbConnection, {
sales_channels: [
{
name: "webshop",
description: "Webshop sales channel",
},
{
name: "amazon",
description: "Amazon sales channel",
},
],
})
})
afterEach(async () => {
@@ -645,20 +609,16 @@ describe("sales channels", () => {
let product
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
product = await simpleProductFactory(dbConnection, {
id: "product_1",
title: "test title",
})
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
products: [product],
})
} catch (e) {
console.error(e)
}
await adminSeeder(dbConnection)
product = await simpleProductFactory(dbConnection, {
id: "product_1",
title: "test title",
})
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
products: [product],
})
})
afterEach(async () => {
@@ -730,19 +690,15 @@ describe("sales channels", () => {
let product
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
product = await simpleProductFactory(dbConnection, {
id: "product_1",
title: "test title",
})
} catch (e) {
console.error(e)
}
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
product = await simpleProductFactory(dbConnection, {
id: "product_1",
title: "test title",
})
})
afterEach(async () => {
@@ -798,19 +754,14 @@ describe("sales channels", () => {
let order
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
order = await simpleOrderFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
await orderSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await adminSeeder(dbConnection)
order = await simpleOrderFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
await orderSeeder(dbConnection)
})
afterEach(async () => {
@@ -850,19 +801,14 @@ describe("sales channels", () => {
let salesChannel
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
const product = await simpleProductFactory(dbConnection, productData)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
products: [product],
})
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
const product = await simpleProductFactory(dbConnection, productData)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
products: [product],
})
})
afterEach(async () => {
@@ -900,17 +846,12 @@ describe("sales channels", () => {
let salesChannel
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
})
afterEach(async () => {
@@ -965,17 +906,12 @@ describe("sales channels", () => {
let salesChannel
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
})
afterEach(async () => {

View File

@@ -32,13 +32,8 @@ describe("/admin/shipping-options", () => {
describe("POST /admin/shipping-options/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await shippingOptionSeeder(dbConnection)
} catch (err) {
console.error(err)
throw err
}
await adminSeeder(dbConnection)
await shippingOptionSeeder(dbConnection)
})
afterEach(async () => {
@@ -254,40 +249,35 @@ describe("/admin/shipping-options", () => {
let payload
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await shippingOptionSeeder(dbConnection)
await adminSeeder(dbConnection)
await shippingOptionSeeder(dbConnection)
const api = useApi()
await api.post(
`/admin/regions/region`,
{
fulfillment_providers: ["test-ful"],
const api = useApi()
await api.post(
`/admin/regions/region`,
{
fulfillment_providers: ["test-ful"],
},
{
headers: {
Authorization: "Bearer test_token",
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
const manager = dbConnection.manager
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
})
payload = {
name: "Test option",
amount: 100,
price_type: "flat_rate",
region_id: "region",
provider_id: "test-ful",
data: {},
profile_id: defaultProfile.id,
}
} catch (err) {
console.error(err)
throw err
)
const manager = dbConnection.manager
const defaultProfile = await manager.findOne(ShippingProfile, {
type: "default",
})
payload = {
name: "Test option",
amount: 100,
price_type: "flat_rate",
region_id: "region",
provider_id: "test-ful",
data: {},
profile_id: defaultProfile.id,
}
})
@@ -385,13 +375,8 @@ describe("/admin/shipping-options", () => {
})
describe("GET /admin/shipping-options", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await shippingOptionSeeder(dbConnection)
} catch (err) {
console.error(err)
throw err
}
await adminSeeder(dbConnection)
await shippingOptionSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -28,13 +28,9 @@ describe("/admin/swaps", () => {
describe("GET /admin/swaps/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
})
afterEach(async () => {
@@ -106,13 +102,9 @@ describe("/admin/swaps", () => {
describe("GET /admin/swaps/", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
throw err
}
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
})
afterEach(async () => {

View File

@@ -28,13 +28,8 @@ describe("/admin/products", () => {
describe("GET /admin/product-variants", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
}
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
})
afterEach(async () => {