mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
fix(self-hosting): use instance contacts and live product name (#3333)
This commit is contained in:
1 parent
454fefdb92
commit
a5c1362f4a
308 files changed
+16533
-13512
No files matched your search
@@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {getConfig} from '@app/api/Config';
|
||||
import {resolveContactEmails} from '@app/api/instance/ContactEmails';
|
||||
import {afterEach, describe, expect, it} from 'vitest';
|
||||
|
||||
describe('resolveContactEmails', () => {
|
||||
const originalSelfHosted = getConfig().instance.selfHosted;
|
||||
|
||||
afterEach(() => {
|
||||
getConfig().instance.selfHosted = originalSelfHosted;
|
||||
});
|
||||
|
||||
it('gives a hosted instance the hosted mailboxes', () => {
|
||||
getConfig().instance.selfHosted = false;
|
||||
expect(resolveContactEmails()).toEqual({
|
||||
appealsEmail: '[email protected]',
|
||||
safetyEmail: '[email protected]',
|
||||
supportEmail: '[email protected]',
|
||||
});
|
||||
});
|
||||
|
||||
it('gives a self-hosted instance no mailbox at all', () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
expect(resolveContactEmails()).toEqual({appealsEmail: null, safetyEmail: null, supportEmail: null});
|
||||
});
|
||||
|
||||
it('follows the instance switch on every call', () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
expect(resolveContactEmails().supportEmail).toBeNull();
|
||||
getConfig().instance.selfHosted = false;
|
||||
expect(resolveContactEmails().supportEmail).toBe('[email protected]');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {Config} from '@app/api/Config';
|
||||
|
||||
export interface ContactEmails {
|
||||
appealsEmail: string | null;
|
||||
safetyEmail: string | null;
|
||||
supportEmail: string | null;
|
||||
}
|
||||
|
||||
const HOSTED_CONTACT_EMAILS: ContactEmails = {
|
||||
appealsEmail: '[email protected]',
|
||||
safetyEmail: '[email protected]',
|
||||
supportEmail: '[email protected]',
|
||||
};
|
||||
|
||||
const SELF_HOSTED_CONTACT_EMAILS: ContactEmails = {
|
||||
appealsEmail: null,
|
||||
safetyEmail: null,
|
||||
supportEmail: null,
|
||||
};
|
||||
|
||||
export function resolveContactEmails(): ContactEmails {
|
||||
return Config.instance.selfHosted ? SELF_HOSTED_CONTACT_EMAILS : HOSTED_CONTACT_EMAILS;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
import {spawnSync} from 'node:child_process';
|
||||
import {createHash} from 'node:crypto';
|
||||
import {createServer} from 'node:net';
|
||||
import {Config} from '@app/api/Config';
|
||||
import {Config, getConfig} from '@app/api/Config';
|
||||
import type {CassandraQueryExecutorForTesting} from '@app/api/database/CassandraQueryExecution';
|
||||
import {setCassandraQueryExecutorForTesting} from '@app/api/database/CassandraQueryExecution';
|
||||
import type {PreparedQuery} from '@app/api/database/CassandraTypes';
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
InstanceConfigWriteConflictError,
|
||||
type InstanceRegistrationConfig,
|
||||
} from '@app/api/instance/InstanceConfigRepository';
|
||||
import {getLegalUrls, setCachedConfiguredLegalUrls} from '@app/api/instance/LegalUrls';
|
||||
import {getInstanceProductName, setCachedProductName} from '@app/api/instance/ProductName';
|
||||
import {InstanceConfigWriteRaceExecutor} from '@app/api/instance/tests/InstanceConfigWriteRaceExecutor';
|
||||
import {startDockerContainer} from '@app/api/test/DockerTestContainer';
|
||||
import {InMemoryCassandraQueryExecutor} from '@app/api/test/InMemoryCassandraQueryExecutor';
|
||||
@@ -272,6 +274,90 @@ describe('InstanceConfigRepository', () => {
|
||||
expect(config.branding.icon_url).toBe('https://other.example/branding/0/89abcdef.png');
|
||||
});
|
||||
|
||||
it('round-trips the community guidelines URL and clears a blank one', async () => {
|
||||
setCassandraQueryExecutorForTesting(new CountingInMemoryCassandraQueryExecutor());
|
||||
const repository = createRepository(new MockKVProvider());
|
||||
const originalSelfHosted = getConfig().instance.selfHosted;
|
||||
getConfig().instance.selfHosted = true;
|
||||
try {
|
||||
expect((await repository.getAppPublicConfig()).legal).toEqual({
|
||||
terms_url: null,
|
||||
privacy_url: null,
|
||||
guidelines_url: null,
|
||||
});
|
||||
const saved = await repository.setAppPublicConfig({
|
||||
legal: {terms_url: 'https://example.org/tos', guidelines_url: ' https://example.org/rules '},
|
||||
});
|
||||
expect(saved.legal).toEqual({
|
||||
terms_url: 'https://example.org/tos',
|
||||
privacy_url: null,
|
||||
guidelines_url: 'https://example.org/rules',
|
||||
});
|
||||
expect((await repository.getAppPublicConfig()).legal.guidelines_url).toBe('https://example.org/rules');
|
||||
expect(getLegalUrls()).toEqual({termsUrl: 'https://example.org/tos', guidelinesUrl: 'https://example.org/rules'});
|
||||
await repository.setAppPublicConfig({legal: {privacy_url: 'https://example.org/privacy'}});
|
||||
expect((await repository.getAppPublicConfig()).legal.guidelines_url).toBe('https://example.org/rules');
|
||||
await repository.setAppPublicConfig({legal: {guidelines_url: ' '}});
|
||||
expect((await repository.getAppPublicConfig()).legal.guidelines_url).toBeNull();
|
||||
expect(getLegalUrls()).toEqual({termsUrl: 'https://example.org/tos', guidelinesUrl: null});
|
||||
} finally {
|
||||
getConfig().instance.selfHosted = originalSelfHosted;
|
||||
setCachedConfiguredLegalUrls({terms_url: null, guidelines_url: null});
|
||||
}
|
||||
});
|
||||
|
||||
it('loads the stored guidelines URL into the legal URL cache on initialize', async () => {
|
||||
setCassandraQueryExecutorForTesting(new CountingInMemoryCassandraQueryExecutor());
|
||||
const kvProvider = new MockKVProvider();
|
||||
const originalSelfHosted = getConfig().instance.selfHosted;
|
||||
getConfig().instance.selfHosted = true;
|
||||
try {
|
||||
await createRepository(kvProvider).setConfig(
|
||||
APP_PUBLIC_CONFIG_KEY,
|
||||
JSON.stringify({legal: {terms_url: null, privacy_url: null, guidelines_url: 'https://example.org/rules'}}),
|
||||
);
|
||||
setCachedConfiguredLegalUrls({terms_url: null, guidelines_url: null});
|
||||
expect(getLegalUrls().guidelinesUrl).toBeNull();
|
||||
await createRepository(kvProvider).initialize();
|
||||
expect(getLegalUrls().guidelinesUrl).toBe('https://example.org/rules');
|
||||
} finally {
|
||||
getConfig().instance.selfHosted = originalSelfHosted;
|
||||
setCachedConfiguredLegalUrls({terms_url: null, guidelines_url: null});
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps the product name cache in step with the stored branding', async () => {
|
||||
setCassandraQueryExecutorForTesting(new CountingInMemoryCassandraQueryExecutor());
|
||||
const kvProvider = new MockKVProvider();
|
||||
try {
|
||||
await createRepository(kvProvider).setConfig(
|
||||
APP_PUBLIC_CONFIG_KEY,
|
||||
JSON.stringify({branding: {product_name: 'Example Chat'}}),
|
||||
);
|
||||
setCachedProductName(null);
|
||||
await createRepository(kvProvider).initialize();
|
||||
expect(getInstanceProductName()).toBe('Example Chat');
|
||||
await createRepository(kvProvider).setAppPublicConfig({branding: {product_name: 'Renamed Chat'}});
|
||||
expect(getInstanceProductName()).toBe('Renamed Chat');
|
||||
} finally {
|
||||
setCachedProductName(null);
|
||||
}
|
||||
});
|
||||
|
||||
it('reads a stored legal config written before the guidelines URL existed', async () => {
|
||||
setCassandraQueryExecutorForTesting(new CountingInMemoryCassandraQueryExecutor());
|
||||
const repository = createRepository(new MockKVProvider());
|
||||
await repository.setConfig(
|
||||
APP_PUBLIC_CONFIG_KEY,
|
||||
JSON.stringify({legal: {terms_url: 'https://example.org/tos', privacy_url: null}}),
|
||||
);
|
||||
expect((await repository.getAppPublicConfig()).legal).toEqual({
|
||||
terms_url: 'https://example.org/tos',
|
||||
privacy_url: null,
|
||||
guidelines_url: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps valid stored instance policy flags when one field is invalid', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
|
||||
@@ -29,6 +29,8 @@ import {
|
||||
setCachedDateOfBirthCollection,
|
||||
} from '@app/api/instance/DateOfBirthCollectionCache';
|
||||
import {InstanceConfigCache} from '@app/api/instance/InstanceConfigCache';
|
||||
import {setCachedConfiguredLegalUrls} from '@app/api/instance/LegalUrls';
|
||||
import {getDefaultProductName, setCachedProductName} from '@app/api/instance/ProductName';
|
||||
import {normalizeSsoAllowedEmailDomains} from '@app/api/instance/SsoConfigValidation';
|
||||
import {Logger} from '@app/api/Logger';
|
||||
import {isLimitConfigSnapshot} from '@app/api/limits/LimitConfigValidation';
|
||||
@@ -409,7 +411,7 @@ export function getDefaultPremiumProductName(): string {
|
||||
function getDefaultAppPublicConfig(): InstanceAppPublicConfig {
|
||||
return {
|
||||
branding: {
|
||||
product_name: Config.instance.branding.productName || 'Fluxer',
|
||||
product_name: getDefaultProductName(),
|
||||
icon_url: normalizeOptionalString(Config.instance.branding.iconUrl),
|
||||
symbol_url: normalizeOptionalString(Config.instance.branding.symbolUrl),
|
||||
logo_url: normalizeOptionalString(Config.instance.branding.logoUrl),
|
||||
@@ -427,6 +429,7 @@ function getDefaultAppPublicConfig(): InstanceAppPublicConfig {
|
||||
legal: {
|
||||
terms_url: null,
|
||||
privacy_url: null,
|
||||
guidelines_url: null,
|
||||
},
|
||||
registration: {
|
||||
collect_date_of_birth: getDefaultDateOfBirthCollection(),
|
||||
@@ -742,6 +745,7 @@ function buildAppPublicConfig(config: z.infer<typeof StoredInstanceAppPublicSche
|
||||
legal: {
|
||||
terms_url: normalizeOptionalPublicString(legal.terms_url, defaults.legal.terms_url),
|
||||
privacy_url: normalizeOptionalPublicString(legal.privacy_url, defaults.legal.privacy_url),
|
||||
guidelines_url: normalizeOptionalPublicString(legal.guidelines_url, defaults.legal.guidelines_url),
|
||||
},
|
||||
registration: {
|
||||
collect_date_of_birth: registration.collect_date_of_birth ?? defaults.registration.collect_date_of_birth,
|
||||
@@ -1378,6 +1382,8 @@ export class InstanceConfigRepository {
|
||||
setStoredBillingConfig(parseStoredInstanceBillingConfig(snapshot.get(INSTANCE_BILLING_CONFIG_KEY) ?? null));
|
||||
const appPublic = parseStoredAppPublicConfig(snapshot.get(APP_PUBLIC_CONFIG_KEY) ?? null);
|
||||
setCachedDateOfBirthCollection(appPublic.registration.collect_date_of_birth);
|
||||
setCachedConfiguredLegalUrls(appPublic.legal);
|
||||
setCachedProductName(appPublic.branding.product_name);
|
||||
setCachedAccountIdentity(readStoredAccountIdentity(snapshot.get(ACCOUNT_IDENTITY_CONFIG_KEY) ?? null));
|
||||
}
|
||||
|
||||
@@ -1659,6 +1665,8 @@ export class InstanceConfigRepository {
|
||||
const raw = await this.getConfig(APP_PUBLIC_CONFIG_KEY);
|
||||
const config = parseStoredAppPublicConfig(raw);
|
||||
setCachedDateOfBirthCollection(config.registration.collect_date_of_birth);
|
||||
setCachedConfiguredLegalUrls(config.legal);
|
||||
setCachedProductName(config.branding.product_name);
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1707,6 +1715,8 @@ export class InstanceConfigRepository {
|
||||
});
|
||||
await this.publishRefresh(cache.sourceId);
|
||||
setCachedDateOfBirthCollection(next.registration.collect_date_of_birth);
|
||||
setCachedConfiguredLegalUrls(next.legal);
|
||||
setCachedProductName(next.branding.product_name);
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {getConfig} from '@app/api/Config';
|
||||
import {getLegalUrls, resolveLegalUrls, setCachedConfiguredLegalUrls} from '@app/api/instance/LegalUrls';
|
||||
import {afterEach, describe, expect, it} from 'vitest';
|
||||
|
||||
const UNSET = {terms_url: null, guidelines_url: null};
|
||||
const CONFIGURED = {terms_url: 'https://example.org/tos', guidelines_url: 'https://example.org/rules'};
|
||||
|
||||
describe('resolveLegalUrls', () => {
|
||||
const originalSelfHosted = getConfig().instance.selfHosted;
|
||||
|
||||
afterEach(() => {
|
||||
getConfig().instance.selfHosted = originalSelfHosted;
|
||||
setCachedConfiguredLegalUrls(UNSET);
|
||||
});
|
||||
|
||||
it('points a hosted instance at the marketing pages by default', () => {
|
||||
getConfig().instance.selfHosted = false;
|
||||
const marketing = getConfig().endpoints.marketing;
|
||||
expect(resolveLegalUrls(UNSET)).toEqual({
|
||||
termsUrl: `${marketing}/terms`,
|
||||
guidelinesUrl: `${marketing}/guidelines`,
|
||||
});
|
||||
});
|
||||
|
||||
it('lets a hosted instance override each page', () => {
|
||||
getConfig().instance.selfHosted = false;
|
||||
expect(resolveLegalUrls(CONFIGURED)).toEqual({
|
||||
termsUrl: 'https://example.org/tos',
|
||||
guidelinesUrl: 'https://example.org/rules',
|
||||
});
|
||||
expect(resolveLegalUrls({terms_url: null, guidelines_url: 'https://example.org/rules'}).termsUrl).toBe(
|
||||
`${getConfig().endpoints.marketing}/terms`,
|
||||
);
|
||||
});
|
||||
|
||||
it('gives a self-hosted instance no links until they are configured', () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
expect(resolveLegalUrls(UNSET)).toEqual({termsUrl: null, guidelinesUrl: null});
|
||||
expect(resolveLegalUrls({terms_url: null, guidelines_url: 'https://example.org/rules'})).toEqual({
|
||||
termsUrl: null,
|
||||
guidelinesUrl: 'https://example.org/rules',
|
||||
});
|
||||
expect(resolveLegalUrls(CONFIGURED)).toEqual({
|
||||
termsUrl: 'https://example.org/tos',
|
||||
guidelinesUrl: 'https://example.org/rules',
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves the cached instance config', () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
expect(getLegalUrls()).toEqual({termsUrl: null, guidelinesUrl: null});
|
||||
setCachedConfiguredLegalUrls(CONFIGURED);
|
||||
expect(getLegalUrls()).toEqual({termsUrl: 'https://example.org/tos', guidelinesUrl: 'https://example.org/rules'});
|
||||
getConfig().instance.selfHosted = false;
|
||||
expect(getLegalUrls()).toEqual({termsUrl: 'https://example.org/tos', guidelinesUrl: 'https://example.org/rules'});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {Config} from '@app/api/Config';
|
||||
|
||||
export interface ConfiguredLegalUrls {
|
||||
terms_url: string | null;
|
||||
guidelines_url: string | null;
|
||||
}
|
||||
|
||||
export interface LegalUrls {
|
||||
termsUrl: string | null;
|
||||
guidelinesUrl: string | null;
|
||||
}
|
||||
|
||||
let cachedConfiguredLegalUrls: ConfiguredLegalUrls = {terms_url: null, guidelines_url: null};
|
||||
|
||||
export function setCachedConfiguredLegalUrls(legal: ConfiguredLegalUrls): void {
|
||||
cachedConfiguredLegalUrls = {terms_url: legal.terms_url, guidelines_url: legal.guidelines_url};
|
||||
}
|
||||
|
||||
export function resolveLegalUrls(legal: ConfiguredLegalUrls): LegalUrls {
|
||||
const hostedUrl = (path: string): string | null =>
|
||||
Config.instance.selfHosted ? null : `${Config.endpoints.marketing}${path}`;
|
||||
return {
|
||||
termsUrl: legal.terms_url ?? hostedUrl('/terms'),
|
||||
guidelinesUrl: legal.guidelines_url ?? hostedUrl('/guidelines'),
|
||||
};
|
||||
}
|
||||
|
||||
export function getLegalUrls(): LegalUrls {
|
||||
return resolveLegalUrls(cachedConfiguredLegalUrls);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {getConfig} from '@app/api/Config';
|
||||
import {getDefaultProductName, getInstanceProductName, setCachedProductName} from '@app/api/instance/ProductName';
|
||||
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
||||
|
||||
describe('getInstanceProductName', () => {
|
||||
const originalProductName = getConfig().instance.branding.productName;
|
||||
|
||||
beforeEach(() => {
|
||||
setCachedProductName(null);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
getConfig().instance.branding.productName = originalProductName;
|
||||
setCachedProductName(null);
|
||||
});
|
||||
|
||||
it('uses the configured name until a stored name is known', () => {
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
expect(getDefaultProductName()).toBe('Configured Chat');
|
||||
expect(getInstanceProductName()).toBe('Configured Chat');
|
||||
});
|
||||
|
||||
it('falls back to Fluxer when no name is configured', () => {
|
||||
getConfig().instance.branding.productName = '';
|
||||
expect(getInstanceProductName()).toBe('Fluxer');
|
||||
});
|
||||
|
||||
it('prefers the stored name', () => {
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
setCachedProductName('Example Chat');
|
||||
expect(getInstanceProductName()).toBe('Example Chat');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {Config} from '@app/api/Config';
|
||||
|
||||
let cachedProductName: string | null = null;
|
||||
|
||||
export function getDefaultProductName(): string {
|
||||
return Config.instance.branding.productName || 'Fluxer';
|
||||
}
|
||||
|
||||
export function getInstanceProductName(): string {
|
||||
return cachedProductName ?? getDefaultProductName();
|
||||
}
|
||||
|
||||
export function setCachedProductName(productName: string | null): void {
|
||||
cachedProductName = productName;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {createApplicationID} from '@app/api/BrandedTypes';
|
||||
import {getConfig} from '@app/api/Config';
|
||||
import {setCachedProductName} from '@app/api/instance/ProductName';
|
||||
import {createRuntimeEmailService, getInstanceConfigRepository} from '@app/api/middleware/ServiceSingletons';
|
||||
import {ApplicationRepository, resetAdminSecretHashForTesting} from '@app/api/oauth/repositories/ApplicationRepository';
|
||||
import {ApnsPushServiceTestHooks} from '@app/api/push/ApnsPushService';
|
||||
import type {ApiTestHarness} from '@app/api/test/ApiTestHarness';
|
||||
import {createApiTestHarness} from '@app/api/test/ApiTestHarness';
|
||||
import {ADMIN_OAUTH2_APPLICATION_ID} from '@fluxer/constants/src/Core';
|
||||
import {EmailI18nService} from '@pkgs/email/src/EmailI18nService';
|
||||
import type {IEmailService} from '@pkgs/email/src/IEmailService';
|
||||
import {SmtpEmailProvider} from '@pkgs/email/src/SmtpEmailProvider';
|
||||
import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
describe('instance product name in server-rendered text', () => {
|
||||
let harness: ApiTestHarness;
|
||||
const original = {
|
||||
productName: getConfig().instance.branding.productName,
|
||||
selfHosted: getConfig().instance.selfHosted,
|
||||
adminSecret: getConfig().admin.oauthClientSecret,
|
||||
emailEnabled: getConfig().email.enabled,
|
||||
emailFromName: getConfig().email.fromName,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
harness = await createApiTestHarness();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await harness.reset();
|
||||
getInstanceConfigRepository().clearCacheForTesting();
|
||||
setCachedProductName(null);
|
||||
getConfig().email.enabled = false;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
getConfig().instance.branding.productName = original.productName;
|
||||
getConfig().instance.selfHosted = original.selfHosted;
|
||||
getConfig().admin.oauthClientSecret = original.adminSecret;
|
||||
getConfig().email.enabled = original.emailEnabled;
|
||||
getConfig().email.fromName = original.emailFromName;
|
||||
resetAdminSecretHashForTesting();
|
||||
setCachedProductName(null);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await harness.shutdown();
|
||||
});
|
||||
|
||||
function createRecordedEmailService(): {service: IEmailService; subjects: Array<string>; names: Array<string>} {
|
||||
const subjects: Array<string> = [];
|
||||
const names: Array<string> = [];
|
||||
const getTemplate = EmailI18nService.prototype.getTemplate;
|
||||
vi.spyOn(EmailI18nService.prototype, 'getTemplate').mockImplementation(function (
|
||||
this: EmailI18nService,
|
||||
key,
|
||||
locale,
|
||||
variables,
|
||||
productName,
|
||||
) {
|
||||
const result = getTemplate.call(this, key, locale, variables, productName);
|
||||
names.push(productName);
|
||||
if (result.ok) subjects.push(result.value.subject);
|
||||
return result;
|
||||
});
|
||||
return {service: createRuntimeEmailService({isEmailBounced: async () => false}), subjects, names};
|
||||
}
|
||||
|
||||
it('sends hosted emails as Fluxer', async () => {
|
||||
getConfig().instance.branding.productName = '';
|
||||
const {service, subjects, names} = createRecordedEmailService();
|
||||
await expect(service.sendPasswordResetEmail('[email protected]', 'testuser', 'token', 'en-US')).resolves.toBe(true);
|
||||
expect(names).toEqual(['Fluxer']);
|
||||
expect(subjects).toEqual(['Reset your Fluxer password']);
|
||||
});
|
||||
|
||||
it('sends self-hosted emails under the configured name', async () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
const {service, subjects} = createRecordedEmailService();
|
||||
await service.sendPasswordResetEmail('[email protected]', 'testuser', 'token', 'en-US');
|
||||
await service.sendEmailVerification('[email protected]', 'testuser', 'token', 'de');
|
||||
expect(subjects[0]).toBe('Reset your Configured Chat password');
|
||||
expect(subjects[1]).toContain('Configured Chat');
|
||||
expect(subjects.join('\n')).not.toContain('Fluxer');
|
||||
});
|
||||
|
||||
it('picks up a name saved in the dashboard on the next email without a restart', async () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
const {service, subjects} = createRecordedEmailService();
|
||||
await service.sendPasswordResetEmail('[email protected]', 'testuser', 'token', 'en-US');
|
||||
await getInstanceConfigRepository().setAppPublicConfig({branding: {product_name: 'Renamed Chat'}});
|
||||
await service.sendPasswordResetEmail('[email protected]', 'testuser', 'token', 'en-US');
|
||||
setCachedProductName(null);
|
||||
await service.sendPasswordResetEmail('[email protected]', 'testuser', 'token', 'en-US');
|
||||
expect(subjects).toEqual([
|
||||
'Reset your Configured Chat password',
|
||||
'Reset your Renamed Chat password',
|
||||
'Reset your Renamed Chat password',
|
||||
]);
|
||||
});
|
||||
|
||||
async function sendAndReadSenderName(): Promise<string | undefined> {
|
||||
getConfig().email.enabled = true;
|
||||
const sendEmail = vi.spyOn(SmtpEmailProvider.prototype, 'sendEmail').mockResolvedValue(true);
|
||||
const service = createRuntimeEmailService({isEmailBounced: async () => false});
|
||||
await expect(service.sendPasswordResetEmail('[email protected]', 'testuser', 'token', 'en-US')).resolves.toBe(true);
|
||||
return sendEmail.mock.calls.at(-1)?.[0].from.name;
|
||||
}
|
||||
|
||||
it('sends hosted emails from Fluxer when no sender name is set', async () => {
|
||||
getConfig().instance.branding.productName = '';
|
||||
getConfig().email.fromName = '';
|
||||
await expect(sendAndReadSenderName()).resolves.toBe('Fluxer');
|
||||
});
|
||||
|
||||
it('sends self-hosted emails from the product name when no sender name is set', async () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
getConfig().email.fromName = '';
|
||||
await expect(sendAndReadSenderName()).resolves.toBe('Configured Chat');
|
||||
await getInstanceConfigRepository().setAppPublicConfig({branding: {product_name: 'Renamed Chat'}});
|
||||
await expect(sendAndReadSenderName()).resolves.toBe('Renamed Chat');
|
||||
});
|
||||
|
||||
it('keeps a configured sender name over the product name', async () => {
|
||||
getConfig().instance.selfHosted = true;
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
getConfig().email.fromName = 'Configured Mailer';
|
||||
await expect(sendAndReadSenderName()).resolves.toBe('Configured Mailer');
|
||||
getConfig().instance.selfHosted = false;
|
||||
getConfig().instance.branding.productName = '';
|
||||
await expect(sendAndReadSenderName()).resolves.toBe('Configured Mailer');
|
||||
});
|
||||
|
||||
it('titles an APNs alert that has no title with the instance name', () => {
|
||||
const titleOf = (): unknown => {
|
||||
const {aps} = ApnsPushServiceTestHooks.buildApnsPayload({notification: {body: 'Hello'}});
|
||||
return (aps as {alert: {title: string}}).alert.title;
|
||||
};
|
||||
getConfig().instance.branding.productName = '';
|
||||
expect(titleOf()).toBe('Fluxer');
|
||||
getConfig().instance.branding.productName = 'Configured Chat';
|
||||
expect(titleOf()).toBe('Configured Chat');
|
||||
setCachedProductName('Renamed Chat');
|
||||
expect(titleOf()).toBe('Renamed Chat');
|
||||
});
|
||||
|
||||
it('names the built-in admin application after the instance', async () => {
|
||||
getConfig().admin.oauthClientSecret = 'product-name-test-secret';
|
||||
resetAdminSecretHashForTesting();
|
||||
const repository = new ApplicationRepository();
|
||||
const nameOf = async (): Promise<string | undefined> =>
|
||||
(await repository.getApplication(createApplicationID(ADMIN_OAUTH2_APPLICATION_ID)))?.name;
|
||||
getConfig().instance.branding.productName = '';
|
||||
await expect(nameOf()).resolves.toBe('Fluxer Admin');
|
||||
setCachedProductName('Renamed Chat');
|
||||
await expect(nameOf()).resolves.toBe('Renamed Chat Admin');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user