Skip to content

Commit

Permalink
Merge branch 'develop' into chore/remove-admin-from-npx
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Mar 13, 2023
2 parents 2e742d9 + 2f42ed3 commit d4a6bbe
Show file tree
Hide file tree
Showing 483 changed files with 2,953 additions and 2,228 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-plants-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/admin-ui": patch
"@medusajs/medusa": patch
---

feat(medusa, admin-ui): increase tree depth + scope categories on store + allow categories relation in products API
5 changes: 5 additions & 0 deletions .changeset/shy-poems-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/admin-ui": patch
---

fix(admin-ui): update edit-allocation sidebar
5 changes: 5 additions & 0 deletions .changeset/soft-pets-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/client-types": patch
---

feat(types): package scaffolding for generated types
5 changes: 5 additions & 0 deletions .changeset/tame-forks-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/openapi-typescript-codegen": minor
---

feat(codegen): x-expanded-relations
1 change: 0 additions & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
paths-ignore:
- "docs/**"
- "www/**"
- "packages/admin-ui/**"

jobs:
setup:
Expand Down
280 changes: 6 additions & 274 deletions integration-tests/api/__tests__/admin/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { initDb, useDb } = require("../../../helpers/use-db")

const adminSeeder = require("../../helpers/admin-seeder")
const productSeeder = require("../../helpers/product-seeder")
const { ProductCategory } = require("@medusajs/medusa")

const {
ProductVariant,
Expand All @@ -19,7 +18,6 @@ const priceListSeeder = require("../../helpers/price-list-seeder")
const {
simpleProductFactory,
simpleDiscountFactory,
simpleProductCategoryFactory,
simpleSalesChannelFactory,
simpleRegionFactory,
} = require("../../factories")
Expand All @@ -46,6 +44,7 @@ describe("/admin/products", () => {
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({
cwd,
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true }
})
})

Expand Down Expand Up @@ -454,127 +453,6 @@ describe("/admin/products", () => {
}
})

describe("Product Category filtering", () => {
let categoryWithProduct
let categoryWithoutProduct
let nestedCategoryWithProduct
let nested2CategoryWithProduct
const nestedCategoryWithProductId = "nested-category-with-product-id"
const nested2CategoryWithProductId = "nested2-category-with-product-id"
const categoryWithProductId = "category-with-product-id"
const categoryWithoutProductId = "category-without-product-id"

beforeEach(async () => {
const manager = dbConnection.manager
categoryWithProduct = await simpleProductCategoryFactory(dbConnection, {
id: categoryWithProductId,
name: "category with Product",
products: [{ id: testProductId }],
})

nestedCategoryWithProduct = await simpleProductCategoryFactory(
dbConnection,
{
id: nestedCategoryWithProductId,
name: "nested category with Product1",
parent_category: categoryWithProduct,
products: [{ id: testProduct1Id }],
}
)

nested2CategoryWithProduct = await simpleProductCategoryFactory(
dbConnection,
{
id: nested2CategoryWithProductId,
name: "nested2 category with Product1",
parent_category: nestedCategoryWithProduct,
products: [{ id: testProductFilteringId1 }],
}
)

categoryWithoutProduct = await simpleProductCategoryFactory(
dbConnection,
{
id: categoryWithoutProductId,
name: "category without product",
}
)
})

it("returns a list of products in product category without category children", async () => {
const api = useApi()
const params = `category_id[]=${categoryWithProductId}`
const response = await api.get(
`/admin/products?${params}`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: testProductId,
}),
])
})

it("returns a list of products in product category without category children explicitly set to false", async () => {
const api = useApi()
const params = `category_id[]=${categoryWithProductId}&include_category_children=false`
const response = await api.get(
`/admin/products?${params}`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual([
expect.objectContaining({
id: testProductId,
}),
])
})

it("returns a list of products in product category with category children", async () => {
const api = useApi()

const params = `category_id[]=${categoryWithProductId}&include_category_children=true`
const response = await api.get(
`/admin/products?${params}`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(3)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: testProduct1Id,
}),
expect.objectContaining({
id: testProductId,
}),
expect.objectContaining({
id: testProductFilteringId1,
}),
])
)
})

it("returns no products when product category with category children does not have products", async () => {
const api = useApi()

const params = `category_id[]=${categoryWithoutProductId}&include_category_children=true`
const response = await api.get(
`/admin/products?${params}`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(0)
})
})

