Files
2026-05-23 18:23:48 +02:00

85 lines
2.4 KiB
JavaScript

// @ts-nocheck
/**
* tests/helpers/foundryAdapterMock.js
*
* Canonical FoundryAdapter mock factory.
* ALL tests in this project MUST use this factory — no ad-hoc stubs.
*
* Usage:
* import { createFoundryAdapterMock } from '../helpers/foundryAdapterMock.js'
* const adapter = createFoundryAdapterMock()
* const adapter = createFoundryAdapterMock({ settings: { get: () => 'custom' } })
*
* Surface contract mirrors FoundryAdapter (src/foundry/FoundryAdapter.js):
* settings, socket, users, scenes, notifications, webrtc, hooks
*/
/**
* Creates a mock FoundryAdapter with optional overrides.
*
* All methods are vi.fn() stubs by default; pass overrides to customise.
*
* @param {Partial<FoundryAdapterSurface>} [overrides={}]
* @returns {FoundryAdapterSurface}
*/
export function createFoundryAdapterMock(overrides = {}) {
const defaults = {
settings: {
register: () => {},
get: () => null,
set: () => Promise.resolve(),
...overrides.settings,
},
socket: {
emit: () => {},
on: () => {},
off: () => {},
...overrides.socket,
},
users: {
get: () => null,
all: () => [],
isGM: () => false,
current: () => overrides.users?.get?.("test-user") ?? null,
...overrides.users,
},
scenes: {
current: () => null,
get: () => null,
...overrides.scenes,
},
notifications: {
info: () => {},
warn: () => {},
error: () => {},
...overrides.notifications,
},
/**
* WebRTC track-disabling surface, or null when OQ-1 resolved to css-fallback.
*
* Default is null (CSS fallback path). FoundryVTT v14 spike (Story 1.2) confirmed
* that track.enabled = false does not stop inbound RTP bandwidth, so the probe
* always returns 'css-fallback' and this.webrtc remains null in production.
*
* To simulate the track-disable path in tests, override with:
* createFoundryAdapterMock({ webrtc: { disableTrack: vi.fn(), enableTrack: vi.fn() } })
*/
webrtc: overrides.webrtc !== undefined ? overrides.webrtc : null,
/** i18n surface for localization support */
i18n: {
// eslint-disable-next-line no-unused-vars
localize: (key, _data) => key, // Default: return key (no translation)
...overrides.i18n,
},
hooks: {
on: () => {},
once: () => {},
off: () => {},
callAll: () => {},
...overrides.hooks,
},
};
return defaults;
}