feat(medusa, stock-location-next): add list-stock-locations endpoint to api-v2 (#6788)

* initial create

* add list for stock locations

* add changeset

* redo changes for stock locatino module'

* add changeset

* naming

* prep for pr

* move integration tests

* fix pr feedback

* add changeset

* update changeset

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
Philip Korsholm
2024-03-28 17:33:26 +01:00
committed by GitHub
co-authored by Riqwan Thamir
parent a6562d2a41
commit 18438a695a
10 changed files with 288 additions and 1 deletions
@@ -56,6 +56,101 @@ medusaIntegrationTestRunner({
})
})
describe("list stock locations", () => {
let location1
let location2
beforeEach(async () => {
const location1CreateResponse = await api.post(
`/admin/stock-locations`,
{
name: "Test Location 1",
address: {
address_1: "Test Address",
country_code: "US",
},
},
adminHeaders
)
location1 = location1CreateResponse.data.stock_location
const location2CreateResponse = await api.post(
`/admin/stock-locations`,
{
name: "Test Location 2",
address: {
address_1: "Test Address",
country_code: "US",
},
},
adminHeaders
)
location2 = location2CreateResponse.data.stock_location
})
it("should list stock locations", async () => {
const listLocationsResponse = await api.get(
"/admin/stock-locations",
adminHeaders
)
expect(listLocationsResponse.status).toEqual(200)
expect(listLocationsResponse.data.stock_locations).toEqual([
expect.objectContaining(location1),
expect.objectContaining(location2),
])
})
it("should filter stock locations by name", async () => {
const listLocationsResponse = await api.get(
"/admin/stock-locations?name=Test%20Location%201",
adminHeaders
)
expect(listLocationsResponse.status).toEqual(200)
expect(listLocationsResponse.data.stock_locations).toEqual([
expect.objectContaining(location1),
])
})
it("should filter stock locations by partial name with q parameter", async () => {
const listLocationsResponse = await api.get(
"/admin/stock-locations?q=ation%201",
adminHeaders
)
expect(listLocationsResponse.status).toEqual(200)
expect(listLocationsResponse.data.stock_locations).toEqual([
expect.objectContaining(location1),
])
})
it("should filter stock locations on sales_channel_id", async () => {
const remoteLinkService = appContainer.resolve(
ContainerRegistrationKeys.REMOTE_LINK
)
await remoteLinkService.create([
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: "default",
},
[Modules.STOCK_LOCATION]: {
stock_location_id: location1.id,
},
},
])
const listLocationsResponse = await api.get(
"/admin/stock-locations?sales_channel_id=default",
adminHeaders
)
expect(listLocationsResponse.status).toEqual(200)
expect(listLocationsResponse.data.stock_locations).toEqual([
expect.objectContaining(location1),
])
})
})
describe("Update stock locations", () => {
let stockLocationId