Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fulfillment): Module service implementation first iteration #6381

Merged
merged 39 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a22d873
feat(fulfillment): Module sevice implemntation first iteration
adrien2p Feb 12, 2024
1299453
cleanup
adrien2p Feb 12, 2024
a2ba452
Create geo zones as part of the service zones creation during fulfill…
adrien2p Feb 12, 2024
e42052b
cleanup
adrien2p Feb 12, 2024
baf85d8
wrap in a separate describe
adrien2p Feb 12, 2024
1fa628c
rm todo
adrien2p Feb 12, 2024
dc2d2b5
trully run db migrations
adrien2p Feb 12, 2024
f52f6a8
fixes
adrien2p Feb 12, 2024
6050c0f
fixes
adrien2p Feb 12, 2024
00c8ca6
fixes
adrien2p Feb 12, 2024
b89cfe8
continue creation flow
adrien2p Feb 13, 2024
9bf0c82
cleanup
adrien2p Feb 13, 2024
46111d4
resolve conflicts
adrien2p Feb 13, 2024
af47507
Add support to create service zones with geo zones
adrien2p Feb 13, 2024
7323cd2
Update fulfillment sets
adrien2p Feb 13, 2024
e1ba6cf
cleanup
adrien2p Feb 13, 2024
5a1f051
fix integration
adrien2p Feb 13, 2024
3e778b4
Merge branch 'develop' into feat/fulfillment-implementation-1
adrien2p Feb 13, 2024
6beae8b
update service zones
adrien2p Feb 13, 2024
811cb72
add geo zones management
adrien2p Feb 13, 2024
9e563d8
cleanup
adrien2p Feb 13, 2024
7720ba5
add read tests
adrien2p Feb 13, 2024
7053900
tackle all type issues or missing in the integration tesst
adrien2p Feb 13, 2024
d350afe
Merge branch 'develop' into feat/fulfillment-implementation-1
adrien2p Feb 13, 2024
614ce9d
Merge branch 'develop' into feat/fulfillment-implementation-1
adrien2p Feb 13, 2024
f69b91b
add more tests
adrien2p Feb 13, 2024
d2d9813
Merge branch 'feat/fulfillment-implementation-1' of github.com:medusa…
adrien2p Feb 13, 2024
9970652
Create nine-nails-end.md
adrien2p Feb 13, 2024
0e7f690
Add fix ordered on many to many + add pivot table orphan data check
adrien2p Feb 13, 2024
09cf3be
Merge branch 'feat/fulfillment-implementation-1' of github.com:medusa…
adrien2p Feb 13, 2024
7174f73
fix unique indexes
adrien2p Feb 13, 2024
f1f3c50
Update relationship and create* methods
adrien2p Feb 14, 2024
479185c
finalise rework
adrien2p Feb 14, 2024
51e644f
Merge branch 'develop' into feat/fulfillment-implementation-1
adrien2p Feb 14, 2024
aea52f5
cleanup
adrien2p Feb 14, 2024
e55b72b
Merge branch 'feat/fulfillment-implementation-1' of github.com:medusa…
adrien2p Feb 14, 2024
eb775f2
move get set diff
adrien2p Feb 14, 2024
8e53af4
Merge branch 'develop' into feat/fulfillment-implementation-1
adrien2p Feb 14, 2024
0d8a946
Merge branch 'develop' into feat/fulfillment-implementation-1
adrien2p Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Migration20240124154000 extends Migration {
'create index if not exists "IDX_customer_address_customer_id" on "customer_address" ("customer_id");'
)
this.addSql(
'create unique index "IDX_customer_address_unqiue_customer_billing" on "customer_address" ("customer_id") where "is_default_billing" = true;'
'create unique index "IDX_customer_address_unique_customer_billing" on "customer_address" ("customer_id") where "is_default_billing" = true;'
adrien2p marked this conversation as resolved.
Show resolved Hide resolved
)
this.addSql(
'create unique index "IDX_customer_address_unique_customer_shipping" on "customer_address" ("customer_id") where "is_default_shipping" = true;'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
import { Modules } from "@medusajs/modules-sdk"
import { initModules } from "medusa-test-utils/dist"
import {
CreateFulfillmentSetDTO,
IFulfillmentModuleService,
} from "@medusajs/types"
import { getInitModuleConfig, MikroOrmWrapper } from "../utils"
import { GeoZoneType } from "@medusajs/utils"

describe("fulfillment module service", function () {
let service: IFulfillmentModuleService
let shutdownFunc: () => Promise<void>

beforeAll(async () => {
const initModulesConfig = getInitModuleConfig()

const { medusaApp, shutdown } = await initModules(initModulesConfig)

service = medusaApp.modules[Modules.FULFILLMENT]

shutdownFunc = shutdown
})

beforeEach(async () => {
await MikroOrmWrapper.setupDatabase()
})

afterEach(async () => {
await MikroOrmWrapper.clearDatabase()
})

afterAll(async () => {
await shutdownFunc()
})

describe("on create", () => {
it("should create a new fulfillment set", async function () {
const data: CreateFulfillmentSetDTO = {
name: "test",
type: "test-type",
}

const fulfillmentSets = await service.create(data)

expect(fulfillmentSets).toHaveLength(1)
expect(fulfillmentSets[0]).toEqual(
expect.objectContaining({
id: expect.any(String),
name: data.name,
type: data.type,
})
)
})

it("should create a collection of fulfillment sets", async function () {
const data = [
{
name: "test",
type: "test-type",
},
{
name: "test2",
type: "test-type2",
},
]

const fulfillmentSets = await service.create(data)

expect(fulfillmentSets).toHaveLength(2)

let i = 0
for (const data_ of data) {
expect(fulfillmentSets[i]).toEqual(
expect.objectContaining({
id: expect.any(String),
name: data_.name,
type: data_.type,
})
)
++i
}
})

it("should create a new fulfillment set with new service zones", async function () {
const data = {
name: "test",
type: "test-type",
service_zones: [
{
name: "test",
},
],
}

const fulfillmentSets = await service.create(data)

expect(fulfillmentSets).toHaveLength(1)
expect(fulfillmentSets[0]).toEqual(
expect.objectContaining({
id: expect.any(String),
name: data.name,
type: data.type,
service_zones: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: data.service_zones[0].name,
}),
]),
})
)
})

it("should create a collection of fulfillment sets with new service zones", async function () {
const data = [
{
name: "test",
type: "test-type",
service_zones: [
{
name: "test",
},
],
},
{
name: "test2",
type: "test-type2",
service_zones: [
{
name: "test",
},
],
},
{
name: "test3",
type: "test-type3",
service_zones: [
{
name: "test2",
},
],
},
]

const fulfillmentSets = await service.create(data)

expect(fulfillmentSets).toHaveLength(3)

let i = 0
for (const data_ of data) {
expect(fulfillmentSets[i]).toEqual(
expect.objectContaining({
id: expect.any(String),
name: data_.name,
type: data_.type,
service_zones: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: data_.service_zones[0].name,
}),
]),
})
)
++i
}

