Skip to content

Commit

Permalink
chore: use splat instead of lodash to clone, remove unnecessary expec…
Browse files Browse the repository at this point in the history
…tations
  • Loading branch information
riqwan authored and adrien2p committed Dec 7, 2022
1 parent 40694bd commit c1cdb80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
7 changes: 0 additions & 7 deletions integration-tests/api/__tests__/admin/discount.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,6 @@ describe("/admin/discounts", () => {
})

it("fails to create a fixed discount with multiple regions", async () => {
expect.assertions(2)
const api = useApi()

await api
Expand Down Expand Up @@ -1038,7 +1037,6 @@ describe("/admin/discounts", () => {
})

it("fails to update a fixed discount with multiple regions", async () => {
expect.assertions(2)
const api = useApi()

const response = await api.post(
Expand Down Expand Up @@ -1075,7 +1073,6 @@ describe("/admin/discounts", () => {
})

it("fails to add a region to a fixed discount with an existing region", async () => {
expect.assertions(2)
const api = useApi()

const response = await api.post(
Expand Down Expand Up @@ -1236,7 +1233,6 @@ describe("/admin/discounts", () => {
})

it("fails to create discount with end date before start date", async () => {
expect.assertions(2)
const api = useApi()

await api
Expand Down Expand Up @@ -1268,7 +1264,6 @@ describe("/admin/discounts", () => {
})

it("fails to create a discount if the regions contains an invalid regionId ", async () => {
expect.assertions(2)
const api = useApi()

const err = await api.post(
Expand All @@ -1293,7 +1288,6 @@ describe("/admin/discounts", () => {
})

it("fails to create a discount if the regions contains only invalid regionIds ", async () => {
expect.assertions(2)
const api = useApi()

const err = await api.post(
Expand All @@ -1318,7 +1312,6 @@ describe("/admin/discounts", () => {
})

it("fails to create a discount if regions are not present ", async () => {
expect.assertions(2)
const api = useApi()

const err = await api.post(
Expand Down
3 changes: 1 addition & 2 deletions packages/medusa/src/helpers/test-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
27 changes: 12 additions & 15 deletions packages/medusa/src/services/__tests__/discount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/services/discount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c1cdb80

Please sign in to comment.