feat: add hasMany flag to enforce in app link uniqueness (#12039)
* feat: add createMultiple flag to enforce inApp link uniqueness * changes * mocks * default * many to many --------- Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com>
This commit is contained in:
@@ -46,7 +46,7 @@ medusaIntegrationTestRunner({
|
||||
entity: "Currency",
|
||||
primaryKey: "code",
|
||||
foreignKey: "currency_code",
|
||||
isList: true,
|
||||
hasMany: false,
|
||||
alias: "currency",
|
||||
args: {
|
||||
methodSuffix: "Currencies",
|
||||
@@ -59,7 +59,7 @@ medusaIntegrationTestRunner({
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
alias: "region",
|
||||
isList: false,
|
||||
hasMany: false,
|
||||
args: {
|
||||
methodSuffix: "Regions",
|
||||
},
|
||||
@@ -90,9 +90,9 @@ medusaIntegrationTestRunner({
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
fieldAlias: {
|
||||
currencies: {
|
||||
currency: {
|
||||
path: "currency_link.currency",
|
||||
isList: true,
|
||||
isList: false,
|
||||
forwardArgumentsOnPath: ["currency_link.currency"],
|
||||
},
|
||||
},
|
||||
@@ -102,7 +102,7 @@ medusaIntegrationTestRunner({
|
||||
primaryKey: "region_id",
|
||||
foreignKey: "id",
|
||||
alias: "currency_link",
|
||||
isList: true,
|
||||
isList: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -147,7 +147,7 @@ medusaIntegrationTestRunner({
|
||||
entity: "ProductVariant",
|
||||
primaryKey: "id",
|
||||
foreignKey: "product_variant_id",
|
||||
isList: true,
|
||||
hasMany: false,
|
||||
alias: "product_variant",
|
||||
args: {
|
||||
methodSuffix: "ProductVariants",
|
||||
@@ -159,7 +159,7 @@ medusaIntegrationTestRunner({
|
||||
entity: "Region",
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
isList: false,
|
||||
hasMany: false,
|
||||
alias: "region",
|
||||
args: {
|
||||
methodSuffix: "Regions",
|
||||
@@ -191,9 +191,9 @@ medusaIntegrationTestRunner({
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
fieldAlias: {
|
||||
product_variants: {
|
||||
product_variant: {
|
||||
path: "product_variant_link.product_variant",
|
||||
isList: true,
|
||||
isList: false,
|
||||
forwardArgumentsOnPath: [
|
||||
"product_variant_link.product_variant",
|
||||
],
|
||||
@@ -205,7 +205,7 @@ medusaIntegrationTestRunner({
|
||||
primaryKey: "region_id",
|
||||
foreignKey: "id",
|
||||
alias: "product_variant_link",
|
||||
isList: true,
|
||||
isList: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -253,7 +253,7 @@ medusaIntegrationTestRunner({
|
||||
entity: "Currency",
|
||||
primaryKey: "code",
|
||||
foreignKey: "currency_code",
|
||||
isList: true,
|
||||
hasMany: false,
|
||||
alias: "currency",
|
||||
args: {
|
||||
methodSuffix: "Currencies",
|
||||
@@ -265,7 +265,7 @@ medusaIntegrationTestRunner({
|
||||
entity: "Region",
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
isList: false,
|
||||
hasMany: false,
|
||||
alias: "region",
|
||||
args: {
|
||||
methodSuffix: "Regions",
|
||||
@@ -297,9 +297,9 @@ medusaIntegrationTestRunner({
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
fieldAlias: {
|
||||
currencies: {
|
||||
currency: {
|
||||
path: "currency_link.currency",
|
||||
isList: true,
|
||||
isList: false,
|
||||
forwardArgumentsOnPath: ["currency_link.currency"],
|
||||
},
|
||||
},
|
||||
@@ -309,7 +309,7 @@ medusaIntegrationTestRunner({
|
||||
primaryKey: "region_id",
|
||||
foreignKey: "id",
|
||||
alias: "currency_link",
|
||||
isList: true,
|
||||
isList: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -353,7 +353,7 @@ medusaIntegrationTestRunner({
|
||||
entity: "Currency",
|
||||
primaryKey: "code",
|
||||
foreignKey: "currency_code",
|
||||
isList: true,
|
||||
hasMany: false,
|
||||
alias: "currency",
|
||||
args: {
|
||||
methodSuffix: "Currencies",
|
||||
@@ -365,7 +365,113 @@ medusaIntegrationTestRunner({
|
||||
entity: "Region",
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
isList: true,
|
||||
hasMany: true,
|
||||
alias: "region",
|
||||
args: {
|
||||
methodSuffix: "Regions",
|
||||
},
|
||||
deleteCascade: false,
|
||||
},
|
||||
],
|
||||
extends: [
|
||||
{
|
||||
serviceName: "currency",
|
||||
entity: "Currency",
|
||||
fieldAlias: {
|
||||
regions: {
|
||||
path: "region_link.region",
|
||||
isList: true,
|
||||
forwardArgumentsOnPath: ["region_link.region"],
|
||||
},
|
||||
},
|
||||
relationship: {
|
||||
serviceName: "CurrencyCurrencyRegionRegionLink",
|
||||
entity: "LinkCurrencyCurrencyRegionRegion",
|
||||
primaryKey: "currency_code",
|
||||
foreignKey: "code",
|
||||
alias: "region_link",
|
||||
isList: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
fieldAlias: {
|
||||
currency: {
|
||||
path: "currency_link.currency",
|
||||
isList: false,
|
||||
forwardArgumentsOnPath: ["currency_link.currency"],
|
||||
},
|
||||
},
|
||||
relationship: {
|
||||
serviceName: "CurrencyCurrencyRegionRegionLink",
|
||||
entity: "LinkCurrencyCurrencyRegionRegion",
|
||||
primaryKey: "region_id",
|
||||
foreignKey: "id",
|
||||
alias: "currency_link",
|
||||
isList: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("should generate a proper link with both sides using explicit isList=true", async () => {
|
||||
const currencyLinks = CurrencyModule.linkable
|
||||
const regionLinks = RegionModule.linkable
|
||||
|
||||
const link = defineLink(
|
||||
{
|
||||
linkable: currencyLinks.currency,
|
||||
isList: true,
|
||||
},
|
||||
{
|
||||
linkable: regionLinks.region,
|
||||
isList: true,
|
||||
}
|
||||
)
|
||||
|
||||
const linkDefinition = MedusaModule.getCustomLinks()
|
||||
.map((linkDefinition: any) => {
|
||||
const definition = linkDefinition(
|
||||
MedusaModule.getAllJoinerConfigs()
|
||||
)
|
||||
return definition.serviceName === link.serviceName && definition
|
||||
})
|
||||
.filter(Boolean)[0]
|
||||
|
||||
expect(link.serviceName).toEqual("CurrencyCurrencyRegionRegionLink")
|
||||
expect(linkDefinition).toEqual({
|
||||
serviceName: "CurrencyCurrencyRegionRegionLink",
|
||||
isLink: true,
|
||||
alias: [
|
||||
{
|
||||
name: ["currency_region"],
|
||||
args: {
|
||||
entity: "LinkCurrencyCurrencyRegionRegion",
|
||||
},
|
||||
},
|
||||
],
|
||||
primaryKeys: ["id", "currency_code", "region_id"],
|
||||
relationships: [
|
||||
{
|
||||
serviceName: "currency",
|
||||
entity: "Currency",
|
||||
primaryKey: "code",
|
||||
foreignKey: "currency_code",
|
||||
hasMany: true,
|
||||
alias: "currency",
|
||||
args: {
|
||||
methodSuffix: "Currencies",
|
||||
},
|
||||
deleteCascade: false,
|
||||
},
|
||||
{
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
hasMany: true,
|
||||
alias: "region",
|
||||
args: {
|
||||
methodSuffix: "Regions",
|
||||
@@ -415,6 +521,112 @@ medusaIntegrationTestRunner({
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("should generate a proper link with both sides using explicit isList=false", async () => {
|
||||
const currencyLinks = CurrencyModule.linkable
|
||||
const regionLinks = RegionModule.linkable
|
||||
|
||||
const link = defineLink(
|
||||
{
|
||||
linkable: currencyLinks.currency,
|
||||
isList: false,
|
||||
},
|
||||
{
|
||||
linkable: regionLinks.region,
|
||||
isList: false,
|
||||
}
|
||||
)
|
||||
|
||||
const linkDefinition = MedusaModule.getCustomLinks()
|
||||
.map((linkDefinition: any) => {
|
||||
const definition = linkDefinition(
|
||||
MedusaModule.getAllJoinerConfigs()
|
||||
)
|
||||
return definition.serviceName === link.serviceName && definition
|
||||
})
|
||||
.filter(Boolean)[0]
|
||||
|
||||
expect(link.serviceName).toEqual("CurrencyCurrencyRegionRegionLink")
|
||||
expect(linkDefinition).toEqual({
|
||||
serviceName: "CurrencyCurrencyRegionRegionLink",
|
||||
isLink: true,
|
||||
alias: [
|
||||
{
|
||||
name: ["currency_region"],
|
||||
args: {
|
||||
entity: "LinkCurrencyCurrencyRegionRegion",
|
||||
},
|
||||
},
|
||||
],
|
||||
primaryKeys: ["id", "currency_code", "region_id"],
|
||||
relationships: [
|
||||
{
|
||||
serviceName: "currency",
|
||||
entity: "Currency",
|
||||
primaryKey: "code",
|
||||
foreignKey: "currency_code",
|
||||
hasMany: false,
|
||||
alias: "currency",
|
||||
args: {
|
||||
methodSuffix: "Currencies",
|
||||
},
|
||||
deleteCascade: false,
|
||||
},
|
||||
{
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
primaryKey: "id",
|
||||
foreignKey: "region_id",
|
||||
hasMany: false,
|
||||
alias: "region",
|
||||
args: {
|
||||
methodSuffix: "Regions",
|
||||
},
|
||||
deleteCascade: false,
|
||||
},
|
||||
],
|
||||
extends: [
|
||||
{
|
||||
serviceName: "currency",
|
||||
entity: "Currency",
|
||||
fieldAlias: {
|
||||
region: {
|
||||
path: "region_link.region",
|
||||
isList: false,
|
||||
forwardArgumentsOnPath: ["region_link.region"],
|
||||
},
|
||||
},
|
||||
relationship: {
|
||||
serviceName: "CurrencyCurrencyRegionRegionLink",
|
||||
entity: "LinkCurrencyCurrencyRegionRegion",
|
||||
primaryKey: "currency_code",
|
||||
foreignKey: "code",
|
||||
alias: "region_link",
|
||||
isList: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
serviceName: "region",
|
||||
entity: "Region",
|
||||
fieldAlias: {
|
||||
currency: {
|
||||
path: "currency_link.currency",
|
||||
isList: false,
|
||||
forwardArgumentsOnPath: ["currency_link.currency"],
|
||||
},
|
||||
},
|
||||
relationship: {
|
||||
serviceName: "CurrencyCurrencyRegionRegionLink",
|
||||
entity: "LinkCurrencyCurrencyRegionRegion",
|
||||
primaryKey: "region_id",
|
||||
foreignKey: "id",
|
||||
alias: "currency_link",
|
||||
isList: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user