Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Feb 19, 2024
1 parent 54db034 commit cd6ef57
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 62 deletions.
6 changes: 3 additions & 3 deletions packages/customer/integration-tests/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper({
pathToMigrations,
})

export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig(
export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig({
mikroOrmEntities,
pathToMigrations
)
pathToMigrations,
})

export const DB_URL = TestDatabaseUtils.getDatabaseURL()
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import { GeoZoneType } from "@medusajs/utils"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"

jest.setTimeout(100000)

moduleIntegrationTestRunner({
moduleName: Modules.FULFILLMENT,
testSuite: ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,13 +818,7 @@
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "'default'",
"enumItems": [
"default",
"gift_card",
"custom"
],
"mappedType": "enum"
"mappedType": "text"
},
"metadata": {
"name": "metadata",
Expand Down Expand Up @@ -965,15 +959,6 @@
"nullable": true,
"mappedType": "text"
},
"shipping_option_type_id": {
"name": "shipping_option_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"data": {
"name": "data",
"type": "jsonb",
Expand All @@ -992,6 +977,15 @@
"nullable": true,
"mappedType": "json"
},
"shipping_option_type_id": {
"name": "shipping_option_type_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"mappedType": "text"
},
"created_at": {
"name": "created_at",
"type": "timestamptz",
Expand Down Expand Up @@ -1037,16 +1031,6 @@
"primary": false,
"unique": true
},
{
"keyName": "IDX_shipping_option_name_unique",
"columnNames": [
"name"
],
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_shipping_option_name_unique\" ON \"shipping_option\" (name) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_shipping_option_service_zone_id",
"columnNames": [
Expand Down Expand Up @@ -1766,7 +1750,7 @@
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_line_item_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_fulfillment_item_inventory_item_id",
Expand All @@ -1776,7 +1760,7 @@
"composite": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL"
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_inventory_item_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_fulfillment_item_fulfillment_id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240215122031 extends Migration {
export class Migration20240219115644 extends Migration {

async up(): Promise<void> {
this.addSql('create table if not exists "fulfillment_address" ("id" text not null, "fulfillment_id" text null, "company" text null, "first_name" text null, "last_name" text null, "address_1" text null, "address_2" text null, "city" text null, "country_code" text null, "province" text null, "postal_code" text null, "phone" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_address_pkey" primary key ("id"));');
Expand Down Expand Up @@ -30,13 +30,12 @@ export class Migration20240215122031 extends Migration {
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_type_shipping_option_id" ON "shipping_option_type" (shipping_option_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_type_deleted_at" ON "shipping_option_type" (deleted_at) WHERE deleted_at IS NOT NULL;');

this.addSql('create table if not exists "shipping_profile" ("id" text not null, "name" text not null, "type" text check ("type" in (\'default\', \'gift_card\', \'custom\')) not null default \'default\', "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_profile_pkey" primary key ("id"));');
this.addSql('create table if not exists "shipping_profile" ("id" text not null, "name" text not null, "type" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_profile_pkey" primary key ("id"));');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_shipping_profile_name_unique" ON "shipping_profile" (name) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_profile_deleted_at" ON "shipping_profile" (deleted_at) WHERE deleted_at IS NOT NULL;');

this.addSql('create table if not exists "shipping_option" ("id" text not null, "name" text not null, "price_type" text check ("price_type" in (\'calculated\', \'flat\')) not null default \'calculated\', "service_zone_id" text not null, "shipping_profile_id" text null, "service_provider_id" text null, "shipping_option_type_id" text null, "data" jsonb null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_pkey" primary key ("id"));');
this.addSql('create table if not exists "shipping_option" ("id" text not null, "name" text not null, "price_type" text check ("price_type" in (\'calculated\', \'flat\')) not null default \'calculated\', "service_zone_id" text not null, "shipping_profile_id" text null, "service_provider_id" text null, "data" jsonb null, "metadata" jsonb null, "shipping_option_type_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_pkey" primary key ("id"));');
this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_shipping_option_type_id_unique" unique ("shipping_option_type_id");');
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_shipping_option_name_unique" ON "shipping_option" (name) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_service_zone_id" ON "shipping_option" (service_zone_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_shipping_profile_id" ON "shipping_option" (shipping_profile_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_service_provider_id" ON "shipping_option" (service_provider_id) WHERE deleted_at IS NULL;');
Expand All @@ -58,8 +57,8 @@ export class Migration20240215122031 extends Migration {
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_label_deleted_at" ON "fulfillment_label" (deleted_at) WHERE deleted_at IS NOT NULL;');

this.addSql('create table if not exists "fulfillment_item" ("id" text not null, "title" text not null, "sku" text not null, "barcode" text not null, "quantity" numeric not null, "line_item_id" text null, "inventory_item_id" text null, "fulfillment_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_item_pkey" primary key ("id"));');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (line_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (inventory_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_line_item_id" ON "fulfillment_item" (line_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_inventory_item_id" ON "fulfillment_item" (inventory_item_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (fulfillment_id) WHERE deleted_at IS NULL;');
this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_deleted_at" ON "fulfillment_item" (deleted_at) WHERE deleted_at IS NOT NULL;');

Expand Down
24 changes: 18 additions & 6 deletions packages/fulfillment/src/models/shipping-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,29 @@ export default class ShippingOption {
})
price_type: ShippingOptionPriceType

@Property({ columnType: "text" })
@ManyToOne(() => ShippingProfile, {
type: "text",
fieldName: "service_zone_id",
mapToPk: true,
})
@ServiceZoneIdIndex.MikroORMIndex()
service_zone_id: string

@Property({ columnType: "text", nullable: true })
@ManyToOne(() => ShippingProfile, {
type: "text",
fieldName: "shipping_profile_id",
mapToPk: true,
nullable: true,
})
@ShippingProfileIdIndex.MikroORMIndex()
shipping_profile_id: string | null

@Property({ columnType: "text", nullable: true })
@ManyToOne(() => ServiceProvider, {
type: "text",
fieldName: "service_provider_id",
mapToPk: true,
nullable: true,
})
@ServiceProviderIdIndex.MikroORMIndex()
service_provider_id: string

Expand All @@ -104,15 +118,13 @@ export default class ShippingOption {

@ManyToOne(() => ShippingProfile, {
persist: false,
nullable: true,
})
shipping_profile: ShippingProfile | null

@ManyToOne(() => ServiceProvider, {
persist: false,
nullable: true,
})
service_provider: ServiceProvider
service_provider: ServiceProvider | null

@OneToOne(() => ShippingOptionType, (so) => so.shipping_option, {
owner: true,
Expand Down
3 changes: 0 additions & 3 deletions packages/medusa-test-utils/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql"
import * as process from "process"
import { Migrator } from "@mikro-orm/migrations"

export function getDatabaseURL(dbName?: string): string {
const DB_HOST = process.env.DB_HOST ?? "localhost"
Expand Down Expand Up @@ -32,7 +30,6 @@ export function getMikroOrmConfig({
entities: Object.values(mikroOrmEntities),
schema: schema ?? process.env.MEDUSA_DB_SCHEMA,
debug: false,
extensions: [Migrator],
migrations: {
pathTs: pathToMigrations,
silent: true,
Expand Down
5 changes: 1 addition & 4 deletions packages/medusa-test-utils/src/module-test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ export function moduleIntegrationTestRunner({
moduleModels,
joinerConfig = [],
schema = "public",
migrationPath,
testSuite,
}: {
moduleName: string
moduleModels?: any[]
joinerConfig?: any[]
migrationPath?: string
schema?: string
dbName?: string
testSuite: <TService = unknown>(options: SuiteOptions<TService>) => () => void
}) {
moduleModels = Object.values(require(`${process.cwd()}/src/models`))
migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"
// migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"

const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
const dbName = `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
Expand All @@ -45,7 +43,6 @@ export function moduleIntegrationTestRunner({

const MikroOrmWrapper = getMikroOrmWrapper({
mikroOrmEntities: moduleModels,
pathToMigrations: migrationPath,
clientUrl: dbConfig.clientUrl,
schema: dbConfig.schema,
})
Expand Down
16 changes: 4 additions & 12 deletions packages/types/src/fulfillment/mutations/shipping-option.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
CreateShippingOptionTypeDTO,
UpdateShippingOptionTypeDTO,
} from "./shipping-option-type"
import { CreateShippingOptionTypeDTO } from "./shipping-option-type"
import { ShippingOptionPriceType } from "../common"
import {
CreateShippingOptionRuleDTO,
UpdateShippingOptionRuleDTO,
} from "./shipping-option-rule"
import { CreateShippingOptionRuleDTO } from "./shipping-option-rule"

export interface CreateShippingOptionDTO {
name: string
Expand All @@ -26,12 +20,10 @@ export interface UpdateShippingOptionDTO {
service_zone_id?: string
shipping_profile_id?: string
service_provider_id?: string
type:
| Omit<CreateShippingOptionTypeDTO, "shipping_option_id">
| Omit<UpdateShippingOptionTypeDTO, "shipping_option_id">
type: Omit<CreateShippingOptionTypeDTO, "shipping_option_id"> | { id: string }
data?: Record<string, unknown> | null
rules?: (
| Omit<CreateShippingOptionRuleDTO, "shipping_option_id">
| Omit<UpdateShippingOptionRuleDTO, "shipping_option_id">
| { id: string }
)[]
}

0 comments on commit cd6ef57

Please sign in to comment.