Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

test(config): trim the config loader and env override suites

Hampus97333eac02ab
diff --git a/packages/config/src/__tests__/ConfigLoader.test.ts b/packages/config/src/__tests__/ConfigLoader.test.ts
index da384f505..4a974e7a5 100644
--- a/packages/config/src/__tests__/ConfigLoader.test.ts
+++ b/packages/config/src/__tests__/ConfigLoader.test.ts
@@ -67,19 +67,6 @@ describe('ConfigLoader', () => {
vi.unstubAllEnvs();
});
- test('loadConfig builds and caches config from FLUXER environment variables', async () => {
- stubMinimalEnv();
- const config = await loadConfig();
- expect(config.env).toBe('test');
- expect(config.domain.base_domain).toBe('localhost');
- expect(config.database.backend).toBe('postgres');
- expect(config.database.postgres.database).toBe('fluxer');
- expect(config.database.cassandra.hosts).toEqual(['127.0.0.1']);
-
- vi.stubEnv('FLUXER_BASE_DOMAIN', 'changed.example');
- expect((await loadConfig()).domain.base_domain).toBe('localhost');
- });
-
test('a self-hosted instance without FLUXER_ENV runs in production', async () => {
stubMinimalEnv({
FLUXER_SELF_HOSTED: 'true',
@@ -92,290 +79,6 @@ describe('ConfigLoader', () => {
expect((await loadConfig()).env).toBe('production');
});
- test('a self-hosted instance keeps an explicit FLUXER_ENV', async () => {
- stubMinimalEnv({FLUXER_SELF_HOSTED: 'true', FLUXER_ENV: 'development'});
- expect((await loadConfig()).env).toBe('development');
- });
-
- test('an instance that is not self-hosted still defaults to development', async () => {
- stubMinimalEnv();
- vi.stubEnv('FLUXER_ENV', undefined);
- expect((await loadConfig()).env).toBe('development');
- });
-
- test('endpoint overrides take precedence over derived endpoints', async () => {
- stubMinimalEnv({
- FLUXER_API_ENDPOINT: 'https://custom-api.example.com',
- FLUXER_API_CLIENT_ENDPOINT: 'https://custom-api-client.example.com',
- FLUXER_GATEWAY_ENDPOINT: 'wss://custom-gw.example.com',
- });
-
- const config = await loadConfig();
-
- expect(config.endpoints.api).toBe('https://custom-api.example.com');
- expect(config.endpoints.api_client).toBe('https://custom-api-client.example.com');
- expect(config.endpoints.gateway).toBe('wss://custom-gw.example.com');
- expect(config.endpoints.app).toBe('http://localhost:8088');
- });
-
- test('inserts the public port into portless endpoints on a non-standard port', async () => {
- stubMinimalEnv({
- FLUXER_MARKETING_ENDPOINT: 'http://localhost',
- FLUXER_MEDIA_ENDPOINT: 'http://localhost/media',
- FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT: 'http://localhost/media',
- FLUXER_PASSKEY_ADDITIONAL_ALLOWED_ORIGINS: 'http://localhost',
- });
-
- const config = await loadConfig();
-
- expect(config.endpoints.marketing).toBe('http://localhost:8088');
- expect(config.endpoints.media).toBe('http://localhost:8088/media');
- expect(config.services.media_proxy.upload_relay.endpoint).toBe('http://localhost:8088/media');
- expect(config.auth.passkeys.additional_allowed_origins).toEqual(['http://localhost:8088']);
- });
-
- test('leaves a default https install untouched', async () => {
- stubMinimalEnv({
- FLUXER_BASE_DOMAIN: 'chat.example',
- FLUXER_PUBLIC_SCHEME: 'https',
- FLUXER_PUBLIC_PORT: '443',
- FLUXER_MARKETING_ENDPOINT: 'https://chat.example',
- FLUXER_MEDIA_ENDPOINT: 'https://chat.example/media',
- FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT: 'https://chat.example/media',
- FLUXER_PASSKEY_ADDITIONAL_ALLOWED_ORIGINS: 'https://chat.example',
- });
-
- const config = await loadConfig();
-
- expect(config.endpoints.marketing).toBe('https://chat.example');
- expect(config.endpoints.media).toBe('https://chat.example/media');
- expect(config.endpoints.api).toBe('https://chat.example/api');
- expect(config.endpoints.gateway).toBe('wss://chat.example/gateway');
- expect(config.services.media_proxy.upload_relay.endpoint).toBe('https://chat.example/media');
- expect(config.auth.passkeys.additional_allowed_origins).toEqual(['https://chat.example']);
- });
-
- test('leaves a default http install untouched', async () => {
- stubMinimalEnv({
- FLUXER_BASE_DOMAIN: 'chat.example',
- FLUXER_PUBLIC_SCHEME: 'http',
- FLUXER_PUBLIC_PORT: '80',
- FLUXER_MARKETING_ENDPOINT: 'http://chat.example',
- FLUXER_MEDIA_ENDPOINT: 'http://chat.example/media',
- FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT: 'http://chat.example/media',
- });
-
- const config = await loadConfig();
-
- expect(config.endpoints.marketing).toBe('http://chat.example');
- expect(config.endpoints.media).toBe('http://chat.example/media');
- expect(config.endpoints.gateway).toBe('ws://chat.example/gateway');
- expect(config.services.media_proxy.upload_relay.endpoint).toBe('http://chat.example/media');
- });
-
- test('leaves foreign hosts and already ported endpoints untouched', async () => {
- stubMinimalEnv({
- FLUXER_STATIC_CDN_ENDPOINT: 'https://cdn.example.net',
- FLUXER_MEDIA_ENDPOINT: 'https://media.example.net/media',
- FLUXER_MARKETING_ENDPOINT: 'http://localhost:9999',
- FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT: 'http://localhost:8088/media',
- });
-
- const config = await loadConfig();
-
- expect(config.endpoints.static_cdn).toBe('https://cdn.example.net');
- expect(config.endpoints.media).toBe('https://media.example.net/media');
- expect(config.endpoints.marketing).toBe('http://localhost:9999');
- expect(config.services.media_proxy.upload_relay.endpoint).toBe('http://localhost:8088/media');
- });
-
- test('normalizes each passkey origin independently', async () => {
- stubMinimalEnv({
- FLUXER_PASSKEY_ADDITIONAL_ALLOWED_ORIGINS:
- 'http://localhost,http://localhost:3000,https://desktop.example.net,android:apk-key-hash:keSY4bimyLqZQV7bKXgpa2xYuqXi0qZJzsYtp6gpx7w',
- });
-
- const config = await loadConfig();
-
- expect(config.auth.passkeys.additional_allowed_origins).toEqual([
- 'http://localhost:8088',
- 'http://localhost:3000',
- 'https://desktop.example.net',
- 'android:apk-key-hash:keSY4bimyLqZQV7bKXgpa2xYuqXi0qZJzsYtp6gpx7w',
- ]);
- });
-
- test('includes the app origin alongside the default passkey origins', async () => {
- stubMinimalEnv();
- const config = await loadConfig();
- expect(config.auth.passkeys.additional_allowed_origins).toEqual([
- 'https://fluxer.app',
- 'https://web.fluxer.app',
- 'https://web.canary.fluxer.app',
- 'https://fluxer.com',
- 'https://canary.fluxer.com',
- 'android:apk-key-hash:keSY4bimyLqZQV7bKXgpa2xYuqXi0qZJzsYtp6gpx7w',
- 'http://localhost:8088',
- ]);
- });
-
- test('defaults to no app origin aliases', async () => {
- stubMinimalEnv();
- const config = await loadConfig();
- expect(config.services.api.app_origin_aliases).toEqual([]);
- });
-
- test('normalizes and deduplicates app origin aliases', async () => {
- stubMinimalEnv({
- FLUXER_APP_ORIGIN_ALIASES:
- 'https://Web.Fluxer.App/, https://fluxer.com,https://fluxer.com:443,http://localhost:3000',
- });
- const config = await loadConfig();
- expect(config.services.api.app_origin_aliases).toEqual([
- 'https://web.fluxer.app',
- 'https://fluxer.com',
- 'http://localhost:3000',
- ]);
- });
-
- test.each(['fluxer.com', 'https://fluxer.com/app', 'ftp://fluxer.com', 'https://[email protected]'])(
- 'rejects the app origin alias %s',
- async (alias) => {
- stubMinimalEnv({FLUXER_APP_ORIGIN_ALIASES: alias});
- await expect(loadConfig()).rejects.toThrow('FLUXER_APP_ORIGIN_ALIASES entry 1 must be an HTTP(S) origin');
- },
- );
-
- test('an empty client API endpoint override falls back to the derived endpoint', async () => {
- stubMinimalEnv({FLUXER_API_CLIENT_ENDPOINT: ''});
- expect((await loadConfig()).endpoints.api_client).toBe('http://localhost:8088/api');
- });
-
- test('defaults the passkey relying party to the deployment domain', async () => {
- stubMinimalEnv({
- FLUXER_BASE_DOMAIN: 'chat.example.com',
- FLUXER_PUBLIC_SCHEME: 'https',
- FLUXER_PUBLIC_PORT: '443',
- });
-
- const config = await loadConfig();
-
- expect(config.auth.passkeys.rp_id).toBe('chat.example.com');
- });
-
- test('a blank origin list keeps the built-in origins', async () => {
- stubMinimalEnv({
- FLUXER_BASE_DOMAIN: 'chat.example.com',
- FLUXER_PUBLIC_SCHEME: 'https',
- FLUXER_PUBLIC_PORT: '443',
- FLUXER_PASSKEY_ADDITIONAL_ALLOWED_ORIGINS: ' ',
- });
-
- const config = await loadConfig();
-
- expect(config.auth.passkeys.additional_allowed_origins).toContain('https://web.fluxer.app');
- expect(config.auth.passkeys.additional_allowed_origins).toContain('https://chat.example.com');
- });
-
- test('blank values fall back to the code defaults', async () => {
- stubMinimalEnv({
- FLUXER_API_PORT: '',
- FLUXER_EMAIL_FROM_NAME: '',
- FLUXER_KV_URL: ' ',
- FLUXER_S3_FORCE_PATH_STYLE: '',
- FLUXER_API_STORAGE_CHANGE_FEED_SKIP_BUCKETS: '',
- });
-
- const config = await loadConfig();
-
- expect(config.services.api.port).toBe(8080);
- expect(config.integrations.email.from_name).toBe('');
- expect(config.internal.kv).toBe('redis://localhost:6379/0');
- expect(config.s3?.force_path_style).toBe(false);
- expect(config.services.api.storage_change_feed?.skip_buckets).toBeUndefined();
- });
-
- test.each(['support', 'Support <[email protected]>', '[email protected],[email protected]', ' [email protected]'])(
- 'rejects %j as the email reply-to address',
- async (value) => {
- stubMinimalEnv({FLUXER_EMAIL_REPLY_TO_EMAIL: value});
- await expect(loadConfig()).rejects.toThrow('FLUXER_EMAIL_REPLY_TO_EMAIL must be a single email address');
- },
- );
-
- test('keeps explicit passkey relying party values', async () => {
- stubMinimalEnv({
- FLUXER_BASE_DOMAIN: 'chat.example.com',
- FLUXER_PUBLIC_SCHEME: 'https',
- FLUXER_PUBLIC_PORT: '443',
- FLUXER_PASSKEY_RP_ID: 'example.com',
- FLUXER_PASSKEY_ADDITIONAL_ALLOWED_ORIGINS: 'https://example.com,https://app.example.com',
- });
-
- const config = await loadConfig();
-
- expect(config.auth.passkeys.rp_id).toBe('example.com');
- expect(config.auth.passkeys.additional_allowed_origins).toEqual(['https://example.com', 'https://app.example.com']);
- });
-
- test('parses typed named environment variables', async () => {
- stubMinimalEnv({
- FLUXER_API_PORT: '9090',
- FLUXER_CASSANDRA_HOSTS: 'db1,db2',
- FLUXER_POSTGRES_HOST: 'pg1',
- FLUXER_POSTGRES_PORT: '5544',
- FLUXER_POSTGRES_MAX_CONNECTIONS: '7',
- FLUXER_POSTGRES_SSL_CA: '-----BEGIN CERTIFICATE-----\\n-----END CERTIFICATE-----',
- FLUXER_POSTGRES_PREPARED_STATEMENTS: 'false',
- FLUXER_API_WORKER_MODE: 'single_task',
- FLUXER_API_WORKER_TASK: 'processStripeWebhook',
- FLUXER_LIVEKIT_ENABLED: 'true',
- FLUXER_LIVEKIT_DEFAULT_REGION:
- '{"id":"local","name":"Local","emoji":"LC","latitude":59.3293,"longitude":18.0686}',
- });
-
- const config = await loadConfig();
-
- expect(config.services.api.port).toBe(9090);
- expect(config.database.cassandra.hosts).toEqual(['db1', 'db2']);
- expect(config.database.postgres.host).toBe('pg1');
- expect(config.database.postgres.port).toBe(5544);
- expect(config.database.postgres.max_connections).toBe(7);
- expect(config.database.postgres.ssl_ca).toBe('-----BEGIN CERTIFICATE-----\\n-----END CERTIFICATE-----');
- expect(config.database.postgres.prepared_statements).toBe(false);
- expect(config.services.api.worker?.mode).toBe('single_task');
- expect(config.services.api.worker?.task).toBe('processStripeWebhook');
- expect(config.integrations.voice.default_region?.id).toBe('local');
- });
-
- test('rejects an unknown worker lane', async () => {
- stubMinimalEnv({FLUXER_API_WORKER_MODE: 'single_lane', FLUXER_API_WORKER_LANE: 'publishing'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_API_WORKER_LANE');
- });
-
- test('rejects single task worker mode without task env', async () => {
- stubMinimalEnv({FLUXER_API_WORKER_MODE: 'single_task'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_API_WORKER_TASK');
- });
-
- test('rejects a storage change feed stream name that JetStream cannot use', async () => {
- stubMinimalEnv({
- FLUXER_API_STORAGE_CHANGE_FEED_ENABLED: 'true',
- FLUXER_API_STORAGE_CHANGE_FEED_STREAM: 'storage.changes',
- });
- await expect(loadConfig()).rejects.toThrow('FLUXER_API_STORAGE_CHANGE_FEED_STREAM');
- });
-
- test('rejects invalid Postgres typed environment values', async () => {
- stubMinimalEnv({FLUXER_POSTGRES_PORT: 'abc'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_PORT');
- });
-
- test('rejects a non-boolean Postgres prepared statements value', async () => {
- stubMinimalEnv({FLUXER_POSTGRES_PREPARED_STATEMENTS: 'maybe'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_PREPARED_STATEMENTS');
- });
-
test('reads the profile pseudonym secret and requires it in production', async () => {
stubMinimalEnv();
expect((await loadConfig()).auth.profile_pseudonym_secret).toBe('test-profile-pseudonym-secret');
@@ -400,22 +103,6 @@ describe('ConfigLoader', () => {
await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_HOST');
});
- test('accepts explicitly configured production Postgres with TLS', async () => {
- stubMinimalEnv({
- FLUXER_ENV: 'production',
- FLUXER_POSTGRES_HOST: 'postgres.internal',
- FLUXER_POSTGRES_DATABASE: 'fluxer_prod',
- FLUXER_POSTGRES_USERNAME: 'fluxer_app',
- FLUXER_POSTGRES_PASSWORD: 'prod-postgres-secret',
- FLUXER_POSTGRES_SSL: 'true',
- });
-
- const config = await loadConfig();
-
- expect(config.database.postgres.host).toBe('postgres.internal');
- expect(config.database.postgres.ssl).toBe(true);
- });
-
test('allows self-hosted production Postgres without TLS', async () => {
stubMinimalEnv({
FLUXER_ENV: 'production',
@@ -446,188 +133,6 @@ describe('ConfigLoader', () => {
await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_SSL must be true');
});
- test.each([
- ['email', 'email'],
- ['username', 'username'],
- [' Username ', 'username'],
- ])('parses FLUXER_ACCOUNT_IDENTITY=%j', async (raw, expected) => {
- stubMinimalEnv({FLUXER_ACCOUNT_IDENTITY: raw});
- const config = await loadConfig();
- expect(config.instance.account_identity).toBe(expected);
- });
-
- test.each([
- ['none', 'none'],
- [' Random ', 'random'],
- ['', null],
- ])('parses FLUXER_TAG_STYLE=%j', async (raw, expected) => {
- stubMinimalEnv({FLUXER_TAG_STYLE: raw});
- const config = await loadConfig();
- expect(config.instance.tag_style).toBe(expected);
- });
-
- test.each([
- ['implicit', 'implicit'],
- [' StartTLS ', 'starttls'],
- ['opportunistic', 'opportunistic'],
- ['none', 'none'],
- ['', undefined],
- ])('parses FLUXER_EMAIL_SMTP_TLS_MODE=%j', async (raw, expected) => {
- stubMinimalEnv({FLUXER_EMAIL_SMTP_HOST: 'smtp.example.com', FLUXER_EMAIL_SMTP_TLS_MODE: raw});
- const config = await loadConfig();
- expect(config.integrations.email.smtp?.tls_mode).toBe(expected);
- });
-
- test.each(['tls', 'true'])('rejects the SMTP TLS mode %j', async (raw) => {
- stubMinimalEnv({FLUXER_EMAIL_SMTP_TLS_MODE: raw});
- await expect(loadConfig()).rejects.toThrow(
- 'FLUXER_EMAIL_SMTP_TLS_MODE must be implicit, starttls, opportunistic or none',
- );
- });
-
- const emailFallbackEnv = {
- FLUXER_EMAIL_FALLBACK_DOMAINS: ' Gmail.com, googlemail.com ,gmail.com',
- FLUXER_EMAIL_FALLBACK_SMTP_HOST: 'smtp.sendgrid.net',
- FLUXER_EMAIL_FALLBACK_SMTP_USERNAME: 'apikey',
- FLUXER_EMAIL_FALLBACK_SMTP_PASSWORD: 'secret',
- };
-
- test('leaves the email fallback unset by default', async () => {
- stubMinimalEnv();
- const config = await loadConfig();
- expect(config.integrations.email.fallback).toBeUndefined();
- });
-
- test('loads the email fallback with normalized domains and port 587', async () => {
- stubMinimalEnv(emailFallbackEnv);
- const config = await loadConfig();
- expect(config.integrations.email.fallback).toEqual({
- domains: ['gmail.com', 'googlemail.com'],
- smtp: {host: 'smtp.sendgrid.net', port: 587, username: 'apikey', password: 'secret'},
- });
- });
-
- test('loads the email fallback port and TLS mode', async () => {
- stubMinimalEnv({
- ...emailFallbackEnv,
- FLUXER_EMAIL_FALLBACK_SMTP_PORT: '465',
- FLUXER_EMAIL_FALLBACK_SMTP_TLS_MODE: 'implicit',
- });
- const config = await loadConfig();
- expect(config.integrations.email.fallback?.smtp).toMatchObject({port: 465, tls_mode: 'implicit'});
- });
-
- test.each([
- 'FLUXER_EMAIL_FALLBACK_DOMAINS',
- 'FLUXER_EMAIL_FALLBACK_SMTP_HOST',
- 'FLUXER_EMAIL_FALLBACK_SMTP_USERNAME',
- 'FLUXER_EMAIL_FALLBACK_SMTP_PASSWORD',
- ] as const)('rejects an email fallback without %s', async (missing) => {
- stubMinimalEnv({...emailFallbackEnv, [missing]: ''});
- await expect(loadConfig()).rejects.toThrow(`${missing} is required when an email fallback provider is set`);
- });
-
- test('rejects email fallback domains without an SMTP provider', async () => {
- stubMinimalEnv({FLUXER_EMAIL_FALLBACK_DOMAINS: 'gmail.com'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_EMAIL_FALLBACK_SMTP_HOST is required');
- });
-
- test.each(['@gmail.com', '[email protected]', 'gmail', '*.gmail.com', 'gmail.com:25', '-gmail.com', 'gmail..com'])(
- 'rejects the email fallback domain %j',
- async (domain) => {
- stubMinimalEnv({...emailFallbackEnv, FLUXER_EMAIL_FALLBACK_DOMAINS: domain});
- await expect(loadConfig()).rejects.toThrow('FLUXER_EMAIL_FALLBACK_DOMAINS entry');
- },
- );
-
- test('loads * as the email fallback domains', async () => {
- stubMinimalEnv({...emailFallbackEnv, FLUXER_EMAIL_FALLBACK_DOMAINS: ' * '});
- const config = await loadConfig();
- expect(config.integrations.email.fallback?.domains).toEqual(['*']);
- });
-
- test('rejects * mixed with email fallback domains', async () => {
- stubMinimalEnv({...emailFallbackEnv, FLUXER_EMAIL_FALLBACK_DOMAINS: '*,gmail.com'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_EMAIL_FALLBACK_DOMAINS must be either * or a list of domains');
- });
-
- test('loads the email fallback headers', async () => {
- stubMinimalEnv({...emailFallbackEnv, FLUXER_EMAIL_FALLBACK_SMTP_HEADERS: '{"X-Tracking":"{\\"enable\\":0}"}'});
- const config = await loadConfig();
- expect(config.integrations.email.fallback?.smtp.headers).toEqual({'X-Tracking': '{"enable":0}'});
- });
-
- test.each([
- {headers: '["X-Tracking"]', error: 'must be a JSON object'},
- {headers: '{"X-Tracking":{"enable":0}}', error: 'value of X-Tracking must be a string'},
- {headers: '{"X-Tracking":0}', error: 'value of X-Tracking must be a string'},
- {headers: '{"X Tracking":"off"}', error: 'header name "X Tracking" is not a valid header field name'},
- {headers: '{"X-Tracking:":"off"}', error: 'header name "X-Tracking:" is not a valid header field name'},
- {headers: '{"X-Tracking\\r\\nBcc":"off"}', error: 'is not a valid header field name'},
- {headers: '{"X-Tracking":"off\\r\\nBcc: [email protected]"}', error: 'must be printable ASCII without line breaks'},
- {headers: '{"X-Tracking":"off\\n"}', error: 'must be printable ASCII without line breaks'},
- {headers: `{"X-Tracking":"${'a'.repeat(990)}"}`, error: 'must fit on one 998 character line'},
- ...['From', 'to', 'Cc', 'BCC', 'Subject', 'Reply-To', 'Message-ID', 'Date', 'content-type', 'MIME-Version'].map(
- (name) => ({headers: JSON.stringify({[name]: 'x'}), error: `must not set the ${name} header`}),
- ),
- ])('rejects the email fallback headers $headers', async ({headers, error}) => {
- stubMinimalEnv({...emailFallbackEnv, FLUXER_EMAIL_FALLBACK_SMTP_HEADERS: headers});
- await expect(loadConfig()).rejects.toThrow(error);
- });
-
- test('rejects an out of range email fallback port', async () => {
- stubMinimalEnv({...emailFallbackEnv, FLUXER_EMAIL_FALLBACK_SMTP_PORT: '70000'});
- await expect(loadConfig()).rejects.toThrow(
- 'FLUXER_EMAIL_FALLBACK_SMTP_PORT must be an integer between 1 and 65535',
- );
- });
-
- test.each(['sequential', 'zero_first'])('rejects the tag style %j', async (raw) => {
- stubMinimalEnv({FLUXER_TAG_STYLE: raw});
- await expect(loadConfig()).rejects.toThrow('FLUXER_TAG_STYLE must be none or random');
- });
-
- test('rejects an unknown account identity', async () => {
- stubMinimalEnv({FLUXER_ACCOUNT_IDENTITY: 'phone'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_ACCOUNT_IDENTITY must be email or username');
- });
-
- test('loads a valid store catalogue', async () => {
- stubMinimalEnv({
- FLUXER_APP_STORE_ENABLED: 'true',
- FLUXER_APP_STORE_APPS: '[{"bundle_id":"com.fluxer","app_apple_id":1234567890}]',
- FLUXER_APP_STORE_PRODUCTS: '{"com.fluxer.plutonium.monthly":"monthly","com.fluxer.gift.1month":"gift_1_month"}',
- FLUXER_GOOGLE_PLAY_ENABLED: 'true',
- FLUXER_GOOGLE_PLAY_PACKAGES: 'com.fluxer',
- FLUXER_GOOGLE_PLAY_PRODUCTS: '{"plutonium:yearly":"yearly","gift_1_year":"gift_1_year"}',
- FLUXER_STORE_BILLING_SANDBOX_USER_IDS: '1234567890123456',
- });
- const config = await loadConfig();
- expect(config.integrations.app_store.apps).toEqual([{bundle_id: 'com.fluxer', app_apple_id: 1234567890}]);
- expect(config.integrations.google_play.products).toEqual({
- 'plutonium:yearly': 'yearly',
- gift_1_year: 'gift_1_year',
- });
- expect(config.integrations.store_billing.sandbox_user_ids).toEqual(['1234567890123456']);
- });
-
- test('rejects an App Store app without a numeric app_apple_id', async () => {
- for (const apps of [
- '[{"bundle_id":"com.fluxer"}]',
- '[{"bundle_id":"com.fluxer","app_apple_id":"1234567890"}]',
- '[{"bundle_id":"com.fluxer","app_apple_id":0}]',
- ]) {
- resetConfig();
- stubMinimalEnv({FLUXER_APP_STORE_APPS: apps});
- await expect(loadConfig()).rejects.toThrow('FLUXER_APP_STORE_APPS entry 1 must have a numeric app_apple_id');
- }
- });
-
- test('rejects an App Store app without a bundle id', async () => {
- stubMinimalEnv({FLUXER_APP_STORE_APPS: '[{"app_apple_id":1234567890}]'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_APP_STORE_APPS entry 1 must have a bundle_id');
- });
-
test('rejects an App Store product mapped to an unknown slot', async () => {
stubMinimalEnv({FLUXER_APP_STORE_PRODUCTS: '{"com.fluxer.visionary":"visionary"}'});
await expect(loadConfig()).rejects.toThrow(
@@ -652,40 +157,6 @@ describe('ConfigLoader', () => {
);
});
- test('rejects a sandbox user id that is not a snowflake', async () => {
- stubMinimalEnv({FLUXER_STORE_BILLING_SANDBOX_USER_IDS: '123,abc'});
- await expect(loadConfig()).rejects.toThrow(
- 'FLUXER_STORE_BILLING_SANDBOX_USER_IDS must be a comma separated list of user ids',
- );
- });
-
- test('rejects an unknown cache purge adapter', async () => {
- stubMinimalEnv({FLUXER_CACHE_PURGE_ADAPTER: 'varnish'});
- await expect(loadConfig()).rejects.toThrow('Invalid FLUXER_CACHE_PURGE_ADAPTER: varnish');
- });
-
- test('rejects the http cache purge adapter without an endpoint', async () => {
- stubMinimalEnv({FLUXER_CACHE_PURGE_ADAPTER: 'http'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_CACHE_PURGE_HTTP_ENDPOINT is required');
- });
-
- test('rejects the http cache purge adapter without a token', async () => {
- stubMinimalEnv({
- FLUXER_CACHE_PURGE_ADAPTER: 'http',
- FLUXER_CACHE_PURGE_HTTP_ENDPOINT: 'https://purge.internal/purge',
- });
- await expect(loadConfig()).rejects.toThrow('FLUXER_CACHE_PURGE_HTTP_TOKEN is required');
- });
-
- test('rejects a cache purge endpoint that is not an absolute http URL', async () => {
- for (const endpoint of ['/purge', 'purge.internal/purge', 'ftp://purge.internal/purge']) {
- stubMinimalEnv({FLUXER_CACHE_PURGE_ADAPTER: 'http', FLUXER_CACHE_PURGE_HTTP_ENDPOINT: endpoint});
- await expect(loadConfig()).rejects.toThrow(
- 'FLUXER_CACHE_PURGE_HTTP_ENDPOINT must be an absolute http or https URL without credentials',
- );
- }
- });
-
test('rejects a cache purge endpoint that contains credentials', async () => {
stubMinimalEnv({
FLUXER_CACHE_PURGE_ADAPTER: 'http',
@@ -696,20 +167,6 @@ describe('ConfigLoader', () => {
);
});
- test('rejects a cache purge timeout outside 1000 to 10000', async () => {
- for (const timeout of ['999', '10001']) {
- stubMinimalEnv({
- FLUXER_CACHE_PURGE_ADAPTER: 'http',
- FLUXER_CACHE_PURGE_HTTP_ENDPOINT: 'https://purge.internal/purge',
- FLUXER_CACHE_PURGE_HTTP_TOKEN: 'purge-token',
- FLUXER_CACHE_PURGE_HTTP_TIMEOUT_MS: timeout,
- });
- await expect(loadConfig()).rejects.toThrow(
- 'FLUXER_CACHE_PURGE_HTTP_TIMEOUT_MS must be an integer between 1000 and 10000',
- );
- }
- });
-
test('rejects a cache purge token with spaces or control characters without echoing it', async () => {
for (const token of ['secret\nvalue', 'secret\rvalue', 'secret value', 'secret-value\n']) {
stubMinimalEnv({
@@ -723,11 +180,6 @@ describe('ConfigLoader', () => {
}
});
- test('rejects the controller cache purge adapter without an endpoint', async () => {
- stubMinimalEnv({FLUXER_CACHE_PURGE_ADAPTER: 'controller'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_CACHE_PURGE_CONTROLLER_ENDPOINT is required');
- });
-
test('rejects a controller cache purge endpoint that is not https', async () => {
stubMinimalEnv({
FLUXER_CACHE_PURGE_ADAPTER: 'controller',
@@ -739,38 +191,6 @@ describe('ConfigLoader', () => {
);
});
- test('rejects the controller cache purge adapter without a token', async () => {
- stubMinimalEnv({
- FLUXER_CACHE_PURGE_ADAPTER: 'controller',
- FLUXER_CACHE_PURGE_CONTROLLER_ENDPOINT: 'https://controller.test/v1/orgs/a/sites/b/purge',
- });
- await expect(loadConfig()).rejects.toThrow('FLUXER_CACHE_PURGE_CONTROLLER_TOKEN is required');
- });
-
- test('accepts a complete controller cache purge configuration', async () => {
- stubMinimalEnv({
- FLUXER_CACHE_PURGE_ADAPTER: 'controller',
- FLUXER_CACHE_PURGE_CONTROLLER_ENDPOINT: 'https://controller.test/v1/orgs/a/sites/b/purge',
- FLUXER_CACHE_PURGE_CONTROLLER_TOKEN: 'pak_test',
- FLUXER_CACHE_PURGE_CONTROLLER_TIMEOUT_MS: '5000',
- });
- const cachePurge = (await loadConfig()).integrations.cache_purge;
- expect(cachePurge.adapter).toBe('controller');
- expect(cachePurge.controller).toEqual({
- endpoint: 'https://controller.test/v1/orgs/a/sites/b/purge',
- token: 'pak_test',
- timeout_ms: 5000,
- });
- });
-
- test('leaves the cache purge settings unvalidated when the adapter is none', async () => {
- stubMinimalEnv({
- FLUXER_CACHE_PURGE_HTTP_ENDPOINT: 'ftp://purge.internal/purge',
- FLUXER_CACHE_PURGE_HTTP_TIMEOUT_MS: '1',
- });
- expect((await loadConfig()).integrations.cache_purge.adapter).toBe('none');
- });
-
test('rejects a missing upload relay secret', async () => {
stubMinimalEnv();
vi.stubEnv('FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SECRET_BASE64', '');
@@ -797,7 +217,7 @@ describe('ConfigLoader', () => {
FLUXER_VAPID_PRIVATE_KEY: privateKey,
});
await expect(loadConfig()).rejects.toThrow(
- 'FLUXER_VAPID_PUBLIC_KEY must be the base64url 65-byte uncompressed P-256 point',
+ /^FLUXER_VAPID_PUBLIC_KEY must be the base64url 65-byte uncompressed P-256 point\. Run rexctl doctor --fix/u,
);
});
@@ -807,7 +227,9 @@ describe('ConfigLoader', () => {
FLUXER_VAPID_PUBLIC_KEY: publicKey,
FLUXER_VAPID_PRIVATE_KEY: Buffer.alloc(31, 9).toString('base64url'),
});
- await expect(loadConfig()).rejects.toThrow('FLUXER_VAPID_PRIVATE_KEY must be the base64url 32-byte P-256 scalar');
+ await expect(loadConfig()).rejects.toThrow(
+ /^FLUXER_VAPID_PRIVATE_KEY must be the base64url 32-byte P-256 scalar\. Run rexctl doctor --fix/u,
+ );
});
test('rejects a well formed VAPID scalar that does not derive the public point', async () => {
@@ -833,14 +255,6 @@ describe('ConfigLoader', () => {
expect(config.auth.vapid.private_key).toBe(pair.privateKey);
});
- test('inserts the public port into the LiveKit url', async () => {
- stubMinimalEnv({FLUXER_LIVEKIT_URL: 'http://localhost/livekit'});
-
- const config = await loadConfig();
-
- expect(config.integrations.voice.url).toBe('http://localhost:8088/livekit');
- });
-
test('inserts the public port into every other public url the config contains', async () => {
stubMinimalEnv({
FLUXER_S3_PUBLIC_ENDPOINT: 'http://localhost/s3',
@@ -860,45 +274,6 @@ describe('ConfigLoader', () => {
expect(config.instance.branding.icon_url).toBe('http://localhost:8088/icon.png');
expect(config.integrations.voice.internal_url).toBe('http://livekit:7880');
});
-
- test('rejects a public port outside the valid range', async () => {
- stubMinimalEnv({FLUXER_PUBLIC_PORT: '70000'});
- await expect(loadConfig()).rejects.toThrow('FLUXER_PUBLIC_PORT must be an integer between 1 and 65535');
- });
-});
-
-describe('report retention settings', () => {
- beforeEach(() => {
- resetConfig();
- clearFluxerEnv();
- });
-
- afterEach(() => {
- resetConfig();
- vi.unstubAllEnvs();
- });
-
- test('deletes resolved reports for real after 365 days by default', async () => {
- stubMinimalEnv();
- const config = await loadConfig();
- expect(config.report_retention).toEqual({days: 365, dry_run: false});
- });
-
- test('reads the day setting and the dry run switch from the environment', async () => {
- stubMinimalEnv({FLUXER_REPORT_RETENTION_DAYS: ' 730 ', FLUXER_REPORT_RETENTION_DRY_RUN: 'TRUE'});
- const config = await loadConfig();
- expect(config.report_retention).toEqual({days: 730, dry_run: true});
- });
-
- test.each([
- ['FLUXER_REPORT_RETENTION_DAYS', '0', 'FLUXER_REPORT_RETENTION_DAYS must be an integer between 1 and 36500'],
- ['FLUXER_REPORT_RETENTION_DAYS', '36501', 'FLUXER_REPORT_RETENTION_DAYS must be an integer between 1 and 36500'],
- ['FLUXER_REPORT_RETENTION_DAYS', '1.5', 'FLUXER_REPORT_RETENTION_DAYS must be an integer, got "1.5"'],
- ['FLUXER_REPORT_RETENTION_DRY_RUN', '1', 'FLUXER_REPORT_RETENTION_DRY_RUN must be true or false'],
- ])('refuses %s=%j', async (name, value, message) => {
- stubMinimalEnv({[name]: value});
- await expect(loadConfig()).rejects.toThrow(message);
- });
});
describe('FLUXER_PUBLIC_ORIGIN', () => {
diff --git a/packages/config/src/__tests__/EnvironmentOverrides.test.ts b/packages/config/src/__tests__/EnvironmentOverrides.test.ts
index a7aa402e5..6379c93d7 100644
--- a/packages/config/src/__tests__/EnvironmentOverrides.test.ts
+++ b/packages/config/src/__tests__/EnvironmentOverrides.test.ts
@@ -7,32 +7,6 @@ import {buildNamedFluxerEnvOverrides, readEnvValue} from '@fluxer/config/src/con
import {afterAll, describe, expect, test} from 'vitest';
describe('buildNamedFluxerEnvOverrides', () => {
- test('builds canonical split env overrides', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_BASE_DOMAIN: 'canonical.example',
- FLUXER_API_ENDPOINT: 'https://canonical.example/api',
- FLUXER_PASSKEY_ADDITIONAL_ALLOWED_ORIGINS: 'https://a.example, https://b.example',
- FLUXER_S3_FORCE_PATH_STYLE: 'true',
- FLUXER_AUTH_BLUESKY_KEYS: '[{"kid":"key-1","private_key_path":"/etc/fluxer/keys/bluesky.pem"}]',
- FLUXER_STRIPE_PRICE_MONTHLY_USD: 'price_monthly_usd',
- FLUXER_EMAIL_REPLY_TO_EMAIL: '[email protected]',
- });
-
- expect(overrides).toMatchObject({
- domain: {base_domain: 'canonical.example'},
- endpoint_overrides: {api: 'https://canonical.example/api'},
- auth: {
- passkeys: {additional_allowed_origins: ['https://a.example', 'https://b.example']},
- bluesky: {keys: [{kid: 'key-1', private_key_path: '/etc/fluxer/keys/bluesky.pem'}]},
- },
- s3: {force_path_style: true},
- integrations: {
- stripe: {prices: {monthly_usd: 'price_monthly_usd'}},
- email: {reply_to_email: '[email protected]'},
- },
- });
- });
-
test.each(['', ' ', '\t\n'])('treats %j as unset for every value type', (blank) => {
expect(
buildNamedFluxerEnvOverrides({
@@ -53,69 +27,6 @@ describe('buildNamedFluxerEnvOverrides', () => {
).toEqual({});
});
- test('maps the email fallback variables onto the fallback section', () => {
- expect(
- buildNamedFluxerEnvOverrides({
- FLUXER_EMAIL_FALLBACK_DOMAINS: 'gmail.com, googlemail.com',
- FLUXER_EMAIL_FALLBACK_SMTP_HOST: 'smtp.sendgrid.net',
- FLUXER_EMAIL_FALLBACK_SMTP_PORT: '587',
- FLUXER_EMAIL_FALLBACK_SMTP_USERNAME: 'apikey',
- FLUXER_EMAIL_FALLBACK_SMTP_PASSWORD: 'secret',
- FLUXER_EMAIL_FALLBACK_SMTP_TLS_MODE: 'STARTTLS',
- FLUXER_EMAIL_FALLBACK_SMTP_HEADERS: '{"X-Tracking":"off"}',
- }),
- ).toEqual({
- integrations: {
- email: {
- fallback: {
- domains: ['gmail.com', 'googlemail.com'],
- smtp: {
- host: 'smtp.sendgrid.net',
- port: 587,
- username: 'apikey',
- password: 'secret',
- tls_mode: 'starttls',
- headers: {'X-Tracking': 'off'},
- },
- },
- },
- },
- });
- });
-
- test('maps the setup token onto the instance setup section', () => {
- expect(buildNamedFluxerEnvOverrides({FLUXER_SETUP_TOKEN: 'a-setup-token-of-at-least-32-characters'})).toEqual({
- instance: {setup: {token: 'a-setup-token-of-at-least-32-characters'}},
- });
- });
-
- test('a blank canonical name falls through to its alias', () => {
- expect(
- buildNamedFluxerEnvOverrides({
- FLUXER_NATS_URL: '',
- FLUXER_NATS_CORE_URL: 'nats://alias',
- }),
- ).toMatchObject({
- services: {nats: {core_url: 'nats://alias'}},
- });
- });
-
- test('a blank alias is unset too', () => {
- expect(buildNamedFluxerEnvOverrides({FLUXER_NATS_URL: '', FLUXER_NATS_CORE_URL: ' '})).toEqual({});
- });
-
- test('none clears the storage change feed skip list', () => {
- expect(buildNamedFluxerEnvOverrides({FLUXER_API_STORAGE_CHANGE_FEED_SKIP_BUCKETS: ' None '})).toEqual({
- services: {api: {storage_change_feed: {skip_buckets: []}}},
- });
- });
-
- test('rejects a non-integer value for an integer override', () => {
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_API_PORT: '80a'})).toThrow(
- 'FLUXER_API_PORT must be an integer, got "80a"',
- );
- });
-
test('the canonical name wins over its alias regardless of declaration order', () => {
expect(
buildNamedFluxerEnvOverrides({
@@ -130,76 +41,6 @@ describe('buildNamedFluxerEnvOverrides', () => {
});
});
- test('an alias alone still applies', () => {
- expect(
- buildNamedFluxerEnvOverrides({
- FLUXER_MEDIA_PROXY_ENDPOINT: 'http://alias',
- FLUXER_NATS_CORE_URL: 'nats://alias',
- }),
- ).toMatchObject({
- internal: {media_proxy: 'http://alias'},
- services: {nats: {core_url: 'nats://alias'}},
- });
- });
-
- test('maps the peer-to-peer STUN urls onto integrations.voice', () => {
- expect(
- buildNamedFluxerEnvOverrides({
- FLUXER_VOICE_P2P_STUN_URLS: 'stun:stun.example.com:3478, stun:stun2.example.com:3478',
- }),
- ).toEqual({
- integrations: {
- voice: {
- p2p_stun_urls: ['stun:stun.example.com:3478', 'stun:stun2.example.com:3478'],
- },
- },
- });
- });
-
- test('rejects malformed JSON for a JSON-shaped override', () => {
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_LIVEKIT_DEFAULT_REGION: '{bad'})).toThrow(
- 'FLUXER_LIVEKIT_DEFAULT_REGION must be valid JSON',
- );
- });
-
- test('parses the legacy Stripe price map onto integrations.stripe.legacy_prices', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_STRIPE_LEGACY_PRICES:
- '{"monthly_brl":["price_old_monthly_brl","price_older_monthly_brl"],"yearly_brl":["price_old_yearly_brl"],"monthly_try":["price_archived_monthly_try"],"gift_1_month_brl":["price_old_gift_1_month_brl"],"gift_1_year_brl":["price_old_gift_1_year_brl"]}',
- });
-
- expect(overrides).toMatchObject({
- integrations: {
- stripe: {
- legacy_prices: {
- monthly_brl: ['price_old_monthly_brl', 'price_older_monthly_brl'],
- yearly_brl: ['price_old_yearly_brl'],
- monthly_try: ['price_archived_monthly_try'],
- gift_1_month_brl: ['price_old_gift_1_month_brl'],
- gift_1_year_brl: ['price_old_gift_1_year_brl'],
- },
- },
- },
- });
- });
-
- test('the legacy Stripe price map does not disturb the live price map', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_STRIPE_PRICES: '{"monthly_brl":"price_new_monthly_brl"}',
- FLUXER_STRIPE_LEGACY_PRICES: '{"monthly_brl":["price_old_monthly_brl"]}',
- });
-
- const stripe = (overrides.integrations as {stripe: Record<string, unknown>}).stripe;
- expect(stripe.prices).toEqual({monthly_brl: 'price_new_monthly_brl'});
- expect(stripe.legacy_prices).toEqual({monthly_brl: ['price_old_monthly_brl']});
- });
-
- test('rejects malformed JSON for the legacy Stripe price map', () => {
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_STRIPE_LEGACY_PRICES: '{"monthly_brl":['})).toThrow(
- 'FLUXER_STRIPE_LEGACY_PRICES must be valid JSON',
- );
- });
-
test('an individual Stripe price env var wins over the blob, and the blob keys it does not name survive', () => {
// The deploy runbook flips one slot at a time with FLUXER_STRIPE_PRICE_* while the blob stays
// pinned to the previous release. The individual variable is declared after the blob, so it is
@@ -231,123 +72,6 @@ describe('buildNamedFluxerEnvOverrides', () => {
monthly_eur: 'price_individual_monthly_eur',
});
});
-
- test('maps the four ISK Stripe price variables', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_STRIPE_PRICE_MONTHLY_ISK: 'price_monthly_isk',
- FLUXER_STRIPE_PRICE_YEARLY_ISK: 'price_yearly_isk',
- FLUXER_STRIPE_PRICE_GIFT_1_MONTH_ISK: 'price_gift_1_month_isk',
- FLUXER_STRIPE_PRICE_GIFT_1_YEAR_ISK: 'price_gift_1_year_isk',
- });
-
- expect((overrides.integrations as {stripe: {prices: unknown}}).stripe.prices).toEqual({
- monthly_isk: 'price_monthly_isk',
- yearly_isk: 'price_yearly_isk',
- gift_1_month_isk: 'price_gift_1_month_isk',
- gift_1_year_isk: 'price_gift_1_year_isk',
- });
- });
-
- test('the Stripe price blob applies on its own when no individual price var is set', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_STRIPE_PRICES: '{"monthly_brl":"price_blob_monthly_brl","yearly_brl":"price_blob_yearly_brl"}',
- });
-
- expect((overrides.integrations as {stripe: {prices: unknown}}).stripe.prices).toEqual({
- monthly_brl: 'price_blob_monthly_brl',
- yearly_brl: 'price_blob_yearly_brl',
- });
- });
-
- test('maps the App Store variables onto integrations.app_store', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_APP_STORE_ENABLED: 'true',
- FLUXER_APP_STORE_ISSUER_ID: 'issuer-1',
- FLUXER_APP_STORE_KEY_ID: 'KEY123',
- FLUXER_APP_STORE_PRIVATE_KEY: '-----BEGIN PRIVATE KEY-----\\nabc\\n-----END PRIVATE KEY-----',
- FLUXER_APP_STORE_PRIVATE_KEY_PATH: '/etc/fluxer/keys/app-store.p8',
- FLUXER_APP_STORE_APPS: '[{"bundle_id":"com.fluxer","app_apple_id":1234567890}]',
- FLUXER_APP_STORE_PRODUCTS: '{"com.fluxer.plutonium.monthly":"monthly","com.fluxer.gift.1year":"gift_1_year"}',
- });
-
- expect(overrides).toEqual({
- integrations: {
- app_store: {
- enabled: true,
- issuer_id: 'issuer-1',
- key_id: 'KEY123',
- private_key: '-----BEGIN PRIVATE KEY-----\\nabc\\n-----END PRIVATE KEY-----',
- private_key_path: '/etc/fluxer/keys/app-store.p8',
- apps: [{bundle_id: 'com.fluxer', app_apple_id: 1234567890}],
- products: {'com.fluxer.plutonium.monthly': 'monthly', 'com.fluxer.gift.1year': 'gift_1_year'},
- },
- },
- });
- });
-
- test('maps the Google Play variables onto integrations.google_play', () => {
- const overrides = buildNamedFluxerEnvOverrides({
- FLUXER_GOOGLE_PLAY_ENABLED: 'true',
- FLUXER_GOOGLE_PLAY_PACKAGES: 'com.fluxer, com.fluxer.canary',
- FLUXER_GOOGLE_PLAY_CLIENT_EMAIL: '[email protected]',
- FLUXER_GOOGLE_PLAY_PRIVATE_KEY: 'pem',
- FLUXER_GOOGLE_PLAY_PRIVATE_KEY_PATH: '/etc/fluxer/keys/play.pem',
- FLUXER_GOOGLE_PLAY_SERVICE_ACCOUNT_JSON_PATH: '/etc/fluxer/keys/play.json',
- FLUXER_GOOGLE_PLAY_TOKEN_URI: 'https://oauth2.example/token',
- FLUXER_GOOGLE_PLAY_PRODUCTS: '{"plutonium:monthly":"monthly","gift_1_month":"gift_1_month"}',
- FLUXER_GOOGLE_PLAY_PUSH_AUDIENCE: 'https://api.fluxer.app/webhooks/google-play',
- FLUXER_GOOGLE_PLAY_PUSH_SERVICE_ACCOUNT_EMAIL: '[email protected]',
- });
-
- expect(overrides).toEqual({
- integrations: {
- google_play: {
- enabled: true,
- packages: ['com.fluxer', 'com.fluxer.canary'],
- client_email: '[email protected]',
- private_key: 'pem',
- private_key_path: '/etc/fluxer/keys/play.pem',
- service_account_json_path: '/etc/fluxer/keys/play.json',
- token_uri: 'https://oauth2.example/token',
- products: {'plutonium:monthly': 'monthly', gift_1_month: 'gift_1_month'},
- push_audience: 'https://api.fluxer.app/webhooks/google-play',
- push_service_account_email: '[email protected]',
- },
- },
- });
- });
-
- test('maps the store billing sandbox variables onto integrations.store_billing', () => {
- expect(
- buildNamedFluxerEnvOverrides({
- FLUXER_STORE_BILLING_SANDBOX_USER_IDS: '1234, 5678',
- FLUXER_STORE_BILLING_SANDBOX_ENTITLES_ALL: 'true',
- }),
- ).toEqual({
- integrations: {store_billing: {sandbox_user_ids: ['1234', '5678'], sandbox_entitles_all: true}},
- });
- });
-
- test('rejects a store enabled flag that is not a boolean', () => {
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_APP_STORE_ENABLED: 'yes'})).toThrow(
- 'FLUXER_APP_STORE_ENABLED must be true or false',
- );
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_GOOGLE_PLAY_ENABLED: '1'})).toThrow(
- 'FLUXER_GOOGLE_PLAY_ENABLED must be true or false',
- );
- });
-
- test('rejects a store app list or product map with the wrong JSON shape', () => {
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_APP_STORE_APPS: '{"bundle_id":"com.fluxer"}'})).toThrow(
- 'FLUXER_APP_STORE_APPS must be a JSON array',
- );
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_APP_STORE_PRODUCTS: '["monthly"]'})).toThrow(
- 'FLUXER_APP_STORE_PRODUCTS must be a JSON object',
- );
- expect(() => buildNamedFluxerEnvOverrides({FLUXER_GOOGLE_PLAY_PRODUCTS: '{bad'})).toThrow(
- 'FLUXER_GOOGLE_PLAY_PRODUCTS must be valid JSON',
- );
- });
});
describe('readEnvValue with NAME_FILE', () => {