fix: integration tests modules 2 (#6599)

Currently, if the v2 flag is not enabled it can lead to issues if the modules are part of the medusa config as they will get loaded anyway leading to issues if the migrations did not ran
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-03-06 13:26:42 +00:00
1 parent f0ef0a8784
commit 0c9018eddc
4 files changed
+51 -10

No files matched your search

@@ -22,7 +22,7 @@ import {
import adminSeeder from "../../../../helpers/admin-seeder"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(50000)
jest.setTimeout(200000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
@@ -1,16 +1,20 @@
import { initialize, runMigrations } from "@medusajs/link-modules"
import { MedusaModule, ModuleJoinerConfig } from "@medusajs/modules-sdk"
import { medusaIntegrationTestRunner } from "medusa-test-utils/dist"
jest.setTimeout(5000000)
const DB_HOST = process.env.DB_HOST
const DB_USERNAME = process.env.DB_USERNAME
const DB_PASSWORD = process.env.DB_PASSWORD
const DB_NAME = process.env.DB_TEMP_NAME
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
describe("Link Modules", () => {
medusaIntegrationTestRunner({
force_modules_migration: true,
testSuite: ({ dbConnection, getContainer }) => {
let DB_URL
let container
let links
beforeAll(async () => {
DB_URL = dbConnection.manager.connection.options.url
container = getContainer()
const linkDefinition: ModuleJoinerConfig[] = [
{
serviceName: "linkServiceName",
@@ -51,7 +55,6 @@ describe("Link Modules", () => {
},
}
beforeAll(async () => {
jest.spyOn(MedusaModule, "getLoadedModules").mockImplementation((() => {
return [{ moduleA: [{}] }, { moduleB: [{}] }]
}) as any)
@@ -64,6 +67,7 @@ describe("Link Modules", () => {
jest.clearAllMocks()
})
describe("Link Modules", () => {
it("Should insert values in a declared link", async function () {
// simple
await links.linkServiceName.create("modA_id", "modB_id")
@@ -128,6 +132,23 @@ describe("Link Modules", () => {
})
it("Should dismiss the link of a given pair of keys", async function () {
// simple
await links.linkServiceName.create("modA_id", "modB_id")
// extra fields
await links.linkServiceName.create("123", "abc", {
extra_field: 333,
another_field: "value**",
})
// bulk
await links.linkServiceName.create([
["111", "aaa", { another_field: "test" }],
["222", "bbb"],
["333", "ccc", { extra_field: 2 }],
["444", "bbb"],
])
// simple
const dismissSingle = await links.linkServiceName.dismiss(
"modA_id",
@@ -163,6 +184,23 @@ describe("Link Modules", () => {
})
it("Should delete all the links related to a given key", async function () {
// simple
await links.linkServiceName.create("modA_id", "modB_id")
// extra fields
await links.linkServiceName.create("123", "abc", {
extra_field: 333,
another_field: "value**",
})
// bulk
await links.linkServiceName.create([
["111", "aaa", { another_field: "test" }],
["222", "bbb"],
["333", "ccc", { extra_field: 2 }],
["444", "bbb"],
])
await links.linkServiceName.softDelete({
inventory_item_id: "bbb",
})
@@ -185,4 +223,6 @@ describe("Link Modules", () => {
}),
])
})
})
},
})
@@ -3,6 +3,7 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
jest.setTimeout(30000)
medusaIntegrationTestRunner({
force_modules_migration: true,
testSuite: ({ dbConnection }) => {
describe("Standalone Modules", () => {
beforeAll(async () => {
+1 -1
View File
@@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --ci --silent=true --concurrency=50% --detectOpenHandles --logHeapUsage --forceExit",
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --ci --silent=true -i --detectOpenHandles --logHeapUsage --forceExit",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {