Skip to content

Commit

Permalink
chore(integration): throw errors on catch blocks (medusajs#2091)
Browse files Browse the repository at this point in the history
Why:
Suppressing errors and not failing the execution will lead to misleading errors of the following tests.

Fixes CORE-461
  • Loading branch information
carlos-r-l-rodrigues authored Aug 25, 2022
1 parent 5a964e6 commit ffd6234
Show file tree
Hide file tree
Showing 50 changed files with 1,036 additions and 1,617 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
working-directory: integration-tests/api

- name: Run integration tests
run: yarn test --runInBand
run: yarn test
working-directory: integration-tests/api
env:
DB_PASSWORD: postgres
Expand Down
6 changes: 1 addition & 5 deletions integration-tests/api/__tests__/admin/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
18 changes: 4 additions & 14 deletions integration-tests/api/__tests__/admin/colllections.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
72 changes: 16 additions & 56 deletions integration-tests/api/__tests__/admin/customer-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
34 changes: 7 additions & 27 deletions integration-tests/api/__tests__/admin/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
15 changes: 3 additions & 12 deletions integration-tests/api/__tests__/admin/discount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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",
Expand Down
46 changes: 12 additions & 34 deletions integration-tests/api/__tests__/admin/draft-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -426,7 +421,7 @@ describe("/admin/draft-orders", () => {
}),
expect.objectContaining({
code: "free-shipping",
})
}),
])
)
})
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading

0 comments on commit ffd6234

Please sign in to comment.