Skip to content

Commit

Permalink
Merge branch 'develop' into feat/raise-exception-in-core-if-reservati…
Browse files Browse the repository at this point in the history
…on-quantity-exceeds-available-quantity
  • Loading branch information
kodiakhq[bot] authored Mar 16, 2023
2 parents 04a33b4 + 061a600 commit bb44dc7
Show file tree
Hide file tree
Showing 85 changed files with 1,373 additions and 188 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-melons-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/client-types": patch
"@medusajs/medusa": patch
---

feat(oas): declare x-expanded-relations - Admin
5 changes: 5 additions & 0 deletions .changeset/hungry-papayas-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): fix rank order changing on category update
6 changes: 6 additions & 0 deletions .changeset/loud-pillows-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/client-types": patch
"@medusajs/medusa": patch
---

feat(oas): declare x-expanded-relations - Store
5 changes: 5 additions & 0 deletions .changeset/lucky-vans-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"medusa-react": patch
---

fix(medusa-react): invalidate products query on category delete
45 changes: 45 additions & 0 deletions integration-tests/api/__tests__/admin/product-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,35 @@ describe("/admin/product-categories", () => {

expect(errorFetchingDeleted.response.status).toEqual(404)
})

it("deleting a product category reorders siblings accurately", async () => {
const api = useApi()

const deleteResponse = await api.delete(
`/admin/product-categories/${productCategory.id}`,
adminHeaders
).catch(e => e)

expect(deleteResponse.status).toEqual(200)

const siblingsResponse = await api.get(
`/admin/product-categories?parent_category_id=${productCategoryParent.id}`,
adminHeaders
).catch(e => e)

expect(siblingsResponse.data.product_categories).toEqual(
[
expect.objectContaining({
id: productCategory1.id,
rank: 0
}),
expect.objectContaining({
id: productCategory2.id,
rank: 1
}),
]
)
})
})

