Fix(medusa): Return correct region count (#4514)

* update method for listing regions

* add changeset

* fix unit tests

* fix nit

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2023-07-13 08:59:26 +02:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent cfd3e396cf
commit 56d1d326d4
6 changed files with 78 additions and 35 deletions
@@ -1,6 +1,6 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { RegionServiceMock } from "../../../../../services/__mocks__/region"
import { request } from "../../../../../helpers/test-request"
const defaultFields = [
"id",
@@ -46,8 +46,8 @@ describe("GET /admin/regions", () => {
})
it("calls service list", () => {
expect(RegionServiceMock.list).toHaveBeenCalledTimes(1)
expect(RegionServiceMock.list).toHaveBeenCalledWith(
expect(RegionServiceMock.listAndCount).toHaveBeenCalledTimes(1)
expect(RegionServiceMock.listAndCount).toHaveBeenCalledWith(
{},
{
select: defaultFields,
@@ -81,8 +81,8 @@ describe("GET /admin/regions", () => {
})
it("calls service list", () => {
expect(RegionServiceMock.list).toHaveBeenCalledTimes(1)
expect(RegionServiceMock.list).toHaveBeenCalledWith(
expect(RegionServiceMock.listAndCount).toHaveBeenCalledTimes(1)
expect(RegionServiceMock.listAndCount).toHaveBeenCalledWith(
{},
{
select: defaultFields,
@@ -105,14 +105,14 @@ export default async (req, res) => {
take: validated.limit,
}
const regions: Region[] = await regionService.list(
const [regions, count] = await regionService.listAndCount(
_.pickBy(filterableFields, identity),
listConfig
)
res.json({
regions,
count: regions.length,
count,
offset: validated.offset,
limit: validated.limit,
})