Skip to content

Commit

Permalink
Merge branch 'develop' into chore/clean-up-models
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jan 29, 2024
2 parents 54d24ec + 8739070 commit d567a7f
Show file tree
Hide file tree
Showing 39 changed files with 781 additions and 82 deletions.
6 changes: 6 additions & 0 deletions .changeset/little-carrots-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/client-types": patch
"@medusajs/medusa": patch
---

fix(medusa): Adds support for ordering GET /admin/orders
17 changes: 17 additions & 0 deletions integration-tests/api/__tests__/admin/order/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ describe("/admin/orders", () => {
})
expect(response.status).toEqual(200)
})

it("gets orders ordered by display_id", async () => {
const api = useApi()

const response = await api
.get("/admin/orders?order=display_id", adminReqConfig)
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)

const sortedOrders = response.data.orders.sort((a, b) => {
return a.display_id - b.display_id
})

expect(response.data.orders).toEqual(sortedOrders)
})
})

describe("POST /admin/orders/:id", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("GET /admin/customer-groups", () => {
let dbConnection
let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should get all customer groups and its count", async () => {
await customerModuleService.createCustomerGroup({
name: "Test",
})

const api = useApi() as any
const response = await api.get(`/admin/customer-groups`, adminHeaders)

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.groups).toEqual([
expect.objectContaining({
id: expect.any(String),
name: "Test",
}),
])
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICustomerModuleService } from "@medusajs/types"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"
import { getContainer } from "../../../../environment-helpers/use-container"
import { initDb, useDb } from "../../../../environment-helpers/use-db"
import adminSeeder from "../../../../helpers/admin-seeder"

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("GET /admin/customers", () => {
let dbConnection
let appContainer
let shutdownServer
let customerModuleService: ICustomerModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
customerModuleService = appContainer.resolve(
ModuleRegistrationName.CUSTOMER
)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await adminSeeder(dbConnection)
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should get all customers and its count", async () => {
await customerModuleService.create([
{
first_name: "Test",
last_name: "Test",
email: "test@me.com",
},
])

const api = useApi() as any
const response = await api.get(`/admin/customers`, adminHeaders)

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1)
expect(response.data.customers).toEqual([
expect.objectContaining({
id: expect.any(String),
first_name: "Test",
last_name: "Test",
email: "test@me.com",
}),
])
})

it("should filter customers by last name", async () => {
await customerModuleService.create([
{
first_name: "Jane",
last_name: "Doe",
email: "jane@me.com",
},
{
first_name: "John",
last_name: "Doe",
email: "john@me.com",
},
{
first_name: "LeBron",
last_name: "James",
email: "lebron@me.com",
},
{
first_name: "John",
last_name: "Silver",
email: "johns@me.com",
},
])

const api = useApi() as any
const response = await api.get(
`/admin/customers?last_name=Doe`,
adminHeaders
)

expect(response.status).toEqual(200)
expect(response.data.count).toEqual(2)
expect(response.data.customers).toContainEqual(
expect.objectContaining({
id: expect.any(String),
first_name: "Jane",
last_name: "Doe",
email: "jane@me.com",
})
)
expect(response.data.customers).toContainEqual(
expect.objectContaining({
id: expect.any(String),
first_name: "John",
last_name: "Doe",
email: "john@me.com",
})
)
})
})
5 changes: 5 additions & 0 deletions integration-tests/plugins/medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ module.exports = {
resources: "shared",
resolve: "@medusajs/promotion",
},
[Modules.CUSTOMER]: {
scope: "internal",
resources: "shared",
resolve: "@medusajs/customer",
},
[Modules.SALES_CHANNEL]: {
scope: "internal",
resources: "shared",
Expand Down
1 change: 1 addition & 0 deletions integration-tests/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@medusajs/cache-inmemory": "workspace:*",
"@medusajs/customer": "workspace:^",
"@medusajs/event-bus-local": "workspace:*",
"@medusajs/inventory": "workspace:^",
"@medusajs/medusa": "workspace:*",
Expand Down
71 changes: 0 additions & 71 deletions packages/authentication/src/loaders/providers.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core-flows/src/definition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from "./cart"
export * from "./inventory"
export * from "./price-list"
export * from "./product"
export * from "./promotion"
1 change: 1 addition & 0 deletions packages/core-flows/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./definition"
export * from "./definitions"
export * as Handlers from "./handlers"
export * from "./promotion"
2 changes: 2 additions & 0 deletions packages/core-flows/src/promotion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./steps"
export * from "./workflows"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CampaignDTO, CreateCampaignDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { createCampaignsStep } from "../../handlers/promotion"
import { createCampaignsStep } from "../steps"

type WorkflowInput = { campaignsData: CreateCampaignDTO[] }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CreatePromotionDTO, PromotionDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { createPromotionsStep } from "../../handlers/promotion"
import { createPromotionsStep } from "../steps"

type WorkflowInput = { promotionsData: CreatePromotionDTO[] }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
import { deleteCampaignsStep } from "../../handlers/promotion"
import { deleteCampaignsStep } from "../steps"

type WorkflowInput = { ids: string[] }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
import { deletePromotionsStep } from "../../handlers/promotion"
import { deletePromotionsStep } from "../steps"

type WorkflowInput = { ids: string[] }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CampaignDTO, UpdateCampaignDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { updateCampaignsStep } from "../../handlers/promotion"
import { updateCampaignsStep } from "../steps"

type WorkflowInput = { campaignsData: UpdateCampaignDTO[] }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PromotionDTO, UpdatePromotionDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { updatePromotionsStep } from "../../handlers/promotion"
import { updatePromotionsStep } from "../steps"

type WorkflowInput = { promotionsData: UpdatePromotionDTO[] }

Expand Down
2 changes: 1 addition & 1 deletion packages/customer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@models": ["./src/models"],
"@services": ["./src/services"],
"@repositories": ["./src/repositories"],
"@types": ["./src/types"],
"@types": ["./src/types"]
}
},
"include": ["src"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ export interface AdminGetOrdersParams {
* Comma-separated fields that should be included in the returned order.
*/
fields?: string
/**
* A order field to sort-order the retrieved orders by.
*/
order?: string
}
Loading

0 comments on commit d567a7f

Please sign in to comment.