add is_disabled to create sales channel (#1928)

**What**
- include `is_disabled` when creating a sales channel

**Why**
- To enable creation of draft sales channels
This commit is contained in:
Philip Korsholm
2022-07-28 14:17:11 +00:00
committed by GitHub
parent 97c48a5ab9
commit 5ce8839c54
3 changed files with 130 additions and 94 deletions
@@ -1,5 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`sales channels DELETE /admin/sales-channels/:id should delete the requested sales channel 1`] = `
Object {
"deleted": true,
"id": Any<String>,
"object": "sales-channel",
}
`;
exports[`sales channels GET /admin/orders/:id expands sales channel for single 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>,
}
`;
exports[`sales channels GET /admin/orders?expand=sales_channels expands sales channel with parameter 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>,
}
`;
exports[`sales channels GET /admin/sales-channels should list the sales channel 1`] = ` exports[`sales channels GET /admin/sales-channels should list the sales channel 1`] = `
Object { Object {
"count": 2, "count": 2,
@@ -66,38 +98,6 @@ Object {
} }
`; `;
exports[`sales channels DELETE /admin/sales-channels/:id should delete the requested sales channel 1`] = `
Object {
"deleted": true,
"id": Any<String>,
"object": "sales-channel",
}
`;
exports[`sales channels GET /admin/orders/:id expands sales channel for single 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>,
}
`;
exports[`sales channels GET /admin/orders?expand=sales_channels expands sales channel with parameter 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>,
}
`;
exports[`sales channels GET /admin/sales-channels/:id should retrieve the requested sales channel 1`] = ` exports[`sales channels GET /admin/sales-channels/:id should retrieve the requested sales channel 1`] = `
Object { Object {
"created_at": Any<String>, "created_at": Any<String>,
@@ -110,6 +110,15 @@ Object {
} }
`; `;
exports[`sales channels POST /admin/sales-channels successfully creates a disabled sales channel 1`] = `
Object {
"sales_channel": ObjectContaining {
"is_disabled": true,
"name": "sales channel name",
},
}
`;
exports[`sales channels POST /admin/sales-channels successfully creates a sales channel 1`] = ` exports[`sales channels POST /admin/sales-channels successfully creates a sales channel 1`] = `
Object { Object {
"sales_channel": ObjectContaining { "sales_channel": ObjectContaining {
@@ -12,8 +12,8 @@ const {
simpleCartFactory, simpleCartFactory,
} = require("../../factories") } = require("../../factories")
const { simpleOrderFactory } = require("../../factories") const { simpleOrderFactory } = require("../../factories")
const orderSeeder = require("../../helpers/order-seeder"); const orderSeeder = require("../../helpers/order-seeder")
const productSeeder = require("../../helpers/product-seeder"); const productSeeder = require("../../helpers/product-seeder")
const startServerWithEnvironment = const startServerWithEnvironment =
require("../../../helpers/start-server-with-environment").default require("../../../helpers/start-server-with-environment").default
@@ -88,7 +88,8 @@ describe("sales channels", () => {
}) })
describe("GET /admin/sales-channels", () => { describe("GET /admin/sales-channels", () => {
let salesChannel1, salesChannel2 let salesChannel1
let salesChannel2
beforeEach(async () => { beforeEach(async () => {
try { try {
@@ -113,10 +114,7 @@ describe("sales channels", () => {
it("should list the sales channel", async () => { it("should list the sales channel", async () => {
const api = useApi() const api = useApi()
const response = await api.get( const response = await api.get(`/admin/sales-channels/`, adminReqConfig)
`/admin/sales-channels/`,
adminReqConfig
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.sales_channels).toBeTruthy() expect(response.data.sales_channels).toBeTruthy()
@@ -144,7 +142,7 @@ describe("sales channels", () => {
created_at: expect.any(String), created_at: expect.any(String),
updated_at: expect.any(String), updated_at: expect.any(String),
}, },
]) ]),
}) })
}) })
@@ -172,7 +170,7 @@ describe("sales channels", () => {
created_at: expect.any(String), created_at: expect.any(String),
updated_at: expect.any(String), updated_at: expect.any(String),
}, },
]) ]),
}) })
}) })
@@ -200,7 +198,7 @@ describe("sales channels", () => {
created_at: expect.any(String), created_at: expect.any(String),
updated_at: expect.any(String), updated_at: expect.any(String),
}, },
]) ]),
}) })
}) })
}) })
@@ -270,6 +268,31 @@ describe("sales channels", () => {
await db.teardown() await db.teardown()
}) })
it("successfully creates a disabled sales channel", async () => {
const api = useApi()
const newSalesChannel = {
name: "sales channel name",
is_disabled: true,
}
const response = await api
.post("/admin/sales-channels", newSalesChannel, adminReqConfig)
.catch((err) => {
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.sales_channel).toBeTruthy()
expect(response.data).toMatchSnapshot({
sales_channel: expect.objectContaining({
name: newSalesChannel.name,
is_disabled: true,
}),
})
})
it("successfully creates a sales channel", async () => { it("successfully creates a sales channel", async () => {
const api = useApi() const api = useApi()
@@ -621,7 +644,7 @@ describe("sales channels", () => {
let salesChannel let salesChannel
let product let product
beforeEach(async() => { beforeEach(async () => {
try { try {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
product = await simpleProductFactory(dbConnection, { product = await simpleProductFactory(dbConnection, {
@@ -631,7 +654,7 @@ describe("sales channels", () => {
salesChannel = await simpleSalesChannelFactory(dbConnection, { salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name", name: "test name",
description: "test description", description: "test description",
products: [product] products: [product],
}) })
} catch (e) { } catch (e) {
console.error(e) console.error(e)
@@ -643,12 +666,12 @@ describe("sales channels", () => {
await db.teardown() await db.teardown()
}) })
it("should remove products from a sales channel", async() => { it("should remove products from a sales channel", async () => {
const api = useApi() const api = useApi()
let attachedProduct = await dbConnection.manager.findOne(Product, { let attachedProduct = await dbConnection.manager.findOne(Product, {
where: { id: product.id }, where: { id: product.id },
relations: ["sales_channels"] relations: ["sales_channels"],
}) })
expect(attachedProduct.sales_channels.length).toBe(1) expect(attachedProduct.sales_channels.length).toBe(1)
@@ -659,28 +682,28 @@ describe("sales channels", () => {
name: "test name", name: "test name",
description: "test description", description: "test description",
is_disabled: false, is_disabled: false,
}) }),
]) ])
) )
const payload = { const payload = {
product_ids: [{ id: product.id }] product_ids: [{ id: product.id }],
} }
await api.delete( await api.delete(
`/admin/sales-channels/${salesChannel.id}/products/batch`, `/admin/sales-channels/${salesChannel.id}/products/batch`,
{ {
...adminReqConfig, ...adminReqConfig,
data: payload, data: payload,
}, }
) )
// Validate idempotency // Validate idempotency
const response = await api.delete( const response = await api.delete(
`/admin/sales-channels/${salesChannel.id}/products/batch`, `/admin/sales-channels/${salesChannel.id}/products/batch`,
{ {
...adminReqConfig, ...adminReqConfig,
data: payload, data: payload,
}, }
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -695,7 +718,7 @@ describe("sales channels", () => {
attachedProduct = await dbConnection.manager.findOne(Product, { attachedProduct = await dbConnection.manager.findOne(Product, {
where: { id: product.id }, where: { id: product.id },
relations: ["sales_channels"] relations: ["sales_channels"],
}) })
expect(attachedProduct.sales_channels.length).toBe(0) expect(attachedProduct.sales_channels.length).toBe(0)
@@ -706,7 +729,7 @@ describe("sales channels", () => {
let salesChannel let salesChannel
let product let product
beforeEach(async() => { beforeEach(async () => {
try { try {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, { salesChannel = await simpleSalesChannelFactory(dbConnection, {
@@ -727,17 +750,17 @@ describe("sales channels", () => {
await db.teardown() await db.teardown()
}) })
it("should add products to a sales channel", async() => { it("should add products to a sales channel", async () => {
const api = useApi() const api = useApi()
const payload = { const payload = {
product_ids: [{ id: product.id }] product_ids: [{ id: product.id }],
} }
let response = await api.post( const response = await api.post(
`/admin/sales-channels/${salesChannel.id}/products/batch`, `/admin/sales-channels/${salesChannel.id}/products/batch`,
payload, payload,
adminReqConfig adminReqConfig
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -751,9 +774,9 @@ describe("sales channels", () => {
deleted_at: null, deleted_at: null,
}) })
let attachedProduct = await dbConnection.manager.findOne(Product, { const attachedProduct = await dbConnection.manager.findOne(Product, {
where: { id: product.id }, where: { id: product.id },
relations: ["sales_channels"] relations: ["sales_channels"],
}) })
expect(attachedProduct.sales_channels.length).toBe(1) expect(attachedProduct.sales_channels.length).toBe(1)
@@ -764,7 +787,7 @@ describe("sales channels", () => {
name: "test name", name: "test name",
description: "test description", description: "test description",
is_disabled: false, is_disabled: false,
}) }),
]) ])
) )
}) })
@@ -774,7 +797,7 @@ describe("sales channels", () => {
describe("GET /admin/orders", () => { describe("GET /admin/orders", () => {
let order let order
beforeEach(async() => { beforeEach(async () => {
try { try {
await adminSeeder(dbConnection) await adminSeeder(dbConnection)
order = await simpleOrderFactory(dbConnection, { order = await simpleOrderFactory(dbConnection, {
@@ -790,21 +813,21 @@ describe("sales channels", () => {
} }
}) })
afterEach(async() => { afterEach(async () => {
const db = useDb() const db = useDb()
await db.teardown() await db.teardown()
}) })
it("should successfully lists orders that belongs to the requested sales channels", async() => { it("should successfully lists orders that belongs to the requested sales channels", async () => {
const api = useApi() const api = useApi()
const response = await api.get( const response = await api.get(
`/admin/orders?sales_channel_id[]=${order.sales_channel_id}`, `/admin/orders?sales_channel_id[]=${order.sales_channel_id}`,
{ {
headers: { headers: {
authorization: "Bearer test_token", authorization: "Bearer test_token",
}, },
} }
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
@@ -834,7 +857,7 @@ describe("sales channels", () => {
salesChannel = await simpleSalesChannelFactory(dbConnection, { salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name", name: "test name",
description: "test description", description: "test description",
products: [product] products: [product],
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)
@@ -842,33 +865,33 @@ describe("sales channels", () => {
} }
}) })
afterEach(async() => { afterEach(async () => {
const db = useDb() const db = useDb()
await db.teardown() await db.teardown()
}) })
it("should returns a list of products that belongs to the requested sales channels", async() => { it("should returns a list of products that belongs to the requested sales channels", async () => {
const api = useApi() const api = useApi()
const response = await api const response = await api
.get(`/admin/products?sales_channel_id[]=${salesChannel.id}`, { .get(`/admin/products?sales_channel_id[]=${salesChannel.id}`, {
headers: { headers: {
Authorization: "Bearer test_token", Authorization: "Bearer test_token",
}, },
}) })
.catch((err) => { .catch((err) => {
console.log(err) console.log(err)
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products.length).toEqual(1) expect(response.data.products.length).toEqual(1)
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
expect.arrayContaining([ expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: productData.id, id: productData.id,
title: productData.title title: productData.title,
}), }),
]) ])
) )
}) })
}) })
@@ -1,5 +1,5 @@
import { Request, Response } from "express" import { Request, Response } from "express"
import { IsOptional, IsString } from "class-validator" import { IsBoolean, IsOptional, IsString } from "class-validator"
import SalesChannelService from "../../../../services/sales-channel" import SalesChannelService from "../../../../services/sales-channel"
import { CreateSalesChannelInput } from "../../../../types/sales-channels" import { CreateSalesChannelInput } from "../../../../types/sales-channels"
@@ -44,4 +44,8 @@ export class AdminPostSalesChannelsReq {
@IsString() @IsString()
@IsOptional() @IsOptional()
description: string description: string
@IsBoolean()
@IsOptional()
is_disabled?: boolean
} }