Skip to content

Commit

Permalink
Merge branch 'develop' into fix/oas-inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-medusajs authored Feb 22, 2023
2 parents efda8f4 + 287c829 commit 0378708
Show file tree
Hide file tree
Showing 322 changed files with 480 additions and 340 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-dryers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(oas): include `/admin` and `/store` in paths URLs
5 changes: 5 additions & 0 deletions .changeset/warm-cobras-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): fixes bug for mpath incorrectly updated for nested categories
124 changes: 109 additions & 15 deletions integration-tests/api/__tests__/admin/product-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ describe("/admin/product-categories", () => {
describe("POST /admin/product-categories", () => {
beforeEach(async () => {
await adminSeeder(dbConnection)

productCategoryParent = await simpleProductCategoryFactory(dbConnection, {
name: "category parent",
handle: "category-parent",
})

productCategory = await simpleProductCategoryFactory(dbConnection, {
name: "category",
handle: "category",
parent_category: productCategoryParent,
})
})

afterEach(async () => {
Expand All @@ -267,11 +278,6 @@ describe("/admin/product-categories", () => {
})

it("successfully creates a product category", async () => {
productCategoryParent = await simpleProductCategoryFactory(dbConnection, {
name: "category parent",
handle: "category-parent",
})

const api = useApi()

const response = await api.post(
Expand All @@ -280,7 +286,7 @@ describe("/admin/product-categories", () => {
name: "test",
handle: "test",
is_internal: true,
parent_category_id: productCategoryParent.id,
parent_category_id: productCategory.id,
},
adminHeaders
)
Expand All @@ -296,13 +302,49 @@ describe("/admin/product-categories", () => {
created_at: expect.any(String),
updated_at: expect.any(String),
parent_category: expect.objectContaining({
id: productCategoryParent.id
id: productCategory.id
}),
category_children: []
}),
})
)
})

it("root parent returns children correctly on creating new category", async () => {
const api = useApi()

const response = await api.post(
`/admin/product-categories`,
{
name: "last descendant",
parent_category_id: productCategory.id,
},
adminHeaders
)
const lastDescendant = response.data.product_category

const parentResponse = await api.get(
`/admin/product-categories/${productCategoryParent.id}`,
adminHeaders
)

expect(parentResponse.data.product_category).toEqual(
expect.objectContaining({
id: productCategoryParent.id,
category_children: [
expect.objectContaining({
id: productCategory.id,
category_children: [
expect.objectContaining({
id: lastDescendant.id,
category_children: []
})
]
})
]
})
)
})
})

describe("DELETE /admin/product-categories/:id", () => {
Expand Down Expand Up @@ -381,14 +423,27 @@ describe("/admin/product-categories", () => {
beforeEach(async () => {
await adminSeeder(dbConnection)

productCategoryParent = await simpleProductCategoryFactory(dbConnection, {
name: "category parent",
handle: "category-parent",
})

productCategory = await simpleProductCategoryFactory(dbConnection, {
name: "skinny jeans",
handle: "skinny-jeans",
name: "category",
handle: "category",
parent_category: productCategoryParent,
})

productCategory2 = await simpleProductCategoryFactory(dbConnection, {
name: "sweater",
handle: "sweater",
productCategoryChild = await simpleProductCategoryFactory(dbConnection, {
name: "category child",
handle: "category-child",
parent_category: productCategory,
})

productCategoryChild2 = await simpleProductCategoryFactory(dbConnection, {
name: "category child 2",
handle: "category-child-2",
parent_category: productCategoryChild,
})
})

Expand Down Expand Up @@ -437,13 +492,13 @@ describe("/admin/product-categories", () => {
const api = useApi()

const response = await api.post(
`/admin/product-categories/${productCategory.id}`,
`/admin/product-categories/${productCategoryChild2.id}`,
{
name: "test",
handle: "test",
is_internal: true,
is_active: true,
parent_category_id: productCategory2.id,
parent_category_id: productCategory.id,
},
adminHeaders
)
Expand All @@ -459,13 +514,52 @@ describe("/admin/product-categories", () => {
created_at: expect.any(String),
updated_at: expect.any(String),
parent_category: expect.objectContaining({
id: productCategory2.id,
id: productCategory.id,
}),
category_children: []
}),
})
)
})

it("root parent returns children correctly on updating new category", async () => {
const api = useApi()

const response = await api.post(
`/admin/product-categories/${productCategoryChild2.id}`,
{
parent_category_id: productCategory.id,
},
adminHeaders
)
const lastDescendant = response.data.product_category

const parentResponse = await api.get(
`/admin/product-categories/${productCategoryParent.id}`,
adminHeaders
)

expect(parentResponse.data.product_category).toEqual(
expect.objectContaining({
id: productCategoryParent.id,
category_children: [
expect.objectContaining({
id: productCategory.id,
category_children: [
expect.objectContaining({
id: productCategoryChild.id,
category_children: []
}),
expect.objectContaining({
id: productCategoryChild2.id,
category_children: []
})
]
})
]
})
)
})
})

describe("POST /admin/product-categories/:id/products/batch", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/oas/admin-spec3-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ tags:
- name: User
description: User endpoints that allow handling users in Medusa.
servers:
- url: https://api.medusa-commerce.com/admin
- url: https://api.medusa-commerce.com
paths: { }
components:
responses:
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/oas/store-spec3-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ tags:
- name: Swap
description: Swap endpoints that allow handling swaps in Medusa.
servers:
- url: https://api.medusa-commerce.com/store
- url: https://api.medusa-commerce.com
paths: { }
components:
responses:
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/routes/admin/apps/authorize-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OauthService } from "../../../../services"
import { validator } from "../../../../utils/validator"

/**
* @oas [post] /apps/authorizations
* @oas [post] /admin/apps/authorizations
* operationId: "PostApps"
* summary: "Generate Token for App"
* description: "Generates a token for an application."
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/routes/admin/apps/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OauthService } from "../../../../services"

/**
* @oas [get] /apps
* @oas [get] /admin/apps
* operationId: "GetApps"
* summary: "List Applications"
* description: "Retrieve a list of applications."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AuthService from "../../../../services/auth"
import { validator } from "../../../../utils/validator"

/**
* @oas [post] /auth
* @oas [post] /admin/auth
* operationId: "PostAuth"
* summary: "User Login"
* x-authenticated: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @oas [delete] /auth
* @oas [delete] /admin/auth
* operationId: "DeleteAuth"
* summary: "User Logout"
* x-authenticated: true
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/api/routes/admin/auth/get-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UserService from "../../../../services/user"
import _ from "lodash"

/**
* @oas [get] /auth
* @oas [get] /admin/auth
* operationId: "GetAuth"
* summary: "Get Current User"
* x-authenticated: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BatchJobService } from "../../../../services"
import { EntityManager } from "typeorm"

/**
* @oas [post] /batch-jobs/{id}/cancel
* @oas [post] /admin/batch-jobs/{id}/cancel
* operationId: "PostBatchJobsBatchJobCancel"
* summary: "Cancel a Batch Job"
* description: "Marks a batch job as canceled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BatchJobService } from "../../../../services"
import { EntityManager } from "typeorm"

/**
* @oas [post] /batch-jobs/{id}/confirm
* @oas [post] /admin/batch-jobs/{id}/confirm
* operationId: "PostBatchJobsBatchJobConfirmProcessing"
* summary: "Confirm a Batch Job"
* description: "Confirms that a previously requested batch job should be executed."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EntityManager } from "typeorm"
import { validator } from "../../../../utils/validator"

/**
* @oas [post] /batch-jobs
* @oas [post] /admin/batch-jobs
* operationId: "PostBatchJobs"
* summary: "Create a Batch Job"
* description: "Creates a Batch Job."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @oas [get] /batch-jobs/{id}
* @oas [get] /admin/batch-jobs/{id}
* operationId: "GetBatchJobsBatchJob"
* summary: "Get a Batch Job"
* description: "Retrieves a Batch Job."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { pickBy } from "lodash"
import { isDefined } from "medusa-core-utils"

/**
* @oas [get] /batch-jobs
* @oas [get] /admin/batch-jobs
* operationId: "GetBatchJobs"
* summary: "List Batch Jobs"
* description: "Retrieve a list of Batch Jobs."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EntityManager } from "typeorm"
import ProductCollectionService from "../../../../services/product-collection"

/**
* @oas [post] /collections/{id}/products/batch
* @oas [post] /admin/collections/{id}/products/batch
* operationId: "PostProductsToCollection"
* summary: "Update Products"
* description: "Updates products associated with a Product Collection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Request, Response } from "express"
import { EntityManager } from "typeorm"

/**
* @oas [post] /collections
* @oas [post] /admin/collections
* operationId: "PostCollections"
* summary: "Create a Collection"
* description: "Creates a Product Collection."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EntityManager } from "typeorm"
import ProductCollectionService from "../../../../services/product-collection"

/**
* @oas [delete] /collections/{id}
* @oas [delete] /admin/collections/{id}
* operationId: "DeleteCollectionsCollection"
* summary: "Delete a Collection"
* description: "Deletes a Product Collection."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ProductCollectionService from "../../../../services/product-collection"
import { defaultAdminCollectionsRelations } from "."

/**
* @oas [get] /collections/{id}
* @oas [get] /admin/collections/{id}
* operationId: "GetCollectionsCollection"
* summary: "Get a Collection"
* description: "Retrieves a Product Collection."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ProductCollectionService from "../../../../services/product-collection"
import { Type } from "class-transformer"

/**
* @oas [get] /collections
* @oas [get] /admin/collections
* operationId: "GetCollections"
* summary: "List Collections"
* description: "Retrieve a list of Product Collection."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EntityManager } from "typeorm"
import ProductCollectionService from "../../../../services/product-collection"

/**
* @oas [delete] /collections/{id}/products/batch
* @oas [delete] /admin/collections/{id}/products/batch
* operationId: "DeleteProductsFromCollection"
* summary: "Remove Product"
* description: "Removes products associated with a Product Collection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EntityManager } from "typeorm"
import ProductCollectionService from "../../../../services/product-collection"

/**
* @oas [post] /collections/{id}
* @oas [post] /admin/collections/{id}
* operationId: "PostCollectionsCollection"
* summary: "Update a Collection"
* description: "Updates a Product Collection."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ExtendedRequest } from "../../../../types/global"
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"

/**
* @oas [get] /currencies
* @oas [get] /admin/currencies
* operationId: "GetCurrencies"
* summary: "List Currency"
* description: "Retrieves a list of Currency"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/ta
import { EntityManager } from "typeorm"

/**
* @oas [post] /currencies/{code}
* @oas [post] /admin/currencies/{code}
* operationId: "PostCurrenciesCurrency"
* summary: "Update a Currency"
* description: "Update a Currency"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ValidateNested } from "class-validator"
import { validator } from "../../../../utils/validator"

/**
* @oas [post] /customer-groups/{id}/customers/batch
* @oas [post] /admin/customer-groups/{id}/customers/batch
* operationId: "PostCustomerGroupsGroupCustomersBatch"
* summary: "Add Customers"
* description: "Adds a list of customers, represented by id's, to a customer group."
Expand Down
Loading

0 comments on commit 0378708

Please sign in to comment.