describe("POST /admin/product-categories/:id", () => {
Expand Down Expand Up @@ -779,6 +808,22 @@ describe("/admin/product-categories", () => {
)
})

it("updating properties other than rank should not change its rank", async () => {
const api = useApi()

expect(productCategory.rank).toEqual(0)

const response = await api.post(
`/admin/product-categories/${productCategory.id}`,
{
name: "different-name",
},
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.product_category.rank).toEqual(productCategory.rank)
})

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

Expand Down
18 changes: 0 additions & 18 deletions integration-tests/api/__tests__/store/__snapshots__/auth.js.snap

This file was deleted.

21 changes: 12 additions & 9 deletions integration-tests/api/__tests__/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ describe("/store/auth", () => {

expect(response.status).toEqual(200)
expect(response.data.customer.password_hash).toEqual(undefined)
expect(response.data.customer).toMatchSnapshot({
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "test",
last_name: "testesen",
phone: null,
email: "[email protected]",
})
expect(response.data.customer).toEqual(
expect.objectContaining({
id: expect.any(String),
created_at: expect.any(String),
updated_at: expect.any(String),
first_name: "test",
last_name: "testesen",
phone: null,
email: "[email protected]",
shipping_addresses: expect.arrayContaining([]),
})
)
})

describe("Store session management", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe("/store/payment-collections", () => {
})
)

expect(response.status).toEqual(207)
expect(response.status).toEqual(200)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ export const useAdminUpdateProductCategory = (
return useMutation(
(payload: AdminPostProductCategoriesCategoryReq) =>
client.admin.productCategories.update(id, payload),
buildOptions(
queryClient,
[
adminProductCategoryKeys.lists(),
adminProductCategoryKeys.detail(id),
adminProductKeys.details(),
],
options
buildOptions(
queryClient,
[
adminProductCategoryKeys.lists(),
adminProductCategoryKeys.detail(id),
adminProductKeys.details(),
],
options
)
)
)
}

/**
Expand All @@ -95,11 +95,16 @@ export const useAdminDeleteProductCategory = (
) => {
const { client } = useMedusa()
const queryClient = useQueryClient()

return useMutation(
() => client.admin.productCategories.delete(id),
buildOptions(
queryClient,
[adminProductCategoryKeys.lists(), adminProductCategoryKeys.detail(id)],
[
adminProductCategoryKeys.lists(),
adminProductCategoryKeys.detail(id),
adminProductKeys.all
],
options
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Request, Response } from "express"
import { EntityManager } from "typeorm"

import ProductCollectionService from "../../../../services/product-collection"
import { defaultAdminCollectionsRelations } from "./index"

/**
* @oas [post] /admin/collections/{id}/products/batch
Expand Down Expand Up @@ -67,12 +68,16 @@ export default async (req: Request, res: Response) => {
)

const manager: EntityManager = req.scope.resolve("manager")
const collection = await manager.transaction(async (transactionManager) => {
const updated = await manager.transaction(async (transactionManager) => {
return await productCollectionService
.withTransaction(transactionManager)
.addProducts(id, validatedBody.product_ids)
})

const collection = await productCollectionService.retrieve(updated.id, {
relations: defaultAdminCollectionsRelations,
})

res.status(200).json({ collection })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IsNotEmpty, IsObject, IsOptional, IsString } from "class-validator"
import ProductCollectionService from "../../../../services/product-collection"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
import { defaultAdminCollectionsRelations } from "."

/**
* @oas [post] /admin/collections
Expand Down Expand Up @@ -77,7 +78,9 @@ export default async (req: Request, res: Response) => {
.create(validatedBody)
})

const collection = await productCollectionService.retrieve(created.id)
const collection = await productCollectionService.retrieve(created.id, {
relations: defaultAdminCollectionsRelations,
})

res.status(200).json({ collection })
}
Expand Down
4 changes: 4 additions & 0 deletions packages/medusa/src/api/routes/admin/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export type AdminDeleteProductsFromCollectionRes = {
/**
* @schema AdminCollectionsRes
* type: object
* x-expanded-relations:
* field: collection
* relations:
* - products
* required:
* - collection
* properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IsObject, IsOptional, IsString } from "class-validator"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
import ProductCollectionService from "../../../../services/product-collection"
import { defaultAdminCollectionsRelations } from "."

/**
* @oas [post] /admin/collections/{id}
Expand Down Expand Up @@ -82,7 +83,9 @@ export default async (req: Request, res: Response) => {
.update(id, validatedBody)
})

const collection = await productCollectionService.retrieve(updated.id)
const collection = await productCollectionService.retrieve(updated.id, {
relations: defaultAdminCollectionsRelations,
})

res.status(200).json({ collection })
}
Expand Down
5 changes: 5 additions & 0 deletions packages/medusa/src/api/routes/admin/customers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export default (app) => {
/**
* @schema AdminCustomersRes
* type: object
* x-expanded-relations:
* field: customer
* relations:
* - orders
* - shipping_addresses
* required:
* - customer
* properties:
Expand Down
21 changes: 21 additions & 0 deletions packages/medusa/src/api/routes/admin/discounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ export const defaultAdminDiscountConditionRelations = ["discount_rule"]
/**
* @schema AdminDiscountsRes
* type: object
* x-expanded-relations:
* field: discount
* relations:
* - parent_discount
* - regions
* - rule
* - rule.conditions
* eager:
* - regions.fulfillment_providers
* - regions.payment_providers
* required:
* - discount
* properties:
Expand All @@ -236,6 +246,10 @@ export type AdminDiscountsRes = {
/**
* @schema AdminDiscountConditionsRes
* type: object
* x-expanded-relations:
* field: discount_condition
* relations:
* - discount_rule
* required:
* - discount_condition
* properties:
Expand Down Expand Up @@ -299,6 +313,13 @@ export type AdminDiscountConditionsDeleteRes = DeleteResponse & {
/**
* @schema AdminDiscountsListRes
* type: object
* x-expanded-relations:
* field: discounts
* relations:
* - parent_discount
* - regions
* - rule
* - rule.conditions
* required:
* - discounts
* - count
Expand Down
66 changes: 65 additions & 1 deletion packages/medusa/src/api/routes/admin/draft-orders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,67 @@ export const defaultAdminDraftOrdersFields: (keyof DraftOrder)[] = [
export type AdminPostDraftOrdersDraftOrderRegisterPaymentRes = {
order: Order
}

/**
* @schema AdminDraftOrdersRes
* type: object
* x-expanded-relations:
* field: draft_order
* relations:
* - order
* - cart
* - cart.items
* - cart.items.adjustments
* - cart.billing_address
* - cart.customer
* - cart.discounts
* - cart.discounts.rule
* - cart.items
* - cart.items.adjustments
* - cart.payment
* - cart.payment_sessions
* - cart.region
* - cart.region.payment_providers
* - cart.shipping_address
* - cart.shipping_methods
* - cart.shipping_methods.shipping_option
* eager:
* - cart.region.fulfillment_providers
* - cart.region.payment_providers
* - cart.shipping_methods.shipping_option
* implicit:
* - cart.discounts
* - cart.discounts.rule
* - cart.gift_cards
* - cart.items
* - cart.items.adjustments
* - cart.items.tax_lines
* - cart.items.variant
* - cart.items.variant.product
* - cart.region
* - cart.region.tax_rates
* - cart.shipping_address
* - cart.shipping_methods
* - cart.shipping_methods.tax_lines
* totals:
* - cart.discount_total
* - cart.gift_card_tax_total
* - cart.gift_card_total
* - cart.item_tax_total
* - cart.refundable_amount
* - cart.refunded_total
* - cart.shipping_tax_total
* - cart.shipping_total
* - cart.subtotal
* - cart.tax_total
* - cart.total
* - cart.items.discount_total
* - cart.items.gift_card_total
* - cart.items.original_tax_total
* - cart.items.original_total
* - cart.items.refundable
* - cart.items.subtotal
* - cart.items.tax_total
* - cart.items.total
* required:
* - draft_order
* properties:
Expand Down Expand Up @@ -142,6 +199,13 @@ export type AdminDraftOrdersDeleteRes = DeleteResponse
/**
* @schema AdminDraftOrdersListRes
* type: object
* x-expanded-relations:
* field: draft_orders
* relations:
* - order
* - cart
* - cart.items
* - cart.items.adjustments
* required:
* - draft_orders
* - count
Expand Down
Loading

0 comments on commit bb44dc7

Please sign in to comment.