feat: GET customer group endpoint

This commit is contained in:
fPolic
2022-02-16 11:55:21 +01:00
parent c2241d1101
commit 21d99a44a9
6 changed files with 121 additions and 0 deletions
@@ -0,0 +1,27 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { CustomerGroupServiceMock } from "../../../../../services/__mocks__/customer-group"
describe("GET /customer-groups", () => {
let subject
const id = "123"
beforeAll(async () => {
subject = await request("GET", `/admin/customer-groups/${id}`, {
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
},
},
})
})
it("returns 200", () => {
expect(subject.status).toEqual(200)
})
it("calls CustomerGroupService get", () => {
expect(CustomerGroupServiceMock.retrieve).toHaveBeenCalledTimes(1)
expect(CustomerGroupServiceMock.retrieve).toHaveBeenCalledWith(id)
})
})
@@ -0,0 +1,32 @@
import { CustomerGroupService } from "../../../../services"
/**
* @oas [get] /customer-group/{id}
* operationId: "GetCustomerGroups"
* summary: "Retrieve a CustomerGroup"
* description: "Retrieves a Customer Group."
* x-authenticated: true
* parameters:
* - (path) id=* {string} The id of the Customer Group.
* tags:
* - CustomerGroup
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* customerGroup:
* $ref: "#/components/schemas/customer-group"
*/
export default async (req, res) => {
const { id } = req.params
const customerGroupService: CustomerGroupService = req.scope.resolve(
"customerGroupService"
)
const customerGroup = await customerGroupService.retrieve(id)
res.json({ customerGroup })
}
@@ -8,6 +8,7 @@ const route = Router()
export default (app) => {
app.use("/customer-groups", route)
route.get("/:id", middlewares.wrap(require("./get-customer-group").default))
route.post("/", middlewares.wrap(require("./create-customer-group").default))
return app
}