// The two first fulfillment sets share the same service zone
expect(fulfillmentSets[0].service_zones[0].id).toEqual(
fulfillmentSets[1].service_zones[0].id
)
})

it("should create a new fulfillment set with new service zones and new geo zones", async function () {
const data: CreateFulfillmentSetDTO = {
name: "test",
type: "test-type",
service_zones: [
{
name: "test",
geo_zones: [
{
type: GeoZoneType.COUNTRY,
country_code: "fr",
},
],
},
],
}

const fulfillmentSets = await service.create(data)

expect(fulfillmentSets).toHaveLength(1)
expect(fulfillmentSets[0]).toEqual(
expect.objectContaining({
id: expect.any(String),
name: data.name,
type: data.type,
service_zones: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: (data.service_zones![0] as any).name,
geo_zones: expect.arrayContaining([
expect.objectContaining({
type: (data.service_zones![0] as any).geo_zones[0].type,
country_code: (data.service_zones![0] as any).geo_zones[0]
.country_code,
}),
]),
}),
]),
})
)
})

it("should create a collection of fulfillment sets with new service zones and new geo zones", async function () {
const data: CreateFulfillmentSetDTO[] = [
{
name: "test",
type: "test-type",
service_zones: [
{
name: "test",
geo_zones: [
{
type: GeoZoneType.COUNTRY,
country_code: "fr",
},
],
},
],
},
{
name: "test2",
type: "test-type2",
service_zones: [
{
name: "test",
geo_zones: [
{
type: GeoZoneType.COUNTRY,
country_code: "fr",
},
],
},
],
},
{
name: "test3",
type: "test-type3",
service_zones: [
{
name: "test2",
geo_zones: [
{
type: GeoZoneType.CITY,
country_code: "fr",
city: "lyon",
},
],
},
],
},
]

const fulfillmentSets = await service.create(data)

expect(fulfillmentSets).toHaveLength(3)

let i = 0
for (const data_ of data) {
expect(fulfillmentSets[i]).toEqual(
expect.objectContaining({
id: expect.any(String),
name: data_.name,
type: data_.type,
service_zones: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: (data_.service_zones![0] as any).name,
geo_zones: expect.arrayContaining([
expect.objectContaining({
type: (data_.service_zones![0] as any).geo_zones[0].type,
country_code: (data_.service_zones![0] as any).geo_zones[0]
.country_code,
}),
]),
}),
]),
})
)
++i
}

// The two first fulfillment sets share the same geo zone for their service zones
expect(fulfillmentSets[0].service_zones[0].geo_zones[0].id).toEqual(
fulfillmentSets[1].service_zones[0].geo_zones[0].id
)
})

describe("should fail", () => {
it(`on duplicated fulfillment set name`, async function () {
const data: CreateFulfillmentSetDTO = {
name: "test",
type: "test-type",
}

await service.create(data)
await service.create(data)

const ful = await service.list({})
console.log(JSON.stringify(ful, null, 2))
})
})
})
})
5 changes: 0 additions & 5 deletions packages/fulfillment/integration-tests/__tests__/index.ts

This file was deleted.

9 changes: 2 additions & 7 deletions packages/fulfillment/integration-tests/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import { TestDatabaseUtils } from "medusa-test-utils"

import * as Models from "@models"

const pathToMigrations = "../../src/migrations"
const mikroOrmEntities = Models as unknown as any[]

export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper(
mikroOrmEntities,
pathToMigrations
)

export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig(
mikroOrmEntities,
pathToMigrations
null,
process.env.MEDUSA_FULFILLMENT_DB_SCHEMA
)

export const DB_URL = TestDatabaseUtils.getDatabaseURL()
1 change: 1 addition & 0 deletions packages/fulfillment/integration-tests/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./database"
export * from "./get-init-module-config"
1 change: 1 addition & 0 deletions packages/fulfillment/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
"^@services": "<rootDir>/src/services",
"^@repositories": "<rootDir>/src/repositories",
"^@types": "<rootDir>/src/types",
"^@migrations": "<rootDir>/src/migrations",
},
transform: {
"^.+\\.[jt]s?$": [
Expand Down
Loading
Loading