feat(medusa, medusa-js, medusa-react): Implement Sales Channel list (#1815)
**What** Support sales channel list in medusa, medusa-js and medusa-react **How** By implementing a new endpoint and the associated service method as well as the repository methods. Medusa-js new list method in the resource Medusa-react new hook in the queries **Tests** Endpoint test Service test Integration test Hook tests Fixes CORE-280
This commit is contained in:
committed by
GitHub
parent
c20d720040
commit
a1a5848827
@@ -1,5 +1,71 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`sales channels GET /admin/sales-channels should list the sales channel 1`] = `
|
||||
Object {
|
||||
"count": 2,
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"sales_channels": ArrayContaining [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description 2",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name 2",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`sales channels GET /admin/sales-channels should list the sales channel using free text search 1`] = `
|
||||
Object {
|
||||
"count": 1,
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"sales_channels": ArrayContaining [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description 2",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name 2",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`sales channels GET /admin/sales-channels should list the sales channel using properties filters 1`] = `
|
||||
Object {
|
||||
"count": 1,
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"sales_channels": ArrayContaining [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`sales channels DELETE /admin/sales-channels/:id should delete the requested sales channel 1`] = `
|
||||
Object {
|
||||
"deleted": true,
|
||||
|
||||
@@ -1521,7 +1521,7 @@ describe("/admin/orders", () => {
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(2)
|
||||
expect(response.data.orders).toEqual([
|
||||
expect(response.data.orders).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
shipping_address: expect.objectContaining({ first_name: "lebron" }),
|
||||
@@ -1530,7 +1530,7 @@ describe("/admin/orders", () => {
|
||||
id: "discount-order",
|
||||
shipping_address: expect.objectContaining({ first_name: "lebron" }),
|
||||
}),
|
||||
])
|
||||
]))
|
||||
})
|
||||
|
||||
it("successfully lists orders with greater than", async () => {
|
||||
|
||||
@@ -86,6 +86,124 @@ describe("sales channels", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/sales-channels", () => {
|
||||
let salesChannel1, salesChannel2
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
salesChannel1 = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "test name",
|
||||
description: "test description",
|
||||
})
|
||||
salesChannel2 = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "test name 2",
|
||||
description: "test description 2",
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should list the sales channel", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/sales-channels/`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.sales_channels).toBeTruthy()
|
||||
expect(response.data.sales_channels.length).toBe(2)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
count: 2,
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
sales_channels: expect.arrayContaining([
|
||||
{
|
||||
id: expect.any(String),
|
||||
name: salesChannel1.name,
|
||||
description: salesChannel1.description,
|
||||
is_disabled: false,
|
||||
deleted_at: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
{
|
||||
id: expect.any(String),
|
||||
name: salesChannel2.name,
|
||||
description: salesChannel2.description,
|
||||
is_disabled: false,
|
||||
deleted_at: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it("should list the sales channel using free text search", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/sales-channels/?q=2`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.sales_channels).toBeTruthy()
|
||||
expect(response.data.sales_channels.length).toBe(1)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
count: 1,
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
sales_channels: expect.arrayContaining([
|
||||
{
|
||||
id: expect.any(String),
|
||||
name: salesChannel2.name,
|
||||
description: salesChannel2.description,
|
||||
is_disabled: false,
|
||||
deleted_at: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it("should list the sales channel using properties filters", async () => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/sales-channels/?name=test+name`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.sales_channels).toBeTruthy()
|
||||
expect(response.data.sales_channels.length).toBe(1)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
count: 1,
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
sales_channels: expect.arrayContaining([
|
||||
{
|
||||
id: expect.any(String),
|
||||
name: salesChannel1.name,
|
||||
description: salesChannel1.description,
|
||||
is_disabled: false,
|
||||
deleted_at: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/sales-channels/:id", () => {
|
||||
let sc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user