chore: Move stock location tests to HTTP folder (#7615)
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
|||||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||||
import { getProductFixture } from "../../../../helpers/fixtures"
|
import { getProductFixture } from "../../../../helpers/fixtures"
|
||||||
|
|
||||||
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let inventoryItem1
|
let inventoryItem1
|
||||||
|
|||||||
+102
-225
@@ -1,66 +1,25 @@
|
|||||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import {
|
import {
|
||||||
adminHeaders,
|
adminHeaders,
|
||||||
createAdminUser,
|
createAdminUser,
|
||||||
} from "../../../../helpers/create-admin-user"
|
} from "../../../../helpers/create-admin-user"
|
||||||
|
|
||||||
import { IStockLocationServiceNext } from "@medusajs/types"
|
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
|
||||||
|
|
||||||
const { medusaIntegrationTestRunner } = require("medusa-test-utils")
|
const { medusaIntegrationTestRunner } = require("medusa-test-utils")
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
env: {
|
|
||||||
MEDUSA_FF_MEDUSA_V2: true,
|
|
||||||
},
|
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let appContainer
|
let location1
|
||||||
let service: IStockLocationServiceNext
|
let location2
|
||||||
|
let salesChannel1
|
||||||
|
let salesChannel2
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
appContainer = getContainer()
|
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||||
|
|
||||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
location1 = (
|
||||||
|
await api.post(
|
||||||
service = appContainer.resolve(ModuleRegistrationName.STOCK_LOCATION)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("create stock location", () => {
|
|
||||||
it("should create a stock location with a name and address", async () => {
|
|
||||||
const address = {
|
|
||||||
address_1: "Test Address",
|
|
||||||
country_code: "US",
|
|
||||||
}
|
|
||||||
const location = {
|
|
||||||
name: "Test Location",
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await api.post(
|
|
||||||
"/admin/stock-locations",
|
|
||||||
{
|
|
||||||
...location,
|
|
||||||
address,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
|
||||||
expect(response.data.stock_location).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
...location,
|
|
||||||
address: expect.objectContaining(address),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("list stock locations", () => {
|
|
||||||
let location1
|
|
||||||
let location2
|
|
||||||
beforeEach(async () => {
|
|
||||||
const location1CreateResponse = await api.post(
|
|
||||||
`/admin/stock-locations`,
|
`/admin/stock-locations`,
|
||||||
{
|
{
|
||||||
name: "Test Location 1",
|
name: "Test Location 1",
|
||||||
@@ -71,8 +30,10 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
location1 = location1CreateResponse.data.stock_location
|
).data.stock_location
|
||||||
const location2CreateResponse = await api.post(
|
|
||||||
|
location2 = (
|
||||||
|
await api.post(
|
||||||
`/admin/stock-locations`,
|
`/admin/stock-locations`,
|
||||||
{
|
{
|
||||||
name: "Test Location 2",
|
name: "Test Location 2",
|
||||||
@@ -83,9 +44,57 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
location2 = location2CreateResponse.data.stock_location
|
).data.stock_location
|
||||||
})
|
|
||||||
|
|
||||||
|
salesChannel1 = (
|
||||||
|
await api.post(
|
||||||
|
`/admin/sales-channels`,
|
||||||
|
{
|
||||||
|
name: "Test SC",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.sales_channel
|
||||||
|
|
||||||
|
salesChannel2 = (
|
||||||
|
await api.post(
|
||||||
|
`/admin/sales-channels`,
|
||||||
|
{
|
||||||
|
name: "Test SC 2",
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.sales_channel
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("create stock location", () => {
|
||||||
|
it("should create a stock location with a name and address", async () => {
|
||||||
|
const response = await api.post(
|
||||||
|
"/admin/stock-locations",
|
||||||
|
{
|
||||||
|
name: "Test Location",
|
||||||
|
address: {
|
||||||
|
address_1: "Test Address",
|
||||||
|
country_code: "US",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.stock_location).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
name: "Test Location",
|
||||||
|
address: expect.objectContaining({
|
||||||
|
address_1: "Test Address",
|
||||||
|
country_code: "US",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("list stock locations", () => {
|
||||||
it("should list stock locations", async () => {
|
it("should list stock locations", async () => {
|
||||||
const listLocationsResponse = await api.get(
|
const listLocationsResponse = await api.get(
|
||||||
"/admin/stock-locations",
|
"/admin/stock-locations",
|
||||||
@@ -124,23 +133,16 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should filter stock locations on sales_channel_id", async () => {
|
it("should filter stock locations on sales_channel_id", async () => {
|
||||||
const remoteLinkService = appContainer.resolve(
|
await api.post(
|
||||||
ContainerRegistrationKeys.REMOTE_LINK
|
`/admin/stock-locations/${location1.id}/sales-channels`,
|
||||||
|
{
|
||||||
|
add: [salesChannel1.id],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
await remoteLinkService.create([
|
|
||||||
{
|
|
||||||
[Modules.SALES_CHANNEL]: {
|
|
||||||
sales_channel_id: "default",
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
|
||||||
stock_location_id: location1.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const listLocationsResponse = await api.get(
|
const listLocationsResponse = await api.get(
|
||||||
"/admin/stock-locations?sales_channel_id=default",
|
`/admin/stock-locations?sales_channel_id=${salesChannel1.id}`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -152,63 +154,33 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Update stock locations", () => {
|
describe("Update stock locations", () => {
|
||||||
let stockLocationId
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const createResponse = await api.post(
|
|
||||||
`/admin/stock-locations`,
|
|
||||||
{
|
|
||||||
name: "test location",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
stockLocationId = createResponse.data.stock_location.id
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should update stock location name", async () => {
|
it("should update stock location name", async () => {
|
||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
`/admin/stock-locations/${stockLocationId}`,
|
`/admin/stock-locations/${location1.id}`,
|
||||||
{
|
{
|
||||||
name: "new name",
|
name: "new name",
|
||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
|
|
||||||
expect(response.data.stock_location.name).toEqual("new name")
|
expect(response.data.stock_location.name).toEqual("new name")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Get stock location", () => {
|
describe("Get stock location", () => {
|
||||||
let locationId
|
|
||||||
const location = {
|
|
||||||
name: "Test Location",
|
|
||||||
}
|
|
||||||
beforeEach(async () => {
|
|
||||||
const createLocationRespones = await api.post(
|
|
||||||
"/admin/stock-locations",
|
|
||||||
{
|
|
||||||
...location,
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
locationId = createLocationRespones.data.stock_location.id
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should get a stock location", async () => {
|
it("should get a stock location", async () => {
|
||||||
const response = await api.get(
|
const response = await api.get(
|
||||||
`/admin/stock-locations/${locationId}`,
|
`/admin/stock-locations/${location1.id}`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).toEqual(200)
|
expect(response.status).toEqual(200)
|
||||||
expect(response.data.stock_location).toEqual(
|
expect(response.data.stock_location).toEqual(
|
||||||
expect.objectContaining({ id: locationId, ...location })
|
expect.objectContaining({ id: location1.id, name: "Test Location 1" })
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should get a stock location", async () => {
|
it("should throw an error when a stock location does not exist", async () => {
|
||||||
let error
|
let error
|
||||||
await api
|
await api
|
||||||
.get(`/admin/stock-locations/does-not-exist`, adminHeaders)
|
.get(`/admin/stock-locations/does-not-exist`, adminHeaders)
|
||||||
@@ -222,26 +194,15 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Delete stock location", () => {
|
describe("Delete stock location", () => {
|
||||||
let stockLocationId
|
|
||||||
beforeEach(async () => {
|
|
||||||
const stockLocationCreateResponse = await api.post(
|
|
||||||
`/admin/stock-locations`,
|
|
||||||
{ name: "test location" },
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
stockLocationId = stockLocationCreateResponse.data.stock_location.id
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should successfully delete stock location", async () => {
|
it("should successfully delete stock location", async () => {
|
||||||
const stockLocationDeleteResponse = await api.delete(
|
const stockLocationDeleteResponse = await api.delete(
|
||||||
`/admin/stock-locations/${stockLocationId}`,
|
`/admin/stock-locations/${location1.id}`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(stockLocationDeleteResponse.status).toEqual(200)
|
expect(stockLocationDeleteResponse.status).toEqual(200)
|
||||||
expect(stockLocationDeleteResponse.data).toEqual({
|
expect(stockLocationDeleteResponse.data).toEqual({
|
||||||
id: stockLocationId,
|
id: location1.id,
|
||||||
object: "stock_location",
|
object: "stock_location",
|
||||||
deleted: true,
|
deleted: true,
|
||||||
})
|
})
|
||||||
@@ -252,72 +213,38 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(stockLocations.status).toEqual(200)
|
expect(stockLocations.status).toEqual(200)
|
||||||
expect(stockLocations.data.stock_locations).toEqual([])
|
expect(stockLocations.data.stock_locations).toEqual([
|
||||||
|
expect.objectContaining(location2),
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should successfully delete stock location associations", async () => {
|
it("should successfully delete stock location associations", async () => {
|
||||||
const remoteLink = appContainer.resolve(
|
await api.post(
|
||||||
ContainerRegistrationKeys.REMOTE_LINK
|
`/admin/stock-locations/${location1.id}/sales-channels`,
|
||||||
)
|
|
||||||
|
|
||||||
await remoteLink.create([
|
|
||||||
{
|
{
|
||||||
[Modules.SALES_CHANNEL]: {
|
add: [salesChannel1.id],
|
||||||
sales_channel_id: "default",
|
|
||||||
},
|
|
||||||
[Modules.STOCK_LOCATION]: {
|
|
||||||
stock_location_id: stockLocationId,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
])
|
|
||||||
|
|
||||||
await api.delete(
|
|
||||||
`/admin/stock-locations/${stockLocationId}`,
|
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
const linkService = remoteLink.getLinkModule(
|
await api.delete(`/admin/stock-locations/${location1.id}`, adminHeaders)
|
||||||
Modules.SALES_CHANNEL,
|
|
||||||
"sales_channel_id",
|
|
||||||
Modules.STOCK_LOCATION,
|
|
||||||
"stock_location_id"
|
|
||||||
)
|
|
||||||
|
|
||||||
const stockLocationLinks = await linkService.list()
|
const scWithAssociation = (
|
||||||
expect(stockLocationLinks).toHaveLength(0)
|
await api.get(
|
||||||
|
`/admin/sales-channels/${salesChannel1.id}?fields=*stock_locations`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.sales_channel
|
||||||
|
|
||||||
|
expect(scWithAssociation.stock_locations).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Add sales channels", () => {
|
describe("Add sales channels", () => {
|
||||||
let salesChannel
|
|
||||||
let location
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const salesChannelResponse = await api.post(
|
|
||||||
"/admin/sales-channels",
|
|
||||||
{
|
|
||||||
name: "test name",
|
|
||||||
description: "test description",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
salesChannel = salesChannelResponse.data.sales_channel
|
|
||||||
|
|
||||||
const locationResponse = await api.post(
|
|
||||||
"/admin/stock-locations",
|
|
||||||
{
|
|
||||||
name: "test location",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
location = locationResponse.data.stock_location
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should add sales channels to a location", async () => {
|
it("should add sales channels to a location", async () => {
|
||||||
const salesChannelResponse = await api.post(
|
const salesChannelResponse = await api.post(
|
||||||
`/admin/stock-locations/${location.id}/sales-channels?fields=*sales_channels`,
|
`/admin/stock-locations/${location1.id}/sales-channels?fields=*sales_channels`,
|
||||||
{ add: [salesChannel.id] },
|
{ add: [salesChannel1.id] },
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -328,43 +255,9 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Remove sales channels", () => {
|
describe("Remove sales channels", () => {
|
||||||
let salesChannel1
|
|
||||||
let salesChannel2
|
|
||||||
let location
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const salesChannelResponse1 = await api.post(
|
|
||||||
"/admin/sales-channels",
|
|
||||||
{
|
|
||||||
name: "test name",
|
|
||||||
description: "test description",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
salesChannel1 = salesChannelResponse1.data.sales_channel
|
|
||||||
|
|
||||||
const salesChannelResponse2 = await api.post(
|
|
||||||
"/admin/sales-channels",
|
|
||||||
{
|
|
||||||
name: "test name",
|
|
||||||
description: "test description",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
salesChannel2 = salesChannelResponse2.data.sales_channel
|
|
||||||
|
|
||||||
const locationResponse = await api.post(
|
|
||||||
"/admin/stock-locations",
|
|
||||||
{
|
|
||||||
name: "test location",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
location = locationResponse.data.stock_location
|
|
||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/stock-locations/${location.id}/sales-channels?fields=*sales_channels`,
|
`/admin/stock-locations/${location1.id}/sales-channels?fields=*sales_channels`,
|
||||||
{ add: [salesChannel1.id, salesChannel2.id] },
|
{ add: [salesChannel1.id, salesChannel2.id] },
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -372,7 +265,7 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
it("should remove sales channels from a location", async () => {
|
it("should remove sales channels from a location", async () => {
|
||||||
const salesChannelResponse = await api.post(
|
const salesChannelResponse = await api.post(
|
||||||
`/admin/stock-locations/${location.id}/sales-channels?fields=*sales_channels`,
|
`/admin/stock-locations/${location1.id}/sales-channels?fields=*sales_channels`,
|
||||||
{ remove: [salesChannel1.id] },
|
{ remove: [salesChannel1.id] },
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
@@ -384,23 +277,9 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("Location fulfillment sets", () => {
|
describe("Location fulfillment sets", () => {
|
||||||
let stockLocationId
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const createResponse = await api.post(
|
|
||||||
`/admin/stock-locations`,
|
|
||||||
{
|
|
||||||
name: "test location",
|
|
||||||
},
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
stockLocationId = createResponse.data.stock_location.id
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should create a fulfillment set for the location and then delete it and its associations", async () => {
|
it("should create a fulfillment set for the location and then delete it and its associations", async () => {
|
||||||
const response = await api.post(
|
const response = await api.post(
|
||||||
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
`/admin/stock-locations/${location1.id}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
||||||
{
|
{
|
||||||
name: "Fulfillment Set",
|
name: "Fulfillment Set",
|
||||||
type: "shipping",
|
type: "shipping",
|
||||||
@@ -416,17 +295,13 @@ medusaIntegrationTestRunner({
|
|||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
await api.delete(
|
await api.delete(`/admin/stock-locations/${location1.id}`, adminHeaders)
|
||||||
`/admin/stock-locations/${stockLocationId}`,
|
|
||||||
adminHeaders
|
|
||||||
)
|
|
||||||
|
|
||||||
const fulfillmentModule = appContainer.resolve(
|
// TODO: Ideally we use HTTP here, maybe we should have a get endpoint for fulfillment sets?
|
||||||
|
const fulfillmentModule = getContainer().resolve(
|
||||||
ModuleRegistrationName.FULFILLMENT
|
ModuleRegistrationName.FULFILLMENT
|
||||||
)
|
)
|
||||||
|
|
||||||
const sets = await fulfillmentModule.list()
|
const sets = await fulfillmentModule.list()
|
||||||
|
|
||||||
expect(sets).toHaveLength(0)
|
expect(sets).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -434,7 +309,7 @@ medusaIntegrationTestRunner({
|
|||||||
it("should throw a validation error on wrong input", async () => {
|
it("should throw a validation error on wrong input", async () => {
|
||||||
const errorResponse = await api
|
const errorResponse = await api
|
||||||
.post(
|
.post(
|
||||||
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
`/admin/stock-locations/${location1.id}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
||||||
{
|
{
|
||||||
name: "Fulfillment Set",
|
name: "Fulfillment Set",
|
||||||
type: "shipping",
|
type: "shipping",
|
||||||
@@ -446,7 +321,9 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
expect(errorResponse.status).toEqual(400)
|
expect(errorResponse.status).toEqual(400)
|
||||||
|
|
||||||
expect(errorResponse.data.message).toContain("Invalid request body: ")
|
expect(errorResponse.data.message).toEqual(
|
||||||
|
"Invalid request: Unrecognized fields: 'foo'"
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Reference in New Issue
Block a user