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