fix: add metadata to collection resp (#9514)

**What**
- Adds `metadata` to the default response for `/admin/collection` endpoints.
- Fixes tests to expect correct shape and not use objectContaining.

Fixes CC-551
This commit is contained in:
Sebastian Rindom
2024-10-09 15:52:59 +00:00
committed by GitHub
parent 0e11e89233
commit aeaedc8539
2 changed files with 42 additions and 27 deletions
@@ -77,17 +77,16 @@ medusaIntegrationTestRunner({
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data).toEqual( expect(response.data).toEqual({
expect.objectContaining({ collection: {
collection: expect.objectContaining({ id: expect.stringMatching(/^pcol_*/),
id: expect.stringMatching(/^pcol_*/), title: "New collection",
title: "New collection", handle: "test-new-collection",
handle: "test-new-collection", created_at: expect.any(String),
created_at: expect.any(String), updated_at: expect.any(String),
updated_at: expect.any(String), metadata: null,
}), },
}) })
)
}) })
it("lists collections", async () => { it("lists collections", async () => {
@@ -96,22 +95,33 @@ medusaIntegrationTestRunner({
expect(response.data).toEqual( expect(response.data).toEqual(
expect.objectContaining({ expect.objectContaining({
count: 3, count: 3,
limit: 10,
offset: 0,
collections: expect.arrayContaining([ collections: expect.arrayContaining([
expect.objectContaining({ {
id: baseCollection2.id,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: baseCollection1.id,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: baseCollection.id, id: baseCollection.id,
created_at: expect.any(String), created_at: expect.any(String),
updated_at: expect.any(String), updated_at: expect.any(String),
}), handle: "test-collection",
metadata: null,
title: "test-collection",
},
{
id: baseCollection1.id,
created_at: expect.any(String),
updated_at: expect.any(String),
handle: "test-collection1",
metadata: null,
title: "test-collection1",
},
{
id: baseCollection2.id,
created_at: expect.any(String),
updated_at: expect.any(String),
handle: "test-collection2",
metadata: null,
title: "test-collection2",
},
]), ]),
}) })
) )
@@ -127,11 +137,14 @@ medusaIntegrationTestRunner({
expect.objectContaining({ expect.objectContaining({
count: 1, count: 1,
collections: expect.arrayContaining([ collections: expect.arrayContaining([
expect.objectContaining({ {
id: baseCollection.id, id: baseCollection.id,
created_at: expect.any(String), created_at: expect.any(String),
updated_at: expect.any(String), updated_at: expect.any(String),
}), handle: "test-collection",
metadata: null,
title: "test-collection",
},
]), ]),
}) })
) )
@@ -154,13 +167,14 @@ medusaIntegrationTestRunner({
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data).toEqual( expect(response.data).toEqual(
expect.objectContaining({ expect.objectContaining({
collection: expect.objectContaining({ collection: {
id: expect.stringMatching(/^pcol_*/), id: expect.stringMatching(/^pcol_*/),
title: "test collection creation", title: "test collection creation",
handle: "test-handle-creation", handle: "test-handle-creation",
created_at: expect.any(String), created_at: expect.any(String),
updated_at: expect.any(String), updated_at: expect.any(String),
}), metadata: null,
},
}) })
) )
}) })
@@ -4,6 +4,7 @@ export const defaultAdminCollectionFields = [
"handle", "handle",
"created_at", "created_at",
"updated_at", "updated_at",
"metadata",
] ]
export const retrieveTransformQueryConfig = { export const retrieveTransformQueryConfig = {