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: add opf sub-libs to schematics #19387

Merged
merged 10 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -19,7 +19,7 @@ describe('OpfEndpointsService', () => {
beforeEach(() => {
opfConfigMock = {
opf: {
baseUrl: 'https://elec-spa.com/opf',
opfBaseUrl: 'https://elec-spa.com/opf',
},
};
opfApiConfigMock = {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('OpfEndpointsService', () => {
});

it('should return an empty string when baseUrl is empty', () => {
service['opfConfig'] = { opf: { baseUrl: '' } };
service['opfConfig'] = { opf: { opfBaseUrl: '' } };
const result = service['getBaseEndpoint']();
expect(result).toEqual('');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export class OpfEndpointsService {
}

private getBaseEndpoint(): string {
if (this.opfConfig && this.opfConfig.opf && this.opfConfig.opf.baseUrl) {
return this.opfConfig.opf.baseUrl;
if (this.opfConfig && this.opfConfig.opf && this.opfConfig.opf.opfBaseUrl) {
return this.opfConfig.opf.opfBaseUrl;
}

return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { OpfConfig } from './opf-config';

export const defaultOpfConfig: OpfConfig = {
opf: {
baseUrl: '',
opfBaseUrl: '',
},
};
2 changes: 1 addition & 1 deletion integration-libs/opf/base/root/config/opf-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Config } from '@spartacus/core';
})
export abstract class OpfConfig {
opf?: {
baseUrl?: string;
opfBaseUrl?: string;
commerceCloudPublicKey?: string;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,45 @@

exports[`Spartacus SAP OPF integration schematics: ng-add SAP OPF feature general setup should add the feature using the lazy loading syntax 1`] = `
"import { NgModule } from '@angular/core';
import { CmsConfig, I18nConfig, provideConfig } from "@spartacus/core";
import { opfBaseTranslationChunksConfig, opfBaseTranslations } from "@spartacus/opf/base/assets";
import { OPF_BASE_FEATURE, OpfBaseRootModule, OpfConfig } from "@spartacus/opf/base/root";
import { CmsConfig, provideConfig } from "@spartacus/core";
import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyRootModule } from "@spartacus/opf/quick-buy/root";

@NgModule({
declarations: [],
imports: [
OpfBaseRootModule
OpfQuickBuyRootModule
],
providers: [provideConfig(<CmsConfig>{
featureModules: {
[OPF_BASE_FEATURE]: {
[OPF_QUICK_BUY_FEATURE]: {
module: () =>
import('@spartacus/opf/base').then((m) => m.OpfBaseModule),
import('@spartacus/opf/quick-buy').then((m) => m.OpfQuickBuyModule),
},
}
}),
provideConfig(<I18nConfig>{
i18n: {
resources: opfBaseTranslations,
chunks: opfBaseTranslationChunksConfig,
},
}),
provideConfig(<OpfConfig>{
opf: {
baseUrl: "PLACEHOLDER_OPF_BASE_URL",
commerceCloudPublicKey: "PLACEHOLDER_COMMERCE_CLOUD_PUBLIC_KEY",
},
})
]
})]
})
export class OpfFeatureModule { }
"
`;

exports[`Spartacus SAP OPF integration schematics: ng-add SAP OPF feature general setup should add the feature using the lazy loading syntax 2`] = `
"import { NgModule } from '@angular/core';
import { CmsConfig, I18nConfig, provideConfig } from "@spartacus/core";
import { opfBaseTranslationChunksConfig, opfBaseTranslations } from "@spartacus/opf/base/assets";
import { OPF_BASE_FEATURE, OpfBaseRootModule, OpfConfig } from "@spartacus/opf/base/root";
import { CmsConfig, provideConfig } from "@spartacus/core";
import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyRootModule } from "@spartacus/opf/quick-buy/root";

@NgModule({
declarations: [],
imports: [
OpfBaseRootModule
OpfQuickBuyRootModule
],
providers: [provideConfig(<CmsConfig>{
featureModules: {
[OPF_BASE_FEATURE]: {
[OPF_QUICK_BUY_FEATURE]: {
module: () =>
import('@spartacus/opf/base').then((m) => m.OpfBaseModule),
import('@spartacus/opf/quick-buy').then((m) => m.OpfQuickBuyModule),
},
}
}),
provideConfig(<I18nConfig>{
i18n: {
resources: opfBaseTranslations,
chunks: opfBaseTranslationChunksConfig,
},
}),
provideConfig(<OpfConfig>{
opf: {
baseUrl: "PLACEHOLDER_OPF_BASE_URL",
commerceCloudPublicKey: "PLACEHOLDER_COMMERCE_CLOUD_PUBLIC_KEY",
},
})
]
})]
})
export class OpfFeatureModule { }
"
Expand Down
32 changes: 31 additions & 1 deletion integration-libs/opf/schematics/add-opf/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema
import {
OPF_BASE_FEATURE_NAME,
OPF_CHECKOUT_FEATURE_NAME,
OPF_CTA_FEATURE_NAME,
OPF_GLOBAL_FUNCTIONS_FEATURE_NAME,
OPF_PAYMENT_FEATURE_NAME,
OPF_QUICK_BUY_FEATURE_NAME,
SPARTACUS_CHECKOUT,
SPARTACUS_OPF,
SPARTACUS_SCHEMATICS,
Expand Down Expand Up @@ -72,6 +76,25 @@ describe('Spartacus SAP OPF integration schematics: ng-add', () => {
features: [OPF_BASE_FEATURE_NAME],
};

const opfPaymentFeatureOptions: SpartacusOpfOptions = {
...libraryNoFeaturesOptions,
features: [OPF_PAYMENT_FEATURE_NAME],
};

const opfCtaFeatureOptions: SpartacusOpfOptions = {
...libraryNoFeaturesOptions,
features: [OPF_CTA_FEATURE_NAME],
};
const opfGlobalFunctionsFeatureOptions: SpartacusOpfOptions = {
...libraryNoFeaturesOptions,
features: [OPF_GLOBAL_FUNCTIONS_FEATURE_NAME],
};

const opfQuickBuyFeatureOptions: SpartacusOpfOptions = {
...libraryNoFeaturesOptions,
features: [OPF_QUICK_BUY_FEATURE_NAME],
};

beforeEach(async () => {
schematicRunner.registerCollection(
SPARTACUS_SCHEMATICS,
Expand Down Expand Up @@ -129,7 +152,14 @@ describe('Spartacus SAP OPF integration schematics: ng-add', () => {
beforeEach(async () => {
appTree = await schematicRunner.runSchematic(
'ng-add',
{ ...checkoutFeatureOptions, ...opfFeatureOptions },
{
...checkoutFeatureOptions,
...opfFeatureOptions,
...opfPaymentFeatureOptions,
...opfCtaFeatureOptions,
...opfGlobalFunctionsFeatureOptions,
...opfQuickBuyFeatureOptions,
},
appTree
);
});
Expand Down
20 changes: 17 additions & 3 deletions integration-libs/opf/schematics/add-opf/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@
"type": "array",
"uniqueItems": true,
"items": {
"enum": ["OPF-Checkout", "OPF-Base"],
"enum": [
"OPF-Checkout",
"OPF-Base",
"OPF-Payment",
"OPF-Cta",
"OPF-Global-Functions",
"OPF-Quick-Buy"
],
"type": "string"
},
"default": ["OPF-Checkout", "OPF-Base"]
"default": [
"OPF-Checkout",
"OPF-Base",
"OPF-Payment",
"OPF-Cta",
"OPF-Global-Functions",
"OPF-Quick-Buy"
]
},
"baseUrl": {
"opfBaseUrl": {
"type": "string",
"description": "The base url of Cloud Commerce Adapter for Open Payment Framework integration",
"x-prompt": "[OPF] What is the base URL (origin) of your OPF Cloud Commerce Adapter?"
Expand Down
Loading