chore: fix integration tests (#1240)

* chore: fix integration tests

* chore: fix integration tests

* fix: store tests

* fix: store tests

* fix: cleanup
This commit is contained in:
Sebastian Rindom
2022-03-25 15:08:54 +01:00
committed by GitHub
parent a610805917
commit e4af6b8f9c
13 changed files with 119 additions and 104 deletions

View File

@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/discounts POST /admin/discounts fails if multiple types of resources are provided on update 1`] = `
Object {
"message": "Only one of products, product_types is allowed, Only one of product_types, products is allowed",
"type": "invalid_data",
}
`;
exports[`/admin/discounts POST /admin/discounts fails to add condition on rule with existing comb. of type and operator 1`] = `
Object {
"code": "invalid_request_error",
"message": "Discount Condition with operator 'in' and type 'products' already exist on a Discount Rule",
"type": "duplicate_error",
}
`;

View File

@@ -77,7 +77,7 @@ describe("/admin/customer-groups", () => {
},
})
.catch((err) => {
expect(err.response.status).toEqual(402)
expect(err.response.status).toEqual(422)
expect(err.response.data.type).toEqual("duplicate_error")
expect(err.response.data.message).toEqual(
"Key (name)=(vip-customers) already exists."

View File

@@ -489,32 +489,34 @@ describe("/admin/discounts", () => {
})
expect(response.status).toEqual(200)
expect(response.data.discount.rule.conditions).toEqual([
expect.objectContaining({
type: "products",
operator: "in",
}),
expect.objectContaining({
type: "products",
operator: "not_in",
}),
expect.objectContaining({
type: "product_types",
operator: "not_in",
}),
expect.objectContaining({
type: "product_types",
operator: "in",
}),
expect.objectContaining({
type: "product_tags",
operator: "not_in",
}),
expect.objectContaining({
type: "product_tags",
operator: "in",
}),
])
expect(response.data.discount.rule.conditions).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: "products",
operator: "in",
}),
expect.objectContaining({
type: "products",
operator: "not_in",
}),
expect.objectContaining({
type: "product_types",
operator: "not_in",
}),
expect.objectContaining({
type: "product_types",
operator: "in",
}),
expect.objectContaining({
type: "product_tags",
operator: "not_in",
}),
expect.objectContaining({
type: "product_tags",
operator: "in",
}),
])
)
})
it("creates a discount with conditions and updates said conditions", async () => {
@@ -668,36 +670,32 @@ describe("/admin/discounts", () => {
const createdRule = response.data.discount.rule
try {
await api.post(
`/admin/discounts/${response.data.discount.id}?expand=rule,rule.conditions,rule.conditions.products`,
{
rule: {
id: createdRule.id,
type: createdRule.type,
value: createdRule.value,
allocation: createdRule.allocation,
conditions: [
{
products: [anotherProduct.id],
operator: "in",
},
],
await expect(
api
.post(
`/admin/discounts/${response.data.discount.id}?expand=rule,rule.conditions,rule.conditions.products`,
{
rule: {
id: createdRule.id,
type: createdRule.type,
value: createdRule.value,
allocation: createdRule.allocation,
conditions: [
{
products: [anotherProduct.id],
operator: "in",
},
],
},
},
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
} catch (error) {
console.log(error)
expect(error.response.data.type).toEqual("duplicate_error")
expect(error.response.data.message).toEqual(
`Discount Condition with operator 'in' and type 'products' already exist on a Discount Rule`
)
}
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch((err) => err.response.data)
).resolves.toMatchSnapshot()
})
it("fails if multiple types of resources are provided on create", async () => {
@@ -785,37 +783,33 @@ describe("/admin/discounts", () => {
const createdRule = response.data.discount.rule
try {
await api.post(
`/admin/discounts/${response.data.discount.id}?expand=rule,rule.conditions,rule.conditions.products`,
{
rule: {
id: createdRule.id,
type: createdRule.type,
value: createdRule.value,
allocation: createdRule.allocation,
conditions: [
{
products: [anotherProduct.id],
product_types: [product.type_id],
operator: "in",
},
],
await expect(
api
.post(
`/admin/discounts/${response.data.discount.id}?expand=rule,rule.conditions,rule.conditions.products`,
{
rule: {
id: createdRule.id,
type: createdRule.type,
value: createdRule.value,
allocation: createdRule.allocation,
conditions: [
{
products: [anotherProduct.id],
product_types: [product.type_id],
operator: "in",
},
],
},
},
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
} catch (error) {
console.log(error)
expect(error.response.data.type).toEqual("invalid_data")
expect(error.response.data.message).toEqual(
`Only one of products, product_types is allowed, Only one of product_types, products is allowed`
)
}
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch((err) => err.response.data)
).resolves.toMatchSnapshot()
})
it("creates a discount and updates it", async () => {

View File

@@ -32,7 +32,7 @@ describe("/admin/store", () => {
afterEach(async () => {
const db = useDb()
await db.teardown()
await db.teardown({ forceDelete: ["store"] })
await medusaProcess.kill()
})