import { describe, it, type TestContext } from 'node:test'; import { elevate, esales, queries, notifications } from './mod.ts'; import { Query } from './query.ts'; import { Notification } from './notification.ts'; import * as lib from './mod.ts'; const session = () => ({ customerKey: '', sessionKey: '' }); describe('lib', () => { it('should export legacy entrypoint for backwards compat', (t: TestContext) => { t.assert.strictEqual(elevate, esales); }); it('should not export any internal values publicly', (t: TestContext) => { const internalKeys = Object.keys(lib).filter(k => /^_/.test(k)); t.assert.strictEqual(internalKeys.length, 0); }); it('should throw if config is invalid', (t: TestContext) => { // deno-lint-ignore no-explicit-any t.assert.throws(() => elevate(undefined as any)); }); it('should have correct properties after instantiation', (t: TestContext) => { const api = elevate({ clusterId: 'w000000', market: 'a', locale: 'a', touchpoint: 'desktop', session }); api satisfies { clusterUrl: string, query: Query, notify: Notification }; t.assert.strictEqual(typeof api.clusterUrl, 'string'); t.assert.ok(api.query instanceof Query); t.assert.ok(api.notify instanceof Notification); }); it('should be able to create Query object only for tree-shaking purposes', (t: TestContext) => { const query = queries({ clusterId: 'w000000', market: 'a', locale: 'a', touchpoint: 'desktop', session }); query satisfies Query; t.assert.ok(query instanceof Query); }); it('should be able to create Notification object only for tree-shaking purposes', (t: TestContext) => { const notify = notifications({ clusterId: 'w000000', market: 'a', session }); notify satisfies Notification; t.assert.ok(notify instanceof Notification); }); it('should pass Config.clusterUrl onwards to API instance', (t: TestContext) => { const base = { market: 'a', locale: 'a', touchpoint: 'desktop', session } as const; t.assert.strictEqual(elevate({ ...base, clusterId: 'https://acme.com/' }).clusterUrl, 'https://acme.com/'); t.assert.strictEqual(elevate({ ...base, clusterId: 'w1337ed' }).clusterUrl, 'https://w1337ed.api.esales.apptus.cloud/'); }); it('should export all public types', () => { // GENERAL type Entrypoint = lib.Config | lib.NotificationConfig | lib.Session | lib.UserContext | lib.SessionMetadata | lib.PersonalizedSession | lib.Touchpoint | lib.LocalStorageSession; type CommonModels = lib.Algorithm | lib.AutoCorrect | lib.Availability | lib.Badge | lib.BadgeType | lib.Breadcrumb | lib.CheckboxFacet | lib.ColorFacet | lib.ColorFacetValue | lib.ContentItem | lib.ContentList | lib.ContentListPage | lib.ContentSortType | lib.CustomAttribute | lib.CustomAttributes | lib.DidYouMean | lib.Facet | lib.FacetParams | lib.FacetRange | lib.FacetType | lib.FacetTextSort | lib.FacetValue | lib.Image | lib.ImageEffect | lib.ImageSource | lib.MeasurementResult | lib.Navigation | lib.NavigationItemType | lib.NavigationLabelNode | lib.NavigationLabelStateNode | lib.NavigationLinkNode | lib.NavigationLinkStateNode | lib.NavigationNode | lib.NavigationProductNode | lib.NavigationProductStateNode | lib.NavigationSpacerNode | lib.NavigationSpacerStateNode | lib.NavigationStateNode | lib.Price | lib.PriceResult | lib.PrimaryList | lib.ProductGroup | lib.Product | lib.ProductListSummary | lib.RangeFacet | lib.RecommendationList | lib.RecommendationListPage | lib.SecondaryList | lib.SizeFacet | lib.SizeFormat | lib.SizeType | lib.Sort | lib.SortOption | lib.SortType | lib.SwatchType | lib.TextFacet | lib.TextFacetValue | lib.Timestamp | lib.TypedCustomAttributes | lib.TypedCustomMeasurementAttribute | lib.TypedCustomNumberAttribute | lib.TypedCustomAttribute | lib.Variant | lib.Visualization; // ENDPOINTS // AddToCartPopup type AllAddToCartPopup = lib.AddToCartPopup | lib.AddToCartPopupParams | lib.AddToCartPopupBody; // Autocomplete type AllAutocomplete = lib.Autocomplete | lib.AutocompleteParams | lib.AutocompleteBody | lib.PhraseSuggestion | lib.ContentSuggestion | lib.RecentSearch; // CartPage type AllCartPage = lib.CartPage | lib.CartPageParams | lib.CartPageBody; // ContentInformation type AllContentInformation = lib.ContentInformation | lib.ContentInformationParams; // DiscoveryAgentTopic type AllDiscoveryAgentTopic = lib.DiscoveryAgentTopic | lib.DiscoveryAgentTopicParams; // ContentSearchPage type AllContentSearchPage = lib.ContentSearchPage | lib.ContentSearchPageParams | lib.ContentSearchPageBody | lib.ContentSearchOrigin | lib.PrimaryContentList; // LandingPage type AllLandingPage = lib.LandingPage | lib.LandingPageParams | lib.LandingPageBody | lib.SearchEngineOptimization; // NavigationTree type AllNavigationTree = lib.NavigationTree | lib.NavigationTreeParams; // ProductPage type AllProductPage = lib.ProductPage | lib.ProductPageParams | lib.ProductPageBody; // SearchPage type AllSearchPage = lib.SearchPage | lib.SearchPageParams | lib.SearchPageBody | lib.SearchOrigin; ({}) satisfies Record< string, Entrypoint | CommonModels | AllAddToCartPopup | AllAutocomplete | AllCartPage | AllContentInformation | AllContentSearchPage | AllDiscoveryAgentTopic | AllLandingPage | AllNavigationTree | AllProductPage | AllSearchPage >; }); });