91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
|
|
import { describe, expect, it } from 'vitest';
|
||
|
|
import * as sdk from '../src/index.js';
|
||
|
|
import { RudderClient } from '../src/index.js';
|
||
|
|
|
||
|
|
describe('public API surface', () => {
|
||
|
|
it('does not expose scenario runtime types from the root package', () => {
|
||
|
|
expect('ScenarioService' in sdk).toBe(false);
|
||
|
|
expect('NotificationSession' in sdk).toBe(false);
|
||
|
|
expect('StoreSession' in sdk).toBe(false);
|
||
|
|
expect('WaitSession' in sdk).toBe(false);
|
||
|
|
expect('LeaderboardSession' in sdk).toBe(false);
|
||
|
|
expect('PlanRun' in sdk).toBe(false);
|
||
|
|
expect('createIndexedDbPlanStateStore' in sdk).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('keeps helpers, domain classes, and service constructors out of the barrel', () => {
|
||
|
|
// Device id helper — internal.
|
||
|
|
expect('getOrCreateDeviceId' in sdk).toBe(false);
|
||
|
|
// Domain classes — exported as types only.
|
||
|
|
for (const name of [
|
||
|
|
'PlayerDomain',
|
||
|
|
'CatalogDomain',
|
||
|
|
'InventoryDomain',
|
||
|
|
'ConfigDomain',
|
||
|
|
'StorageDomain',
|
||
|
|
'StoresDomain',
|
||
|
|
]) {
|
||
|
|
expect(name in sdk).toBe(false);
|
||
|
|
}
|
||
|
|
// Service constructors — exported as types only.
|
||
|
|
for (const name of [
|
||
|
|
'AuthService',
|
||
|
|
'LeaderboardsService',
|
||
|
|
'LeaderboardHandle',
|
||
|
|
'BattlePassService',
|
||
|
|
'BattlepassService',
|
||
|
|
'QuestsService',
|
||
|
|
]) {
|
||
|
|
expect(name in sdk).toBe(false);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
it('exposes the expected value exports', () => {
|
||
|
|
for (const name of [
|
||
|
|
'RudderClient',
|
||
|
|
'RudderError',
|
||
|
|
'RudderNetworkError',
|
||
|
|
'RudderHttpError',
|
||
|
|
'RudderAuthError',
|
||
|
|
'SDK_ERROR_INVALID_OPTIONS',
|
||
|
|
'RudderErrorCodes',
|
||
|
|
'createDefaultTokenStore',
|
||
|
|
'createLocalStorageTokenStore',
|
||
|
|
'SyncedState',
|
||
|
|
'RemoteConfigState',
|
||
|
|
'ShopHandle',
|
||
|
|
'OfferHandle',
|
||
|
|
]) {
|
||
|
|
expect(name in sdk, name).toBe(true);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
it('exposes effects without a public scenarios service on the client', () => {
|
||
|
|
const client = new RudderClient({
|
||
|
|
baseUrl: 'https://api.test.rudder.build',
|
||
|
|
projectKey: 'test-project',
|
||
|
|
runtime: { planStateStore: null, loginEvent: null },
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(client.effects).toBeDefined();
|
||
|
|
expect('scenarios' in client).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('uses the canonical glossary property names on the client', () => {
|
||
|
|
const client = new RudderClient({
|
||
|
|
baseUrl: 'https://api.test.rudder.build',
|
||
|
|
projectKey: 'test-project',
|
||
|
|
runtime: { planStateStore: null, loginEvent: null },
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(client.remoteConfig).toBeDefined();
|
||
|
|
expect('config' in client).toBe(false);
|
||
|
|
expect(client.battlePass).toBeDefined();
|
||
|
|
expect('battlepass' in client).toBe(false);
|
||
|
|
expect(typeof client.effects.onBattlePass).toBe('function');
|
||
|
|
expect(typeof client.effects.onBattlePassLevel).toBe('function');
|
||
|
|
expect('onBattlepass' in client.effects).toBe(false);
|
||
|
|
expect('onBattlepassLevel' in client.effects).toBe(false);
|
||
|
|
});
|
||
|
|
});
|