Skip to content

Commit

Permalink
Merge branch 'develop' into feat/sales-channel-module--joiner-config
Browse files Browse the repository at this point in the history
  • Loading branch information
fPolic authored Dec 15, 2023
2 parents 87fa07b + 56b07ed commit 7a83b51
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 117 deletions.
172 changes: 83 additions & 89 deletions integration-tests/api/__tests__/admin/shipping-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("/admin/shipping-options", () => {
await db.teardown()
})

it("updates a shipping option with no existing requirements", async () => {
it("should update a shipping option with no existing requirements", async () => {
const api = useApi()

const payload = {
Expand All @@ -66,11 +66,11 @@ describe("/admin/shipping-options", () => {
],
}

const res = await api.post(`/admin/shipping-options/test-out`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
const res = await api.post(
`/admin/shipping-options/test-out`,
payload,
adminReqConfig
)

const requirements = res.data.shipping_option.requirements

Expand All @@ -92,7 +92,27 @@ describe("/admin/shipping-options", () => {
)
})

it("fails to add a a requirement with an id if it does not exists", async () => {
it("should update a shipping option with price_type", async () => {
const api = useApi()

const payload = {
price_type: "calculated",
requirements: [],
}

const res = await api
.post(`/admin/shipping-options/test-out`, payload, adminReqConfig)
.catch(console.log)

expect(res.status).toEqual(200)
expect(res.data.shipping_option).toEqual(
expect.objectContaining({
price_type: "calculated",
})
)
})

it("should fail to add a a requirement with an id if it does not exists", async () => {
const api = useApi()

const payload = {
Expand All @@ -113,11 +133,7 @@ describe("/admin/shipping-options", () => {
}

const res = await api
.post(`/admin/shipping-options/test-out`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
.post(`/admin/shipping-options/test-out`, payload, adminReqConfig)
.catch((err) => {
return err.response
})
Expand All @@ -128,7 +144,7 @@ describe("/admin/shipping-options", () => {
)
})

it("it successfully updates a set of existing requirements", async () => {
it("should successfully updates a set of existing requirements", async () => {
const api = useApi()

const payload = {
Expand All @@ -148,19 +164,19 @@ describe("/admin/shipping-options", () => {
}

const res = await api
.post(`/admin/shipping-options/test-option-req`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
.post(
`/admin/shipping-options/test-option-req`,
payload,
adminReqConfig
)
.catch((err) => {
console.log(err.response.data.message)
})

expect(res.status).toEqual(200)
})

it("it successfully updates a set of existing requirements by updating one and deleting the other", async () => {
it("should successfully updates a set of existing requirements by updating one and deleting the other", async () => {
const api = useApi()

const payload = {
Expand All @@ -174,19 +190,19 @@ describe("/admin/shipping-options", () => {
}

const res = await api
.post(`/admin/shipping-options/test-option-req`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
.post(
`/admin/shipping-options/test-option-req`,
payload,
adminReqConfig
)
.catch((err) => {
console.log(err.response.data.message)
})

expect(res.status).toEqual(200)
})

it("successfully updates a set of requirements because max. subtotal >= min. subtotal", async () => {
it("should successfully updates a set of requirements because max. subtotal >= min. subtotal", async () => {
const api = useApi()

const payload = {
Expand All @@ -205,11 +221,11 @@ describe("/admin/shipping-options", () => {
}

const res = await api
.post(`/admin/shipping-options/test-option-req`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
.post(
`/admin/shipping-options/test-option-req`,
payload,
adminReqConfig
)
.catch((err) => {
console.log(err.response.data.message)
})
Expand All @@ -219,7 +235,7 @@ describe("/admin/shipping-options", () => {
expect(res.data.shipping_option.requirements[1].amount).toEqual(200)
})

it("fails to updates a set of requirements because max. subtotal <= min. subtotal", async () => {
it("should fail to updates a set of requirements because max. subtotal <= min. subtotal", async () => {
const api = useApi()

const payload = {
Expand All @@ -238,11 +254,11 @@ describe("/admin/shipping-options", () => {
}

const res = await api
.post(`/admin/shipping-options/test-option-req`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
.post(
`/admin/shipping-options/test-option-req`,
payload,
adminReqConfig
)
.catch((err) => {
return err.response
})
Expand All @@ -267,11 +283,7 @@ describe("/admin/shipping-options", () => {
{
fulfillment_providers: ["test-ful"],
},
{
headers: {
"x-medusa-access-token": "test_token",
},
}
adminReqConfig
)

const manager = dbConnection.manager
Expand All @@ -297,7 +309,7 @@ describe("/admin/shipping-options", () => {
await db.teardown()
})

it("creates a shipping option with requirements", async () => {
it("should create a shipping option with requirements", async () => {
const api = useApi()
payload.requirements = [
{
Expand All @@ -310,29 +322,29 @@ describe("/admin/shipping-options", () => {
},
]

const res = await api.post(`/admin/shipping-options`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
const res = await api.post(
`/admin/shipping-options`,
payload,
adminReqConfig
)

expect(res.status).toEqual(200)
expect(res.data.shipping_option.requirements.length).toEqual(2)
})

it("creates a shipping option with no requirements", async () => {
it("should create a shipping option with no requirements", async () => {
const api = useApi()
const res = await api.post(`/admin/shipping-options`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
const res = await api.post(
`/admin/shipping-options`,
payload,
adminReqConfig
)

expect(res.status).toEqual(200)
expect(res.data.shipping_option.requirements.length).toEqual(0)
})

it("fails on same requirement types", async () => {
it("should fail on same requirement types", async () => {
const api = useApi()
payload.requirements = [
{
Expand All @@ -346,19 +358,15 @@ describe("/admin/shipping-options", () => {
]

try {
await api.post(`/admin/shipping-options`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
await api.post(`/admin/shipping-options`, payload, adminReqConfig)
} catch (error) {
expect(error.response.data.message).toEqual(
"Only one requirement of each type is allowed"
)
}
})

it("fails when min_subtotal > max_subtotal", async () => {
it("should fail when min_subtotal > max_subtotal", async () => {
const api = useApi()
payload.requirements = [
{
Expand All @@ -372,11 +380,7 @@ describe("/admin/shipping-options", () => {
]

try {
await api.post(`/admin/shipping-options`, payload, {
headers: {
"x-medusa-access-token": "test_token",
},
})
await api.post(`/admin/shipping-options`, payload, adminReqConfig)
} catch (error) {
expect(error.response.data.message).toEqual(
"Max. subtotal must be greater than Min. subtotal"
Expand All @@ -395,24 +399,19 @@ describe("/admin/shipping-options", () => {
await db.teardown()
})

it("lists shipping options", async () => {
it("should list shipping options", async () => {
const api = useApi()
const res = await api.get(`/admin/shipping-options`, {
headers: {
"x-medusa-access-token": "test_token",
},
})
const res = await api.get(`/admin/shipping-options`, adminReqConfig)

expect(res.status).toEqual(200)
})

it("lists admin only shipping options", async () => {
it("should list admin only shipping options", async () => {
const api = useApi()
const res = await api.get(`/admin/shipping-options?admin_only=true`, {
headers: {
"x-medusa-access-token": "test_token",
},
})
const res = await api.get(
`/admin/shipping-options?admin_only=true`,
adminReqConfig
)

expect(res.status).toEqual(200)
expect(res.data.shipping_options).toEqual(
Expand All @@ -425,13 +424,12 @@ describe("/admin/shipping-options", () => {
)
})

it("lists return shipping options", async () => {
it("should list return shipping options", async () => {
const api = useApi()
const res = await api.get(`/admin/shipping-options?is_return=true`, {
headers: {
"x-medusa-access-token": "test_token",
},
})
const res = await api.get(
`/admin/shipping-options?is_return=true`,
adminReqConfig
)

expect(res.status).toEqual(200)
expect(res.data.shipping_options).toEqual(
Expand All @@ -444,15 +442,11 @@ describe("/admin/shipping-options", () => {
)
})

it("lists shipping options without return and admin options", async () => {
it("should list shipping options without return and admin options", async () => {
const api = useApi()
const res = await api.get(
`/admin/shipping-options?is_return=false&admin_only=true`,
{
headers: {
"x-medusa-access-token": "test_token",
},
}
adminReqConfig
)

expect(res.status).toEqual(200)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { ShippingOptionServiceMock } from "../../../../../services/__mocks__/shipping-option"
import { request } from "../../../../../helpers/test-request"

describe("POST /admin/shipping-options", () => {
describe("successful creation", () => {
Expand Down
Loading

0 comments on commit 7a83b51

Please sign in to comment.