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:
@@ -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",
|
||||
}
|
||||
`;
|
||||
@@ -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."
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -32,7 +32,7 @@ describe("/admin/store", () => {
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
await db.teardown({ forceDelete: ["store"] })
|
||||
await medusaProcess.kill()
|
||||
})
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ describe("/store/customers", () => {
|
||||
expect(response.data.customer).not.toHaveProperty("password_hash")
|
||||
})
|
||||
|
||||
it("responds 409 on duplicate", async () => {
|
||||
it("responds 422 on duplicate", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
@@ -70,7 +70,7 @@ describe("/store/customers", () => {
|
||||
})
|
||||
.catch((err) => err.response)
|
||||
|
||||
expect(response.status).toEqual(402)
|
||||
expect(response.status).toEqual(422)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ const {
|
||||
simpleProductFactory,
|
||||
} = require("../../factories")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("Swaps", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
@@ -47,6 +47,7 @@ export const simpleProductFactory = async (
|
||||
const productToCreate = {
|
||||
id: prodId,
|
||||
title: data.title || faker.commerce.productName(),
|
||||
status: data.status,
|
||||
is_giftcard: data.is_giftcard || false,
|
||||
discountable: !data.is_giftcard,
|
||||
tags: [],
|
||||
|
||||
@@ -32,7 +32,7 @@ export default () => {
|
||||
"The request conflicted with another request. You may retry the request with the provided Idempotency-Key."
|
||||
break
|
||||
case MedusaError.Types.DUPLICATE_ERROR:
|
||||
statusCode = 402
|
||||
statusCode = 422
|
||||
errObj.code = INVALID_REQUEST_ERROR
|
||||
break
|
||||
case MedusaError.Types.NOT_ALLOWED:
|
||||
|
||||
@@ -31,6 +31,7 @@ export default async (req, res) => {
|
||||
req.scope.resolve("fulfillmentProviderService")
|
||||
|
||||
const data = await storeService.retrieve(["currencies", "default_currency"])
|
||||
|
||||
const paymentProviders = await paymentProviderService.list()
|
||||
const fulfillmentProviders = await fulfillmentProviderService.list()
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ export default async ({ container }) => {
|
||||
const currencyRepo = manager.getCustomRepository(currencyRepository)
|
||||
const hasCurrencies = await currencyRepo.findOne()
|
||||
if (!hasCurrencies) {
|
||||
for (const [_, c] of Object.entries(currencies)) {
|
||||
for (const [, c] of Object.entries(currencies)) {
|
||||
const query = `INSERT INTO "currency" ("code", "symbol", "symbol_native", "name") VALUES ($1, $2, $3, $4)`
|
||||
|
||||
const code = c.code.toLowerCase()
|
||||
@@ -83,40 +83,37 @@ export default async ({ container }) => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
await storeService.withTransaction(manager).create()
|
||||
|
||||
let payIds
|
||||
const pProviderService = container.resolve("paymentProviderService")
|
||||
|
||||
const payProviders =
|
||||
silentResolution(container, "paymentProviders", logger) || []
|
||||
|
||||
payIds = payProviders.map((p) => p.getIdentifier())
|
||||
const payIds = payProviders.map((p) => p.getIdentifier())
|
||||
|
||||
await pProviderService.registerInstalledProviders(payIds)
|
||||
|
||||
let notiIds
|
||||
const nProviderService = container.resolve("notificationService")
|
||||
|
||||
const notiProviders =
|
||||
silentResolution(container, "notificationProviders", logger) || []
|
||||
|
||||
notiIds = notiProviders.map((p) => p.getIdentifier())
|
||||
const notiIds = notiProviders.map((p) => p.getIdentifier())
|
||||
await nProviderService.registerInstalledProviders(notiIds)
|
||||
|
||||
let fulfilIds
|
||||
const fProviderService = container.resolve("fulfillmentProviderService")
|
||||
|
||||
const fulfilProviders =
|
||||
silentResolution(container, "fulfillmentProviders", logger) || []
|
||||
|
||||
fulfilIds = fulfilProviders.map((p) => p.getIdentifier())
|
||||
const fulfilIds = fulfilProviders.map((p) => p.getIdentifier())
|
||||
await fProviderService.registerInstalledProviders(fulfilIds)
|
||||
|
||||
let taxIds
|
||||
const tProviderService = container.resolve("taxProviderService")
|
||||
|
||||
const taxProviders =
|
||||
silentResolution(container, "taxProviders", logger) || []
|
||||
|
||||
taxIds = taxProviders.map((p) => p.getIdentifier())
|
||||
const taxIds = taxProviders.map((p) => p.getIdentifier())
|
||||
await tProviderService.registerInstalledProviders(taxIds)
|
||||
|
||||
await profileService.withTransaction(manager).createDefault()
|
||||
|
||||
@@ -12,7 +12,8 @@ class FulfillmentProviderService {
|
||||
async registerInstalledProviders(providers) {
|
||||
const { manager, fulfillmentProviderRepository } = this.container_
|
||||
const model = manager.getCustomRepository(fulfillmentProviderRepository)
|
||||
model.update({}, { is_installed: false })
|
||||
await model.update({}, { is_installed: false })
|
||||
|
||||
for (const p of providers) {
|
||||
const n = model.create({ id: p, is_installed: true })
|
||||
await model.save(n)
|
||||
@@ -23,7 +24,7 @@ class FulfillmentProviderService {
|
||||
const { manager, fulfillmentProviderRepository } = this.container_
|
||||
const fpRepo = manager.getCustomRepository(fulfillmentProviderRepository)
|
||||
|
||||
return fpRepo.find({})
|
||||
return await fpRepo.find({})
|
||||
}
|
||||
|
||||
async listFulfillmentOptions(providers) {
|
||||
|
||||
@@ -34,8 +34,10 @@ class PaymentProviderService extends BaseService {
|
||||
|
||||
async registerInstalledProviders(providers) {
|
||||
const { manager, paymentProviderRepository } = this.container_
|
||||
|
||||
const model = manager.getCustomRepository(paymentProviderRepository)
|
||||
model.update({}, { is_installed: false })
|
||||
await model.update({}, { is_installed: false })
|
||||
|
||||
for (const p of providers) {
|
||||
const n = model.create({ id: p, is_installed: true })
|
||||
await model.save(n)
|
||||
@@ -46,7 +48,7 @@ class PaymentProviderService extends BaseService {
|
||||
const { manager, paymentProviderRepository } = this.container_
|
||||
const ppRepo = manager.getCustomRepository(paymentProviderRepository)
|
||||
|
||||
return ppRepo.find({})
|
||||
return await ppRepo.find({})
|
||||
}
|
||||
|
||||
async retrievePayment(id, relations = []) {
|
||||
|
||||
@@ -431,7 +431,8 @@ class TaxProviderService extends BaseService {
|
||||
|
||||
async registerInstalledProviders(providers: string[]): Promise<void> {
|
||||
const model = this.manager_.getCustomRepository(this.taxProviderRepo_)
|
||||
model.update({}, { is_installed: false })
|
||||
await model.update({}, { is_installed: false })
|
||||
|
||||
for (const p of providers) {
|
||||
const n = model.create({ id: p, is_installed: true })
|
||||
await model.save(n)
|
||||
|
||||
Reference in New Issue
Block a user