// Copyright: (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) import { describe, it, expect } from 'vitest'; import { AuthOrigin, Channel } from '@archer/domain'; import { resolveChannel } from '../channel'; describe('resolveChannel', () => { // Table-driven exhaustive priority check. // WP build flag dominates over any auth origin; SHOPIFY origin only matters // in the web bundle (no WP build flag); otherwise WEBSITE default. const cases: ReadonlyArray<{ name: string; isWpEmbedBuild: boolean; authOrigin: AuthOrigin | undefined; expected: Channel; }> = [ { name: 'WP build, twwim user', isWpEmbedBuild: true, authOrigin: AuthOrigin.TWWIM, expected: Channel.WORDPRESS }, { name: 'WP build, shopify user (impossible irl)', isWpEmbedBuild: true, authOrigin: AuthOrigin.SHOPIFY, expected: Channel.WORDPRESS }, { name: 'WP build, no user (pre-login)', isWpEmbedBuild: true, authOrigin: undefined, expected: Channel.WORDPRESS }, { name: 'web bundle, shopify user', isWpEmbedBuild: false, authOrigin: AuthOrigin.SHOPIFY, expected: Channel.SHOPIFY }, { name: 'web bundle, twwim user', isWpEmbedBuild: false, authOrigin: AuthOrigin.TWWIM, expected: Channel.WEBSITE }, { name: 'web bundle, no user (pre-login)', isWpEmbedBuild: false, authOrigin: undefined, expected: Channel.WEBSITE }, ]; it.each(cases)('$name → $expected', ({ isWpEmbedBuild, authOrigin, expected }) => { expect(resolveChannel({ isWpEmbedBuild, authOrigin })).toBe(expected); }); it('build flag wins regardless of authOrigin (priority invariant)', () => { const wp = resolveChannel({ isWpEmbedBuild: true, authOrigin: AuthOrigin.SHOPIFY }); expect(wp).toBe(Channel.WORDPRESS); }); it('falls back to WEBSITE for unknown authOrigin string in web bundle', () => { const result = resolveChannel({ isWpEmbedBuild: false, authOrigin: 'something-else' as AuthOrigin }); expect(result).toBe(Channel.WEBSITE); }); });