chore: use splat instead of lodash to clone, remove unnecessary expectations
This commit is contained in:
committed by
Adrien de Peretti
parent
40694bd5d1
commit
c1cdb80436
@@ -1009,7 +1009,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to create a fixed discount with multiple regions", async () => {
|
it("fails to create a fixed discount with multiple regions", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
await api
|
await api
|
||||||
@@ -1038,7 +1037,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to update a fixed discount with multiple regions", async () => {
|
it("fails to update a fixed discount with multiple regions", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
@@ -1075,7 +1073,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to add a region to a fixed discount with an existing region", async () => {
|
it("fails to add a region to a fixed discount with an existing region", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
@@ -1236,7 +1233,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to create discount with end date before start date", async () => {
|
it("fails to create discount with end date before start date", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
await api
|
await api
|
||||||
@@ -1268,7 +1264,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to create a discount if the regions contains an invalid regionId ", async () => {
|
it("fails to create a discount if the regions contains an invalid regionId ", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const err = await api.post(
|
const err = await api.post(
|
||||||
@@ -1293,7 +1288,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to create a discount if the regions contains only invalid regionIds ", async () => {
|
it("fails to create a discount if the regions contains only invalid regionIds ", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const err = await api.post(
|
const err = await api.post(
|
||||||
@@ -1318,7 +1312,6 @@ describe("/admin/discounts", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to create a discount if regions are not present ", async () => {
|
it("fails to create a discount if regions are not present ", async () => {
|
||||||
expect.assertions(2)
|
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const err = await api.post(
|
const err = await api.post(
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { moduleHelper } from "../loaders/module"
|
|||||||
import passportLoader from "../loaders/passport"
|
import passportLoader from "../loaders/passport"
|
||||||
import servicesLoader from "../loaders/services"
|
import servicesLoader from "../loaders/services"
|
||||||
import strategiesLoader from "../loaders/strategies"
|
import strategiesLoader from "../loaders/strategies"
|
||||||
import { clone } from "lodash"
|
|
||||||
|
|
||||||
const adminSessionOpts = {
|
const adminSessionOpts = {
|
||||||
cookieName: "session",
|
cookieName: "session",
|
||||||
@@ -88,7 +87,7 @@ export async function request(method, url, opts = {}) {
|
|||||||
)
|
)
|
||||||
headers.Cookie = headers.Cookie || ""
|
headers.Cookie = headers.Cookie || ""
|
||||||
if (opts.adminSession) {
|
if (opts.adminSession) {
|
||||||
const adminSession = clone(opts.adminSession)
|
const adminSession = { ...opts.adminSession }
|
||||||
|
|
||||||
if (adminSession.jwt) {
|
if (adminSession.jwt) {
|
||||||
adminSession.jwt = jwt.sign(
|
adminSession.jwt = jwt.sign(
|
||||||
|
|||||||
@@ -54,21 +54,18 @@ describe("DiscountService", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("fails to create a discount without regions", async () => {
|
it("fails to create a discount without regions", async () => {
|
||||||
expect.assertions(3)
|
const err = await discountService.create({
|
||||||
try {
|
|
||||||
await discountService.create({
|
|
||||||
code: "test",
|
code: "test",
|
||||||
rule: {
|
rule: {
|
||||||
type: "fixed",
|
type: "fixed",
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
value: 20,
|
value: 20,
|
||||||
},
|
},
|
||||||
})
|
}).catch(e => e)
|
||||||
} catch (err) {
|
|
||||||
expect(err.type).toEqual("invalid_data")
|
expect(err.type).toEqual("invalid_data")
|
||||||
expect(err.message).toEqual("Discount must have atleast 1 region")
|
expect(err.message).toEqual("Discount must have atleast 1 region")
|
||||||
expect(discountRepository.create).toHaveBeenCalledTimes(0)
|
expect(discountRepository.create).toHaveBeenCalledTimes(0)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("successfully creates discount", async () => {
|
it("successfully creates discount", async () => {
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ class DiscountService extends TransactionBaseService {
|
|||||||
)) as Region[]
|
)) as Region[]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty(discount.regions)) {
|
if (!discount.regions?.length) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.INVALID_DATA,
|
MedusaError.Types.INVALID_DATA,
|
||||||
"Discount must have atleast 1 region"
|
"Discount must have atleast 1 region"
|
||||||
|
|||||||
Reference in New Issue
Block a user