it("returns a list of products with tags", async () => {
const api = useApi()

Expand Down Expand Up @@ -1573,7 +1451,6 @@ describe("/admin/products", () => {
],
type: null,
collection: null,
categories: [],
})
)
})
Expand Down Expand Up @@ -1604,152 +1481,6 @@ describe("/admin/products", () => {
})
)
})

describe("Categories", () => {
let categoryWithProduct
let categoryWithoutProduct
const categoryWithProductId = "category-with-product-id"
const categoryWithoutProductId = "category-without-product-id"

beforeEach(async () => {
const manager = dbConnection.manager
categoryWithProduct = await manager.create(ProductCategory, {
id: categoryWithProductId,
name: "category with Product",
products: [{ id: testProductId }],
})
await manager.save(categoryWithProduct)

categoryWithoutProduct = await manager.create(ProductCategory, {
id: categoryWithoutProductId,
name: "category without product",
})
await manager.save(categoryWithoutProduct)
})

it("creates a product with categories associated to it", async () => {
const api = useApi()

const payload = {
title: "Test",
description: "test-product-description",
categories: [
{ id: categoryWithProductId },
{ id: categoryWithoutProductId },
],
}

const response = await api
.post("/admin/products", payload, adminHeaders)
.catch((e) => e)

expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
categories: [
expect.objectContaining({
id: categoryWithProductId,
}),
expect.objectContaining({
id: categoryWithoutProductId,
}),
],
})
)
})

it("throws error when creating a product with invalid category ID", async () => {
const api = useApi()
const categoryNotFoundId = "category-doesnt-exist"

const payload = {
title: "Test",
description: "test-product-description",
categories: [{ id: categoryNotFoundId }],
}

const error = await api
.post("/admin/products", payload, adminHeaders)
.catch((e) => e)

expect(error.response.status).toEqual(404)
expect(error.response.data.type).toEqual("not_found")
expect(error.response.data.message).toEqual(
`Product_category with product_category_id ${categoryNotFoundId} does not exist.`
)
})

it("updates a product's categories", async () => {
const api = useApi()

const payload = {
categories: [{ id: categoryWithoutProductId }],
}

const response = await api.post(
`/admin/products/${testProductId}`,
payload,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
id: testProductId,
handle: "test-product",
categories: [
expect.objectContaining({
id: categoryWithoutProductId,
}),
],
})
)
})

it("remove all categories of a product", async () => {
const api = useApi()
const category = await simpleProductCategoryFactory(dbConnection, {
id: "existing-category",
name: "existing category",
products: [{ id: "test-product" }],
})

const payload = {
categories: [],
}

const response = await api.post(
"/admin/products/test-product",
payload,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.product).toEqual(
expect.objectContaining({
id: "test-product",
categories: [],
})
)
})

it("throws error if product categories input is incorreect", async () => {
const api = useApi()
const payload = {
categories: [{ incorrect: "test-category-d2B" }],
}

const error = await api
.post("/admin/products/test-product", payload, adminHeaders)
.catch((e) => e)

expect(error.response.status).toEqual(400)
expect(error.response.data.type).toEqual("invalid_data")
expect(error.response.data.message).toEqual(
"property incorrect should not exist, id must be a string"
)
})
})
})

describe("DELETE /admin/products/:id/options/:option_id", () => {
Expand Down Expand Up @@ -2032,6 +1763,7 @@ describe("/admin/products", () => {

it("successfully updates a variant's prices by replacing a price", async () => {
const api = useApi()
const variantId = "test-variant"
const data = {
prices: [
{
Expand All @@ -2043,7 +1775,7 @@ describe("/admin/products", () => {

const response = await api
.post(
"/admin/products/test-product/variants/test-variant",
`/admin/products/test-product/variants/${variantId}`,
data,
adminHeaders
)
Expand All @@ -2052,9 +1784,9 @@ describe("/admin/products", () => {
})

expect(response.status).toEqual(200)

expect(response.data.product.variants[0].prices.length).toEqual(1)
expect(response.data.product.variants[0].prices).toEqual(
const variant = response.data.product.variants.find(v => v.id === variantId)
expect(variant.prices.length).toEqual(1)
expect(variant.prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
amount: 4500,
Expand Down
Loading

0 comments on commit d4a6bbe

Please sign in to comment.