SAP Spartacus OccEndpointsService單元測試的依賴注入
OccEndpointsService的兩個依賴:
OccConfig和可選的BaseSiteService:
OccConfig是SiteContextConfig的子類:
export abstract class OccConfig extends SiteContextConfig {
backend?: {
occ?: {
baseUrl?: string;
prefix?: string;
/**
* Indicates whether or not cross-site Access-Control requests should be made
* using credentials such as cookies, authorization headers or TLS client certificates
*/
useWithCredentials?: boolean;
endpoints?: OccEndpoints;
legacy?: boolean;
};
media?: {
/**
* Media URLs are typically relative, so that the host can be configured.
* Configurable media baseURLs are useful for SEO, multi-site,
* switching environments, etc.
*/
baseUrl?: string;
};
loadingScopes?: LoadingScopes;
};
}
SiteContextConfig的實現:urlParameter,字串陣列和上下文名稱:
export abstract class SiteContextConfig {
context?: {
urlParameters?: string[];
[contextName: string]: string[];
};
}
end point資料結構:OccEndpoints
export interface OccEndpoints {
/**
* Client login (get authorization token)
*
* @member {string}
*/
login?: string | OccEndpoint;
/**
* Client logout (revoke authorization token)
*
* @member {string}
*/
revoke?: string | OccEndpoint;
/**
* Get product details for scope
*
* @member Object
*/
product?: string | ProductOccEndpoint;
/**
* Get reviews for a product
*
* @member {string}
*/
productReviews?: string | OccEndpoint;
/**
* Get a list of product references
*
* @member {string}
*/
productReferences?: string | OccEndpoint;
/**
* Get a list of products and additional data
*
* @member {string}
*/
productSearch?: string | OccEndpoint;
/**
* Get a list of available suggestions
*
* @member {string}
*/
productSuggestions?: string | OccEndpoint;
/**
* Get CMS component details
*
* @member {string}
*/
component?: string | OccEndpoint;
/**
* Get a list of CMS component details
*
* @member {string}
*/
components?: string | OccEndpoint;
/**
* Get page data with list of cms content slots
*
* @member {string}
*/
pages?: string | OccEndpoint;
/**
* Get page data with list of cms content slots
*
* @member {string}
*/
page?: string | OccEndpoint;
/**
* Get all carts
*
* @member {string} [carts]
*/
carts?: string | OccEndpoint;
/**
* Get a cart with a given identifier
*
* @member {string} [cart]
*/
cart?: string | OccEndpoint;
/**
* Creates or restore a cart for a user
*
* @member {string} [createCart]
*/
createCart?: string | OccEndpoint;
/**
* Deletes a cart with a given cart id
*
* @member {string} [deleteCart]
*/
deleteCart?: string | OccEndpoint;
/**
* Adds a product to the cart
*
* @member {string} [addEntries]
*/
addEntries?: string | OccEndpoint;
/**
* Update quantity and store the details of a cart entry
*
* @member {string} [updateEntries]
*/
updateEntries?: string | OccEndpoint;
/**
* Deletes cart entry
*
* @member {string} [removeEntries]
*/
removeEntries?: string | OccEndpoint;
/**
* Assign email to cart
*
* @member {string} [addEmail]
*/
addEmail?: string | OccEndpoint;
/**
* Get a store location
*
* @member {string} [page]
*/
store?: string | OccEndpoint;
/**
* Get a list of store locations
*
* @member {string} [page]
*/
stores?: string | OccEndpoint;
/**
* Gets a store location count per country and regions
*
* @member {string} [page]
*/
storescounts?: string | OccEndpoint;
/**
* Get a list of available languages
*
* @member {string}
*/
languages?: string | OccEndpoint;
/**
* Get a list of available currencies
*
* @member {string}
*/
currencies?: string | OccEndpoint;
/**
* Get a list of countries
*
* @member {string}
*/
countries?: string | OccEndpoint;
/**
* Fetch the list of regions for the provided country
*
* @member {string}
*/
regions?: string | OccEndpoint;
/**
* Titles used for user's personal info.
*
* @member {string}
*/
titles?: string | OccEndpoint;
/**
* Get user details
*
* @member {string}
*/
user?: string | OccEndpoint;
/**
* Register a new user.
*
* @member {string}
*/
userRegister?: string | OccEndpoint;
/**
* Request an email to reset the password
*
* @member {string}
*/
userForgotPassword?: string | OccEndpoint;
/**
* Reset the password once the email is recieved.
*
* @member {string}
*/
userResetPassword?: string | OccEndpoint;
/**
* Update the user id with which the user authenticates.
*
* @member {string}
*/
userUpdateLoginId?: string | OccEndpoint;
/**
* Update the user's password
*
* @member {string}
*/
userUpdatePassword?: string | OccEndpoint;
/**
* Payment details root endpoint.
*
* @member {string}
*/
paymentDetailsAll?: string | OccEndpoint;
/**
* Endpoint for a specific payment method.
*
* @member {string}
*/
paymentDetail?: string | OccEndpoint;
/**
* Endpoint for the list of one user's orders
*
* @member {string}
*/
orderHistory?: string | OccEndpoint;
/**
* Endpoint for the details of one user's order
*
* @member {string}
*/
orderDetail?: string | OccEndpoint;
/**
* Endpoint for anonymous consent templates
*
* @member {string}
*/
anonymousConsentTemplates?: string | OccEndpoint;
/**
* Endpoint for consent templates
*
* @member {string}
*/
consentTemplates?: string | OccEndpoint;
/**
* Endpoint for a user's consents
*
* @member {string}
*/
consents?: string | OccEndpoint;
/**
* Endpoint for a user's specific previously given consent.
*
* @member {string}
*/
consentDetail?: string | OccEndpoint;
/**
* Endpoint for a user's addresses
*
* @member {string}
*/
addresses?: string | OccEndpoint;
/**
* Endpoint for a user's specific address
*
* @member {string}
*/
addressDetail?: string | OccEndpoint;
/**
* Endpoint for address verification
*
* @member {string}
*/
addressVerification?: string | OccEndpoint;
/**
* Endpoint for consignment tracking
*
* @member {string}
*/
consignmentTracking?: string | OccEndpoint;
/**
* Endpoint for asm customer search
*
* @member {string}
*/
asmCustomerSearch?: string | OccEndpoint;
/**
* Endpoint for cart voucher
*
* @member {string}
*/
cartVoucher?: string | OccEndpoint;
/**
* Endpoint for coupons
*
* @member {string}
*/
customerCoupons?: string | OccEndpoint;
/**
* Endpoint for claiming coupon
*
* @member {string}
*/
claimCoupon?: string | OccEndpoint;
/**
* Endpoint for coupons
*
* @member {string}
*/
couponNotification?: string | OccEndpoint;
/**
* Explicitly saves a cart
*
* @member {string}
*/
saveCart?: string | OccEndpoint;
/**
* Endpoint for notification preference
*
* @member {string}
*/
notificationPreference?: string | OccEndpoint;
/**
* Endpoint for product interests
*
* @member {string}
*/
productInterests?: string | OccEndpoint;
/**
* Endpoint for getting product interests
*
* @member {string}
*/
getProductInterests?: string | OccEndpoint;
/**
* Endpoint for cancel an order
*/
cancelOrder?: string | OccEndpoint;
/**
* Endpoint for creating order return request
*/
returnOrder?: string | OccEndpoint;
/**
* Endpoint for user's order return requests
*/
orderReturns?: string | OccEndpoint;
/**
* Endpoint for order return request details
*/
orderReturnDetail?: string | OccEndpoint;
/**
* Endpoint for cancelling return request
*/
cancelReturn?: string | OccEndpoint;
/**
* Endpoint for set delivery address to cart
*/
setDeliveryAddress?: string | OccEndpoint;
/**
* Endpoint for place order
*/
placeOrder?: string | OccEndpoint;
/**
* Endpoint for userGroupOrderApprovalPermission
*
* @member {string}
*/
budget?: string | OccEndpoint;
/**
* Endpoint for budgets list
*
* @member {string}
*/
budgets?: string | OccEndpoint;
/**
* Endpoint for organizations
*
* @member {string}
*/
orgUnits?: string | OccEndpoint;
/**
* Endpoint for organizations list
*
* @member {string}
*/
orgUnitsAvailable?: string | OccEndpoint;
/**
* Endpoint for organization units tree
*
* @member {string}
*/
orgUnitsTree?: string | OccEndpoint;
/**
* Endpoint for approval processes for organization units
*
* @member {string}
*/
orgUnitsApprovalProcesses?: string | OccEndpoint;
/**
* Endpoint for organization
*
* @member {string}
*/
orgUnit?: string | OccEndpoint;
/**
* Endpoint for orgUnitUsers:
*
* @member {string}
*/
orgUnitUsers?: string | OccEndpoint;
/**
* Endpoint for add orgUnitUserRoles (except approver):
*
* @member {string}
*/
orgUnitUserRoles?: string | OccEndpoint;
/**
* Endpoint for remove orgUnitUserRole (except approver):
*
* @member {string}
*/
orgUnitUserRole?: string | OccEndpoint;
/**
* Endpoint for add orgUnitApprovers:
*
* @member {string}
*/
orgUnitApprovers?: string | OccEndpoint;
/**
* Endpoint for delete orgUnitApprover:
*
* @member {string}
*/
orgUnitApprover?: string | OccEndpoint;
/**
* Endpoint for organizational unit addresses
*
* @member {string}
*/
orgUnitsAddresses?: string | OccEndpoint;
/**
* Endpoint for organizational unit address
*
* @member {string}
*/
orgUnitsAddress?: string | OccEndpoint;
/**
* Endpoint for organizational unit user groups list
*
* @member {string}
*/
userGroups?: string | OccEndpoint;
/**
* Endpoint for organizational unit user group
*
* @member {string}
*/
userGroup?: string | OccEndpoint;
/**
* Endpoint for costCenter list
*
* @member {string}
*/
userGroupAvailableOrderApprovalPermissions?: string | OccEndpoint;
/**
* Endpoint for userGroupAvailableOrderApprovalPermissions list
*
* @member {string}
*/
userGroupAvailableOrgCustomers?: string | OccEndpoint;
/**
* Endpoint for userGroupAvailableOrgCustomers list
*
* @member {string}
*/
userGroupMembers?: string | OccEndpoint;
/**
* Endpoint for userGroupMembers list
*
* @member {string}
*/
userGroupMember?: string | OccEndpoint;
/**
* Endpoint for userGroupMember
*
* @member {string}
*/
userGroupOrderApprovalPermissions?: string | OccEndpoint;
/**
* Endpoint for userGroupOrderApprovalPermissions list
*
* @member {string}
*/
userGroupOrderApprovalPermission?: string | OccEndpoint;
/**
* Endpoint for userGroupOrderApprovalPermission
*
* @member {string}
*/
costCenters?: string | OccEndpoint;
/**
* Endpoint to schedule a replenishment order
*
* * @member {string}
*/
scheduleReplenishmentOrder?: string | OccEndpoint;
/**
* * Endpoint for the list of one user's replenishment orders
*
* * @member {string}
*/
replenishmentOrderHistory?: string | OccEndpoint;
/* Endpoint to get a replenishment order details
*
* * @member {string}
*/
replenishmentOrderDetails?: string | OccEndpoint;
/**
* Endpoint to get a replenishment order history for a replenishment
*
* * @member {string}
*/
replenishmentOrderDetailsHistory?: string | OccEndpoint;
/**
* Endpoint to get a replenishment order history for a replenishment
*
* * @member {string}
*/
cancelReplenishmentOrder?: string | OccEndpoint;
/**
* Endpoint for all costCenters
*
* @member {string}
*/
costCentersAll?: string | OccEndpoint;
/**
* Endpoint for costCenter
*
* @member {string}
*/
costCenter?: string | OccEndpoint;
/**
* Endpoint for budgets assigned to costCenter
*
* @member {string}
*/
costCenterBudgets?: string | OccEndpoint;
/**
* Endpoint for budget assigned to costCenter
*
* @member {string}
*/
costCenterBudget?: string | OccEndpoint;
/**
* Endpoint for permission list
*
* @member {string}
*/
permissions?: string | OccEndpoint;
/**
* Endpoint for permission
*
* @member {string}
*/
permission?: string | OccEndpoint;
/**
* Endpoint for order approval permission types
*
* @member {string}
*/
orderApprovalPermissionTypes?: string | OccEndpoint;
/**
* Endpoint for organization customers
*
* @member {string}
*/
b2bUsers?: string | OccEndpoint;
/**
* Endpoint for organization customer
*
* @member {string}
*/
b2bUser?: string | OccEndpoint;
/**
* Endpoint for organization customer approvers
*
* @member {string}
*/
b2bUserApprovers?: string | OccEndpoint;
/**
* Endpoint for organization customer approver
*
* @member {string}
*/
b2bUserApprover?: string | OccEndpoint;
/**
* Endpoint for organization customer user groups
*
* @member {string}
*/
b2bUserUserGroups?: string | OccEndpoint;
/**
* Endpoint for organization customer user group
*
* @member {string}
*/
b2bUserUserGroup?: string | OccEndpoint;
/**
* Endpoint for organization customer permissions
*
* @member {string}
*/
b2bUserPermissions?: string | OccEndpoint;
/**
* Endpoint for organization customer permission
*
* @member {string}
*/
b2bUserPermission?: string | OccEndpoint;
/**
* Endpoint for order approvals
*
* @member {string}
*/
orderApprovals?: string | OccEndpoint;
/**
* Endpoint for order approval
*
* @member {string}
*/
orderApproval?: string | OccEndpoint;
/**
* Endpoint for order approval decision
*
* @member {string}
*/
orderApprovalDecision?: string | OccEndpoint;
}
在單元測試裡對OccConfig進行mock:
beforeEach(() => {
mockOccConfig = {
backend: {
occ: {
baseUrl: 'test-baseUrl',
prefix: '/test-occPrefix',
endpoints: {
login: '/authorizationserver/oauth/token',
product: {
default: 'configured-endpoint1/${test}?fields=abc',
test: 'configured-endpoint1/${test}?fields=test',
},
},
},
},
context: {
baseSite: ['/test-baseSite'],
},
};
TestBed.configureTestingModule({
providers: [{ provide: OccConfig, useValue: mockOccConfig }],
});
service = TestBed.inject(OccEndpointsService);
});
相關文章
- 搞定Go單元測試(四)—— 依賴注入框架(wire)Go依賴注入框架
- SAP Spartacus 中的依賴注入 Dependency Injection 介紹依賴注入
- Android單元測試(5):依賴注入,將mock方便的用起來Android依賴注入Mock
- Android單元測試(6):使用dagger2來做依賴注入Android依賴注入
- SAP 電商雲 Spartacus UI SSR 單元測試裡的 callFakeUI
- JUnit5依賴注入與測試介面依賴注入
- 實戰指南:使用 xUnit.DependencyInjection 在單元測試中實現依賴注入【完整教程】依賴注入
- JAVA單元測試框架-9-testng.xml管理依賴Java框架XML
- 在 xunit 測試專案中使用依賴注入依賴注入
- 打造簡單的依賴注入功能依賴注入
- WinForm依賴注入簡單使用ORM依賴注入
- 依賴注入?依賴注入是如何實現解耦的?依賴注入解耦
- SAP 電商雲 Spartacus UI DeliveryComponent 的依賴設計UI
- JavaScrpit 的簡單的依賴注入Java依賴注入
- ASP.NET Core中的依賴注入(2):依賴注入(DI)ASP.NET依賴注入
- SAP 電商雲 Spartacus UI 的單元測試和端到端測試,以及 CI/CD 相關話題UI
- angular依賴注入Angular依賴注入
- XUnit 依賴注入依賴注入
- Struts 依賴注入依賴注入
- 簡單歡樂的依賴注入函式依賴注入函式
- 依賴倒置(DIP)與依賴注入(DI)依賴注入
- 簡單談談Hilt——依賴注入框架依賴注入框架
- spring 的依賴注入Spring依賴注入
- JavaScript裡的依賴注入JavaScript依賴注入
- 用trait實現簡單的依賴注入AI依賴注入
- Angular 依賴的測試和 FakeAngular
- [譯] 依賴注入?? 哈??依賴注入
- Angular 依賴注入原理Angular依賴注入
- .Net Core — 依賴注入依賴注入
- 理解 Angular 依賴注入Angular依賴注入
- Spring依賴注入Spring依賴注入
- Spring依賴注入---Spring依賴注入
- 依賴注入系列教程依賴注入
- 我看依賴注入依賴注入
- webapi - 使用依賴注入WebAPI依賴注入
- 依賴注入是否值得?依賴注入
- Spring【依賴注入】就是這麼簡單Spring依賴注入
- 關於 SAP 電商雲 Spartacus UI package.json 中的 sass 依賴UIPackageJSON