@@ -1,21 +1,27 @@
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { ILinkModule, ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { defineLink, isObject, Modules } from "@medusajs/utils"
|
||||
import { Modules, defineLink, isObject } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { MigrationsExecutionPlanner } from "../../src"
|
||||
import {
|
||||
Car,
|
||||
carJoinerConfig,
|
||||
CarModule,
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableModule,
|
||||
User,
|
||||
userJoinerConfig,
|
||||
UserModule,
|
||||
carJoinerConfig,
|
||||
longNameJoinerConfig,
|
||||
userJoinerConfig,
|
||||
} from "../__fixtures__/migrations"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
MedusaModule.setJoinerConfig(userJoinerConfig.serviceName, userJoinerConfig)
|
||||
MedusaModule.setJoinerConfig(carJoinerConfig.serviceName, carJoinerConfig)
|
||||
MedusaModule.setJoinerConfig(
|
||||
longNameJoinerConfig.serviceName,
|
||||
longNameJoinerConfig
|
||||
)
|
||||
|
||||
moduleIntegrationTestRunner<ILinkModule>({
|
||||
moduleName: Modules.LINK,
|
||||
@@ -24,6 +30,11 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
describe("MigrationsExecutionPlanner", () => {
|
||||
test("should generate an execution plan", async () => {
|
||||
defineLink(UserModule.linkable.user, CarModule.linkable.car)
|
||||
defineLink(
|
||||
UserModule.linkable.user,
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableModule
|
||||
.linkable.veryLongTableNameOfCustomModule
|
||||
)
|
||||
|
||||
MedusaModule.getCustomLinks().forEach((linkDefinition: any) => {
|
||||
MedusaModule.setCustomLink(
|
||||
@@ -44,9 +55,11 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
})
|
||||
|
||||
let actionPlan = await planner.createPlan()
|
||||
|
||||
await planner.executePlan(actionPlan)
|
||||
|
||||
expect(actionPlan).toHaveLength(1)
|
||||
expect(actionPlan).toHaveLength(2)
|
||||
|
||||
expect(actionPlan[0]).toEqual({
|
||||
action: "create",
|
||||
linkDescriptor: {
|
||||
@@ -55,8 +68,8 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
fromModel: "user",
|
||||
toModel: "car",
|
||||
},
|
||||
tableName: "User_user_Car_car",
|
||||
sql: 'create table "User_user_Car_car" ("user_id" varchar(255) not null, "car_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "updated_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz(0) null, constraint "User_user_Car_car_pkey" primary key ("user_id", "car_id"));\ncreate index "IDX_car_id_-8c9667b4" on "User_user_Car_car" ("car_id");\ncreate index "IDX_id_-8c9667b4" on "User_user_Car_car" ("id");\ncreate index "IDX_user_id_-8c9667b4" on "User_user_Car_car" ("user_id");\ncreate index "IDX_deleted_at_-8c9667b4" on "User_user_Car_car" ("deleted_at");\n\n',
|
||||
tableName: "user_user_car_car",
|
||||
sql: 'create table "user_user_car_car" ("user_id" varchar(255) not null, "car_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "updated_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz(0) null, constraint "user_user_car_car_pkey" primary key ("user_id", "car_id"));\ncreate index "IDX_car_id_-8c9667b4" on "user_user_car_car" ("car_id");\ncreate index "IDX_id_-8c9667b4" on "user_user_car_car" ("id");\ncreate index "IDX_user_id_-8c9667b4" on "user_user_car_car" ("user_id");\ncreate index "IDX_deleted_at_-8c9667b4" on "user_user_car_car" ("deleted_at");\n\n',
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -91,7 +104,7 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
actionPlan = await planner.createPlan()
|
||||
await planner.executePlan(actionPlan)
|
||||
|
||||
expect(actionPlan).toHaveLength(1)
|
||||
expect(actionPlan).toHaveLength(2)
|
||||
expect(actionPlan[0]).toEqual({
|
||||
action: "update",
|
||||
linkDescriptor: {
|
||||
@@ -100,8 +113,8 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
fromModel: "user",
|
||||
toModel: "car",
|
||||
},
|
||||
tableName: "User_user_Car_car",
|
||||
sql: 'alter table "User_user_Car_car" add column "data" jsonb not null;\n\n',
|
||||
tableName: "user_user_car_car",
|
||||
sql: 'alter table "user_user_car_car" add column "data" jsonb not null;\n\n',
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -120,7 +133,7 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
fromModel: "user",
|
||||
toModel: "car",
|
||||
},
|
||||
tableName: "User_user_Car_car",
|
||||
tableName: "user_user_car_car",
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -138,7 +151,7 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
expect(actionPlan).toHaveLength(1)
|
||||
expect(actionPlan[0]).toEqual({
|
||||
action: "delete",
|
||||
tableName: "User_user_Car_car",
|
||||
tableName: "user_user_car_car",
|
||||
linkDescriptor: {
|
||||
toModel: "car",
|
||||
toModule: "Car",
|
||||
|
||||
Reference in New Issue
Block a user