feat(medusa): Allow to assign a Collection to a Product on import (#2764)

This commit is contained in:
Adrien de Peretti
2022-12-12 17:10:03 +01:00
committed by GitHub
parent 33aa3edb80
commit 424efff919
8 changed files with 126 additions and 16 deletions
@@ -8,6 +8,7 @@ const adminSeeder = require("../../../helpers/admin-seeder")
const userSeeder = require("../../../helpers/user-seeder")
const { simpleSalesChannelFactory } = require("../../../factories")
const batchJobSeeder = require("../../../helpers/batch-job-seeder")
const { simpleProductCollectionFactory } = require("../../../factories/simple-product-collection-factory");
const startServerWithEnvironment =
require("../../../../helpers/start-server-with-environment").default
@@ -51,6 +52,8 @@ describe("Product import - Sales Channel", () => {
let dbConnection
let medusaProcess
let collectionHandle1 = "test-collection1"
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
@@ -86,6 +89,9 @@ describe("Product import - Sales Channel", () => {
await simpleSalesChannelFactory(dbConnection, {
name: "Import Sales Channel 2",
})
await simpleProductCollectionFactory(dbConnection, {
handle: collectionHandle1
})
} catch (e) {
console.log(e)
throw e
@@ -162,6 +168,9 @@ describe("Product import - Sales Channel", () => {
is_disabled: false,
}),
],
collection: expect.objectContaining({
handle: collectionHandle1
})
}),
])
})
@@ -9,6 +9,7 @@ const adminSeeder = require("../../../helpers/admin-seeder")
const batchJobSeeder = require("../../../helpers/batch-job-seeder")
const userSeeder = require("../../../helpers/user-seeder")
const { simpleProductFactory } = require("../../../factories")
const { simpleProductCollectionFactory } = require("../../../factories/simple-product-collection-factory");
const adminReqConfig = {
headers: {
@@ -49,6 +50,9 @@ describe("Product import batch job", () => {
let medusaProcess
let dbConnection
let collectionHandle1 = "test-collection1"
let collectionHandle2 = "test-collection2"
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd })
@@ -72,14 +76,14 @@ describe("Product import batch job", () => {
})
beforeEach(async () => {
try {
await batchJobSeeder(dbConnection)
await adminSeeder(dbConnection)
await userSeeder(dbConnection)
} catch (e) {
console.log(e)
throw e
}
await batchJobSeeder(dbConnection)
await adminSeeder(dbConnection)
await userSeeder(dbConnection)
await simpleProductCollectionFactory(dbConnection, [{
handle: collectionHandle1
}, {
handle: collectionHandle2
}])
})
afterEach(async () => {
@@ -220,6 +224,9 @@ describe("Product import batch job", () => {
value: "123_1",
}),
],
collection: expect.objectContaining({
handle: collectionHandle1,
})
}),
expect.objectContaining({
title: "Test product",
@@ -279,6 +286,9 @@ describe("Product import batch job", () => {
}),
],
tags: [],
collection: expect.objectContaining({
handle: collectionHandle1,
})
}),
// UPDATED PRODUCT
expect.objectContaining({
@@ -373,6 +383,9 @@ describe("Product import batch job", () => {
value: "123",
}),
],
collection: expect.objectContaining({
handle: collectionHandle2
})
}),
])
)