feat: add product status (#400)

* added statuses to product + unit test for updating status

* add update to product model

* added integration tests

* added integration test to validate that updating status to null results in invalid_data error

* removed comment

* update GET /store/products integration test

* fixed unit test with IdMap

* changed dbehaviour on invalid status input on admin list products

* updated migration to add status = published on all existing products + added integration test on GET /admin/products when status null is provided

* made requested changes to migration and GET /store/products

* fixed test

* made requested changes to migration
This commit is contained in:
Kasper Fabricius Kristensen authored and GitHub committed 2021-09-21 11:22:17 +02:00
1 parent 49a132976d
commit a82332da3e
17 files changed
+255 -36

No files matched your search

@@ -101,6 +101,7 @@ Object {
],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"tags": Array [
Object {
@@ -58,6 +58,7 @@ Object {
"mid_code": null,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"thumbnail": null,
"title": "test product",
@@ -228,6 +229,7 @@ Object {
"mid_code": null,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"thumbnail": null,
"title": "test product",
@@ -5,6 +5,7 @@ const { useApi } = require("../../../helpers/use-api")
const { initDb, useDb } = require("../../../helpers/use-db")
const productSeeder = require("../../helpers/product-seeder")
const adminSeeder = require("../../helpers/admin-seeder")
jest.setTimeout(30000)
describe("/store/products", () => {
let medusaProcess
@@ -26,6 +27,7 @@ describe("/store/products", () => {
beforeEach(async () => {
try {
await productSeeder(dbConnection)
await adminSeeder(dbConnection)
} catch (err) {
console.log(err)
throw err
@@ -261,5 +263,38 @@ describe("/store/products", () => {
expect(product.variants.some((variant) => variant.options)).toEqual(false)
})
it("lists all published products", async () => {
const api = useApi()
//update test-product status to published
await api
.post(
"/admin/products/test-product",
{
status: "published",
},
{
headers: {
Authorization: "Bearer test_token",
},
}
)
.catch((err) => {
console.log(err)
})
const response = await api.get("/store/products")
expect(response.status).toEqual(200)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product",
status: "published",
}),
])
)
})
})
})