chore: use splat instead of lodash to clone, remove unnecessary expectations

This commit is contained in:
Riqwan Thamir
2022-12-07 16:03:02 +01:00
committed by Adrien de Peretti
parent 40694bd5d1
commit c1cdb80436
4 changed files with 14 additions and 25 deletions

View File

@@ -11,7 +11,6 @@ import { moduleHelper } from "../loaders/module"
import passportLoader from "../loaders/passport"
import servicesLoader from "../loaders/services"
import strategiesLoader from "../loaders/strategies"
import { clone } from "lodash"
const adminSessionOpts = {
cookieName: "session",
@@ -88,7 +87,7 @@ export async function request(method, url, opts = {}) {
)
headers.Cookie = headers.Cookie || ""
if (opts.adminSession) {
const adminSession = clone(opts.adminSession)
const adminSession = { ...opts.adminSession }
if (adminSession.jwt) {
adminSession.jwt = jwt.sign(

View File

@@ -54,21 +54,18 @@ describe("DiscountService", () => {
})
it("fails to create a discount without regions", async () => {
expect.assertions(3)
try {
await discountService.create({
code: "test",
rule: {
type: "fixed",
allocation: "total",
value: 20,
},
})
} catch (err) {
expect(err.type).toEqual("invalid_data")
expect(err.message).toEqual("Discount must have atleast 1 region")
expect(discountRepository.create).toHaveBeenCalledTimes(0)
}
const err = await discountService.create({
code: "test",
rule: {
type: "fixed",
allocation: "total",
value: 20,
},
}).catch(e => e)
expect(err.type).toEqual("invalid_data")
expect(err.message).toEqual("Discount must have atleast 1 region")
expect(discountRepository.create).toHaveBeenCalledTimes(0)
})
it("successfully creates discount", async () => {

View File

@@ -212,7 +212,7 @@ class DiscountService extends TransactionBaseService {
)) as Region[]
}
if (isEmpty(discount.regions)) {
if (!discount.regions?.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Discount must have atleast 1 region"