feat(medusa, medusa-js, medusa-react): Implement Sales Channel retrieval (#1793)
This commit is contained in:
committed by
GitHub
parent
e115518dda
commit
263a661031
@@ -0,0 +1,13 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`sales channels GET /admin/sales-channels/:id should retrieve the requested sales channel 1`] = `
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test description",
|
||||
"id": Any<String>,
|
||||
"is_disabled": false,
|
||||
"name": "test name",
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
@@ -2,10 +2,19 @@ const path = require("path")
|
||||
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
const { useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const { simpleSalesChannelFactory, } = require("../../factories")
|
||||
|
||||
const startServerWithEnvironment =
|
||||
require("../../../helpers/start-server-with-environment").default
|
||||
|
||||
const adminReqConfig = {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
describe("sales channels", () => {
|
||||
@@ -36,7 +45,46 @@ describe("sales channels", () => {
|
||||
})
|
||||
})
|
||||
describe("POST /admin/sales-channels", () => {})
|
||||
describe("GET /admin/sales-channels/:id", () => {})
|
||||
|
||||
describe("GET /admin/sales-channels/:id", () => {
|
||||
let salesChannel
|
||||
|
||||
beforeEach(async() => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "test name",
|
||||
description: "test description",
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async() => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("should retrieve the requested sales channel", async() => {
|
||||
const api = useApi()
|
||||
const response = await api.get(
|
||||
`/admin/sales-channels/${salesChannel.id}`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.sales_channel).toBeTruthy()
|
||||
expect(response.data.sales_channel).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
name: salesChannel.name,
|
||||
description: salesChannel.description,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/sales-channels/:id", () => {})
|
||||
describe("DELETE /admin/sales-channels/:id", () => {})
|
||||
})
|
||||
|
||||
@@ -15,3 +15,4 @@ export * from "./simple-shipping-method-factory"
|
||||
export * from "./simple-product-type-tax-rate-factory"
|
||||
export * from "./simple-price-list-factory"
|
||||
export * from "./simple-batch-job-factory"
|
||||
export * from "./simple-sales-channel-factory"
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Connection } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { SalesChannel } from "@medusajs/medusa"
|
||||
|
||||
export type SalesChannelFactoryData = {
|
||||
name?: string
|
||||
description?: string
|
||||
is_disabled?: boolean
|
||||
}
|
||||
|
||||
export const simpleSalesChannelFactory = async (
|
||||
connection: Connection,
|
||||
data: SalesChannelFactoryData = {},
|
||||
seed?: number
|
||||
): Promise<SalesChannel> => {
|
||||
if (typeof seed !== "undefined") {
|
||||
faker.seed(seed)
|
||||
}
|
||||
|
||||
const manager = connection.manager
|
||||
|
||||
const salesChannel = manager.create(SalesChannel, {
|
||||
id: `simple-id-${Math.random() * 1000}`,
|
||||
name: data.name || faker.name.firstName(),
|
||||
description: data.description || faker.name.lastName(),
|
||||
is_disabled:
|
||||
typeof data.is_disabled !== undefined ? data.is_disabled : false,
|
||||
})
|
||||
|
||||
return await manager.save(salesChannel)
|
||||
}
|
||||
Reference in New Issue
Block a user