feat: Convert several batch methods to the standardized format (#7116)
This commit is contained in:
@@ -188,14 +188,19 @@ medusaIntegrationTestRunner({
|
||||
const { api_key } = apiKeyRes.data
|
||||
|
||||
const keyWithChannelsRes = await api.post(
|
||||
`/admin/api-keys/${api_key.id}/sales-channels/batch`,
|
||||
`/admin/api-keys/${api_key.id}/sales-channels`,
|
||||
{
|
||||
create: [sales_channel.id],
|
||||
add: [sales_channel.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const { api_key: keyWithChannels } = keyWithChannelsRes.data
|
||||
const keyWithChannels = (
|
||||
await api.get(
|
||||
`/admin/api-keys/${api_key.id}?fields=*sales_channels`,
|
||||
adminHeaders
|
||||
)
|
||||
).data.api_key
|
||||
|
||||
expect(keyWithChannelsRes.status).toEqual(200)
|
||||
expect(keyWithChannels.title).toEqual("Test publishable KEY")
|
||||
@@ -229,9 +234,9 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const errorRes = await api
|
||||
.post(
|
||||
`/admin/api-keys/${apiKeyRes.data.api_key.id}/sales-channels/batch`,
|
||||
`/admin/api-keys/${apiKeyRes.data.api_key.id}/sales-channels`,
|
||||
{
|
||||
create: [sales_channel.id],
|
||||
add: [sales_channel.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -255,9 +260,9 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const errorRes = await api
|
||||
.post(
|
||||
`/admin/api-keys/${apiKeyRes.data.api_key.id}/sales-channels/batch`,
|
||||
`/admin/api-keys/${apiKeyRes.data.api_key.id}/sales-channels`,
|
||||
{
|
||||
create: ["phony"],
|
||||
add: ["phony"],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
@@ -292,14 +297,19 @@ medusaIntegrationTestRunner({
|
||||
const { api_key } = apiKeyRes.data
|
||||
|
||||
const keyWithChannelsRes = await api.post(
|
||||
`/admin/api-keys/${api_key.id}/sales-channels/batch`,
|
||||
`/admin/api-keys/${api_key.id}/sales-channels`,
|
||||
{
|
||||
create: [sales_channel.id],
|
||||
add: [sales_channel.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const { api_key: keyWithChannels } = keyWithChannelsRes.data
|
||||
const keyWithChannels = (
|
||||
await api.get(
|
||||
`/admin/api-keys/${api_key.id}?fields=*sales_channels`,
|
||||
adminHeaders
|
||||
)
|
||||
).data.api_key
|
||||
|
||||
expect(keyWithChannelsRes.status).toEqual(200)
|
||||
expect(keyWithChannels.title).toEqual("Test publishable KEY")
|
||||
@@ -311,14 +321,19 @@ medusaIntegrationTestRunner({
|
||||
])
|
||||
|
||||
const keyWithoutChannelsRes = await api.post(
|
||||
`/admin/api-keys/${api_key.id}/sales-channels/batch`,
|
||||
`/admin/api-keys/${api_key.id}/sales-channels`,
|
||||
{
|
||||
delete: [sales_channel.id],
|
||||
remove: [sales_channel.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const { api_key: keyWithoutChannels } = keyWithoutChannelsRes.data
|
||||
const keyWithoutChannels = (
|
||||
await api.get(
|
||||
`/admin/api-keys/${api_key.id}?fields=*sales_channels`,
|
||||
adminHeaders
|
||||
)
|
||||
).data.api_key
|
||||
|
||||
expect(keyWithoutChannelsRes.status).toEqual(200)
|
||||
expect(keyWithoutChannels.title).toEqual("Test publishable KEY")
|
||||
@@ -348,14 +363,19 @@ medusaIntegrationTestRunner({
|
||||
const { api_key } = apiKeyRes.data
|
||||
|
||||
const keyWithChannelsRes = await api.post(
|
||||
`/admin/api-keys/${api_key.id}/sales-channels/batch`,
|
||||
`/admin/api-keys/${api_key.id}/sales-channels`,
|
||||
{
|
||||
create: [sales_channel.id],
|
||||
add: [sales_channel.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const { api_key: keyWithChannels } = keyWithChannelsRes.data
|
||||
const keyWithChannels = (
|
||||
await api.get(
|
||||
`/admin/api-keys/${api_key.id}?fields=*sales_channels`,
|
||||
adminHeaders
|
||||
)
|
||||
).data.api_key
|
||||
|
||||
expect(keyWithChannelsRes.status).toEqual(200)
|
||||
expect(keyWithChannels.title).toEqual("Test publishable KEY")
|
||||
|
||||
@@ -2998,8 +2998,7 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.added).toHaveLength(1)
|
||||
expect(response.data.removed).toHaveLength(1)
|
||||
expect(response.data.collection).toBeTruthy()
|
||||
|
||||
const collection = (
|
||||
await api.get(
|
||||
|
||||
@@ -318,9 +318,9 @@ medusaIntegrationTestRunner({
|
||||
scId = scResponse.data.sales_channel.id
|
||||
|
||||
await api.post(
|
||||
`/admin/stock-locations/${location}/sales-channels/batch/add`,
|
||||
`/admin/stock-locations/${location}/sales-channels`,
|
||||
{
|
||||
sales_channel_ids: [scId],
|
||||
add: [scId],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
@@ -827,7 +827,7 @@ medusaIntegrationTestRunner({
|
||||
describe("POST /admin/sales-channels/:id/products/batch", () => {
|
||||
// BREAKING CHANGE: Endpoint has changed
|
||||
// from: /admin/sales-channels/:id/products/batch
|
||||
// to: /admin/sales-channels/:id/products/batch/add
|
||||
// to: /admin/sales-channels/:id/products
|
||||
|
||||
let { salesChannel, product } = {}
|
||||
|
||||
@@ -860,12 +860,14 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add products to a sales channel", async () => {
|
||||
const payload = {
|
||||
product_ids: breaking(
|
||||
() => [{ id: product.id }],
|
||||
() => [product.id]
|
||||
),
|
||||
}
|
||||
const payload = breaking(
|
||||
() => ({
|
||||
product_ids: [{ id: product.id }],
|
||||
}),
|
||||
() => ({
|
||||
add: [product.id],
|
||||
})
|
||||
)
|
||||
|
||||
const response = await breaking(
|
||||
async () => {
|
||||
@@ -877,7 +879,7 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
async () => {
|
||||
return await api.post(
|
||||
`/admin/sales-channels/${salesChannel.id}/products/batch/add`,
|
||||
`/admin/sales-channels/${salesChannel.id}/products`,
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
@@ -308,8 +308,8 @@ medusaIntegrationTestRunner({
|
||||
|
||||
it("should add sales channels to a location", async () => {
|
||||
const salesChannelResponse = await api.post(
|
||||
`/admin/stock-locations/${location.id}/sales-channels/batch/add?fields=*sales_channels`,
|
||||
{ sales_channel_ids: [salesChannel.id] },
|
||||
`/admin/stock-locations/${location.id}/sales-channels?fields=*sales_channels`,
|
||||
{ add: [salesChannel.id] },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
@@ -356,16 +356,16 @@ medusaIntegrationTestRunner({
|
||||
location = locationResponse.data.stock_location
|
||||
|
||||
await api.post(
|
||||
`/admin/stock-locations/${location.id}/sales-channels/batch/add?fields=*sales_channels`,
|
||||
{ sales_channel_ids: [salesChannel1.id, salesChannel2.id] },
|
||||
`/admin/stock-locations/${location.id}/sales-channels?fields=*sales_channels`,
|
||||
{ add: [salesChannel1.id, salesChannel2.id] },
|
||||
adminHeaders
|
||||
)
|
||||
})
|
||||
|
||||
it("should remove sales channels from a location", async () => {
|
||||
const salesChannelResponse = await api.post(
|
||||
`/admin/stock-locations/${location.id}/sales-channels/batch/remove?fields=*sales_channels`,
|
||||
{ sales_channel_ids: [salesChannel1.id] },
|
||||
`/admin/stock-locations/${location.id}/sales-channels?fields=*sales_channels`,
|
||||
{ remove: [salesChannel1.id] },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user