Skip to content

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

TypeScript fluxerfluxerapp

test(schema): delete schema and validator unit suites

Hampus8933ce2aab9b
diff --git a/packages/schema/src/domains/admin/AdminUserSchemas.test.ts b/packages/schema/src/domains/admin/AdminUserSchemas.test.ts
deleted file mode 100644
index c26b64aa6..000000000
--- a/packages/schema/src/domains/admin/AdminUserSchemas.test.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {AdminACLs} from '@fluxer/constants/src/AdminACLs';
-import {SetUserAclsRequest} from '@fluxer/schema/src/domains/admin/AdminUserSchemas';
-import {describe, expect, test} from 'vitest';
-
-describe('SetUserAclsRequest', () => {
- test('accepts every ACL the instance defines', () => {
- const acls = Object.values(AdminACLs);
- const result = SetUserAclsRequest.safeParse({user_id: '1', acls});
- expect(result.success).toBe(true);
- });
-
- test('rejects an ACL outside the registry', () => {
- const result = SetUserAclsRequest.safeParse({user_id: '1', acls: ['user:veiw']});
- expect(result.success).toBe(false);
- });
-
- test('rejects more entries than there are ACLs', () => {
- const acls = [...Object.values(AdminACLs), 'overflow:one'];
- const result = SetUserAclsRequest.safeParse({user_id: '1', acls});
- expect(result.success).toBe(false);
- });
-});
diff --git a/packages/schema/src/domains/admin/ChannelThreadsSchemas.test.ts b/packages/schema/src/domains/admin/ChannelThreadsSchemas.test.ts
deleted file mode 100644
index 136cd69b2..000000000
--- a/packages/schema/src/domains/admin/ChannelThreadsSchemas.test.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {
- ChannelThreadsAssignmentResponse,
- ChannelThreadsConfigSchema,
- everyoneChannelThreadsConfig,
-} from '@fluxer/schema/src/domains/admin/ChannelThreadsSchemas';
-import {describe, expect, test} from 'vitest';
-
-describe('channel threads configuration', () => {
- test('the everyone config serves every guild and user and keeps the given version', () => {
- const everyone = everyoneChannelThreadsConfig(42);
- expect(everyone).toEqual({
- enabled: true,
- config_version: 42,
- ever_enabled: true,
- guild_basis_points: 10000,
- guild_salt: 'channel-threads-guild-v1',
- enabled_guild_ids: [],
- disabled_guild_ids: [],
- user_basis_points: 10000,
- user_salt: 'channel-threads-user-v1',
- included_user_ids: [],
- excluded_user_ids: [],
- });
- expect(ChannelThreadsConfigSchema.parse(everyone)).toEqual(everyone);
- expect(ChannelThreadsAssignmentResponse.parse({active: true, config_version: everyone.config_version})).toEqual({
- active: true,
- config_version: 42,
- });
- });
-});
diff --git a/packages/schema/src/domains/admin/DomainMigrationSchemas.test.ts b/packages/schema/src/domains/admin/DomainMigrationSchemas.test.ts
index 3d07210f3..0ccc35706 100644
--- a/packages/schema/src/domains/admin/DomainMigrationSchemas.test.ts
+++ b/packages/schema/src/domains/admin/DomainMigrationSchemas.test.ts
@@ -3,7 +3,6 @@
import {
DEFAULT_DOMAIN_MIGRATION_CONFIG,
type DomainMigrationConfig,
- DomainMigrationConfigSchema,
DomainMigrationConfigUpdateRequest,
INERT_DOMAIN_MIGRATION_ASSIGNMENT,
resolveDomainMigrationAssignment,
@@ -45,67 +44,12 @@ function targetedUserIds(config: DomainMigrationConfig, userIds: ReadonlyArray<s
}
describe('domain migration configuration', () => {
- test('derives defaults from the schema with independently owned arrays', () => {
- const first = DomainMigrationConfigSchema.parse({});
- const second = DomainMigrationConfigSchema.parse({});
- expect(first).toEqual(DEFAULT_DOMAIN_MIGRATION_CONFIG);
- first.included_user_ids.push(TARGETED_USER_ID);
- first.excluded_user_ids.push(OTHER_USER_ID);
- expect(second).toEqual(DEFAULT_DOMAIN_MIGRATION_CONFIG);
- });
-
- test('defaults to disabled with an empty rollout', () => {
- expect(DEFAULT_DOMAIN_MIGRATION_CONFIG.enabled).toBe(false);
- expect(DEFAULT_DOMAIN_MIGRATION_CONFIG.rollout_basis_points).toBe(0);
- expect(DEFAULT_DOMAIN_MIGRATION_CONFIG.anonymous_rollout_basis_points).toBe(0);
- expect(DEFAULT_DOMAIN_MIGRATION_CONFIG.rollout_salt).toBe('domain-migration-v1');
- expect(DEFAULT_DOMAIN_MIGRATION_CONFIG.standalone_forwarding).toBe(false);
- });
-
- test('fills standalone forwarding in for configs stored before it existed', () => {
- const stored = DomainMigrationConfigSchema.parse({enabled: true, config_version: 4, rollout_basis_points: 100});
- expect(stored.standalone_forwarding).toBe(false);
- });
-
- test.each([{}, {enabled: false}, {enabled: undefined}, {rollout_basis_points: 2500}, {standalone_forwarding: true}])(
- 'keeps partial updates free of configuration defaults: %j',
- (patch) => {
- expect(DomainMigrationConfigUpdateRequest.parse(patch)).toEqual(patch);
- },
- );
-
test('does not accept a client-provided configuration version', () => {
expect(DomainMigrationConfigUpdateRequest.parse({config_version: 12})).toEqual({});
});
-
- test.each([
- {rollout_basis_points: -1},
- {rollout_basis_points: 10001},
- {anonymous_rollout_basis_points: -1},
- {anonymous_rollout_basis_points: 10001},
- {anonymous_rollout_basis_points: 1.5},
- {rollout_salt: ' '},
- {rollout_salt: 'domain-migration-\u00e9'},
- {included_user_ids: ['not-an-id']},
- {excluded_user_ids: ['not-an-id']},
- {standalone_forwarding: 'yes'},
- ])('applies the same validation to stored configuration and updates: %j', (value) => {
- expect(DomainMigrationConfigSchema.safeParse(value).success).toBe(false);
- expect(DomainMigrationConfigUpdateRequest.safeParse(value).success).toBe(false);
- });
-
- test('rejects more than a thousand targeted user ids', () => {
- const ids = syntheticUserIds(1001);
- expect(DomainMigrationConfigSchema.safeParse({included_user_ids: ids}).success).toBe(false);
- expect(DomainMigrationConfigSchema.safeParse({included_user_ids: ids.slice(0, 1000)}).success).toBe(true);
- });
});
describe('resolveDomainMigrationAssignment', () => {
- test('the inert assignment is disabled', () => {
- expect(INERT_DOMAIN_MIGRATION_ASSIGNMENT.enabled).toBe(false);
- });
-
test('returns the inert assignment when the master switch is off', () => {
const config = createConfig({
enabled: false,
@@ -123,11 +67,6 @@ describe('resolveDomainMigrationAssignment', () => {
);
});
- test('never hands back the shared inert object', () => {
- const assignment = resolveDomainMigrationAssignment(createConfig(), TARGETED_USER_ID, NO_TARGETING);
- expect(assignment).not.toBe(INERT_DOMAIN_MIGRATION_ASSIGNMENT);
- });
-
test('denylist beats allowlist', () => {
const config = createConfig({
enabled: true,
@@ -230,15 +169,6 @@ describe('toDomainMigrationDiscovery', () => {
standalone_forwarding: true,
});
});
-
- test('reports the kill switch for the default config', () => {
- expect(toDomainMigrationDiscovery(DEFAULT_DOMAIN_MIGRATION_CONFIG)).toEqual({
- enabled: false,
- anonymous_rollout_basis_points: 0,
- rollout_salt: 'domain-migration-v1',
- standalone_forwarding: false,
- });
- });
});
describe('resolveDomainMigrationAssignment guild targeting', () => {
diff --git a/packages/schema/src/domains/admin/PushRelaySchemas.test.ts b/packages/schema/src/domains/admin/PushRelaySchemas.test.ts
index 1d072bfdf..83076d1c5 100644
--- a/packages/schema/src/domains/admin/PushRelaySchemas.test.ts
+++ b/packages/schema/src/domains/admin/PushRelaySchemas.test.ts
@@ -9,37 +9,8 @@ import {
import {describe, expect, test} from 'vitest';
const ADMIN_USER_ID = '1500000000000000001';
-const ACCEPTED_AT = '2026-09-27T10:11:12.000Z';
describe('push relay consent', () => {
- test('reads back as unaccepted by default', () => {
- expect(PushRelayConfigSchema.parse({})).toEqual({
- relay_consent_accepted: false,
- relay_consent_accepted_at: null,
- relay_consent_accepted_by: null,
- });
- });
-
- test('a stored push service delivery row keeps its consent', () => {
- expect(
- PushRelayConfigSchema.parse({
- enabled: true,
- config_version: 12,
- rollout_basis_points: 10000,
- rollout_salt: 'push-service-delivery-v1',
- included_user_ids: [],
- excluded_user_ids: ['1500000000000000003'],
- relay_consent_accepted: true,
- relay_consent_accepted_at: ACCEPTED_AT,
- relay_consent_accepted_by: ADMIN_USER_ID,
- }),
- ).toEqual({
- relay_consent_accepted: true,
- relay_consent_accepted_at: ACCEPTED_AT,
- relay_consent_accepted_by: ADMIN_USER_ID,
- });
- });
-
test('a stored row that predates relay consent reads back as not accepted', () => {
expect(
PushRelayConfigSchema.parse({
@@ -57,21 +28,6 @@ describe('push relay consent', () => {
});
});
- test('an accepted consent round-trips', () => {
- const accepted = {
- relay_consent_accepted: true,
- relay_consent_accepted_at: ACCEPTED_AT,
- relay_consent_accepted_by: ADMIN_USER_ID,
- };
- expect(PushRelayConfigSchema.parse(accepted)).toEqual(accepted);
- });
-
- test('the update request takes the consent flag on its own', () => {
- expect(PushRelayConfigUpdateRequest.parse({relay_consent_accepted: true})).toEqual({
- relay_consent_accepted: true,
- });
- });
-
test('the update request drops a client-supplied acceptance stamp', () => {
expect(
PushRelayConfigUpdateRequest.parse({
@@ -81,37 +37,9 @@ describe('push relay consent', () => {
}),
).toEqual({relay_consent_accepted: true});
});
-
- test.each([
- {relay_consent_accepted_at: 'yesterday'},
- {relay_consent_accepted_at: '2026-09-27'},
- {relay_consent_accepted_by: 'not-an-id'},
- {relay_consent_accepted: 'yes'},
- ])('rejects a malformed stored consent: %j', (value) => {
- expect(PushRelayConfigSchema.safeParse(value).success).toBe(false);
- });
});
describe('legacy push service delivery wire', () => {
- test('pins every rollout field to full enrolment and keeps the consent and version', () => {
- const wire = toLegacyPushServiceDeliveryWire(
- {relay_consent_accepted: true, relay_consent_accepted_at: ACCEPTED_AT, relay_consent_accepted_by: ADMIN_USER_ID},
- 7,
- );
- expect(wire).toEqual({
- enabled: true,
- config_version: 7,
- rollout_basis_points: 10000,
- rollout_salt: 'push-service-delivery-v1',
- included_user_ids: [],
- excluded_user_ids: [],
- relay_consent_accepted: true,
- relay_consent_accepted_at: ACCEPTED_AT,
- relay_consent_accepted_by: ADMIN_USER_ID,
- });
- expect(LegacyPushServiceDeliveryWire.parse(wire)).toEqual(wire);
- });
-
test('rejects a document that would take anyone off the push service', () => {
const wire = toLegacyPushServiceDeliveryWire(PushRelayConfigSchema.parse({}), 0);
expect(LegacyPushServiceDeliveryWire.safeParse({...wire, enabled: false}).success).toBe(false);
diff --git a/packages/schema/src/domains/admin/VoiceP2pSchemas.test.ts b/packages/schema/src/domains/admin/VoiceP2pSchemas.test.ts
index 959d66bda..a867823b4 100644
--- a/packages/schema/src/domains/admin/VoiceP2pSchemas.test.ts
+++ b/packages/schema/src/domains/admin/VoiceP2pSchemas.test.ts
@@ -4,7 +4,6 @@ import {
DEFAULT_VOICE_P2P_CONFIG,
resolveVoiceP2pAssignment,
type VoiceP2pConfig,
- VoiceP2pConfigSchema,
VoiceP2pConfigUpdateRequest,
} from '@fluxer/schema/src/domains/admin/VoiceP2pSchemas';
import {type ExperimentTargeting, experimentBucket} from '@fluxer/schema/src/domains/experiment/ExperimentBucket';
@@ -26,51 +25,15 @@ function syntheticUserIds(count: number): Array<string> {
}
describe('voice p2p configuration', () => {
- test('defaults to disabled', () => {
- expect(VoiceP2pConfigSchema.parse({})).toEqual({
- enabled: false,
- config_version: 0,
- rollout_basis_points: 0,
- rollout_country_codes: [],
- rollout_salt: 'voice-p2p-v1',
- included_user_ids: [],
- excluded_user_ids: [],
- included_guild_ids: [],
- include_premium_users: false,
- max_participants: 2,
- });
- });
-
test('limits max_participants to 2 through 4', () => {
expect(VoiceP2pConfigUpdateRequest.safeParse({max_participants: 4}).data).toEqual({max_participants: 4});
expect(VoiceP2pConfigUpdateRequest.safeParse({max_participants: 1}).success).toBe(false);
expect(VoiceP2pConfigUpdateRequest.safeParse({max_participants: 5}).success).toBe(false);
expect(VoiceP2pConfigUpdateRequest.safeParse({max_participants: 2.5}).success).toBe(false);
});
-
- test('strips config_version from admin updates', () => {
- expect(VoiceP2pConfigUpdateRequest.safeParse({config_version: 3}).data).toEqual({});
- expect(VoiceP2pConfigUpdateRequest.safeParse({rollout_basis_points: 10001}).success).toBe(false);
- });
});
describe('resolveVoiceP2pAssignment', () => {
- test('reports the configured cap whether or not the caller is selected', () => {
- const config = createConfig({enabled: true, max_participants: 4, included_user_ids: [TARGETED_USER_ID]});
- expect(resolveVoiceP2pAssignment(config, TARGETED_USER_ID, NO_TARGETING)).toEqual({
- enabled: true,
- max_participants: 4,
- });
- expect(resolveVoiceP2pAssignment(config, '1000000000000000007', NO_TARGETING)).toEqual({
- enabled: false,
- max_participants: 4,
- });
- expect(resolveVoiceP2pAssignment({...config, enabled: false}, TARGETED_USER_ID, NO_TARGETING)).toEqual({
- enabled: false,
- max_participants: 4,
- });
- });
-
test('serves nobody while disabled, even included users', () => {
const config = createConfig({rollout_basis_points: 10000, included_user_ids: [TARGETED_USER_ID]});
expect(resolveVoiceP2pAssignment(config, TARGETED_USER_ID, NO_TARGETING)).toEqual(UNSELECTED);
diff --git a/packages/schema/src/domains/tests/AuthLoginSchemas.test.ts b/packages/schema/src/domains/tests/AuthLoginSchemas.test.ts
index 8a97ca5b9..7715c0573 100644
--- a/packages/schema/src/domains/tests/AuthLoginSchemas.test.ts
+++ b/packages/schema/src/domains/tests/AuthLoginSchemas.test.ts
@@ -1,10 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {
- LoginRequest,
- RecoverAccountResponse,
- UsernameInstanceLoginRequest,
-} from '@fluxer/schema/src/domains/auth/AuthSchemas';
+import {LoginRequest, UsernameInstanceLoginRequest} from '@fluxer/schema/src/domains/auth/AuthSchemas';
import {createStringType} from '@fluxer/schema/src/primitives/SchemaPrimitives';
import {EmailType, PasswordType} from '@fluxer/schema/src/primitives/UserValidators';
import {describe, expect, it} from 'vitest';
@@ -88,29 +84,3 @@ describe('UsernameInstanceLoginRequest', () => {
expect(result.error?.issues.map(({path}) => path)).toEqual([['email']]);
});
});
-
-describe('RecoverAccountResponse', () => {
- const kit = {
- recovery_key: 'ABCD-EFGH-JKMN-PQRS-TVWX-YZ01-2345-6789',
- recovery_kit_created_at: '2026-10-01T12:00:00.000Z',
- };
-
- it('adds the new kit to every response variant', () => {
- for (const option of RecoverAccountResponse.options) {
- expect(Object.keys(option.shape)).toEqual(expect.arrayContaining(Object.keys(kit)));
- }
- });
-
- it('carries the new kit next to an MFA ticket', () => {
- const parsed = RecoverAccountResponse.safeParse({
- mfa: true,
- ticket: 'ticket',
- allowed_methods: ['totp'],
- totp: true,
- webauthn: false,
- backup_codes: false,
- ...kit,
- });
- expect(parsed.success ? parsed.data : parsed.error.issues).toMatchObject(kit);
- });
-});
diff --git a/packages/schema/src/domains/tests/ExperimentSchemas.test.ts b/packages/schema/src/domains/tests/ExperimentSchemas.test.ts
deleted file mode 100644
index e73e96d80..000000000
--- a/packages/schema/src/domains/tests/ExperimentSchemas.test.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import {
- DEFAULT_EXPERIMENT_DELIVERY_CONFIG,
- ExperimentAssignmentsResponse,
- ExperimentDeliveryConfigSchema,
- ExperimentDeliveryConfigUpdateRequest,
-} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
-import {describe, expect, it} from 'vitest';
-
-describe('experiment delivery schemas', () => {
- it('derives complete configuration defaults without filling partial updates', () => {
- expect(ExperimentDeliveryConfigSchema.parse({})).toEqual(DEFAULT_EXPERIMENT_DELIVERY_CONFIG);
- expect(ExperimentDeliveryConfigUpdateRequest.parse({})).toEqual({});
- expect(ExperimentDeliveryConfigUpdateRequest.parse({poll_interval_seconds: 3600})).toEqual({
- poll_interval_seconds: 3600,
- });
- });
-
- it.each([
- {poll_interval_seconds: 59},
- {poll_interval_seconds: 86401},
- {poll_jitter_percent: -1},
- {poll_jitter_percent: 51},
- ])('uses the same delivery bounds in configuration and updates: %j', (value) => {
- expect(ExperimentDeliveryConfigSchema.safeParse(value).success).toBe(false);
- expect(ExperimentDeliveryConfigUpdateRequest.safeParse(value).success).toBe(false);
- });
-
- it.each([1, 999999])('preserves server poll intervals for client-side clamping: %i', (interval) => {
- expect(
- ExperimentAssignmentsResponse.parse({
- ...DEFAULT_EXPERIMENT_DELIVERY_CONFIG,
- poll_interval_seconds: interval,
- assignments: {},
- }).poll_interval_seconds,
- ).toBe(interval);
- });
-});
diff --git a/packages/schema/src/domains/tests/GatewayRolloutSchemas.test.ts b/packages/schema/src/domains/tests/GatewayRolloutSchemas.test.ts
deleted file mode 100644
index e98097f38..000000000
--- a/packages/schema/src/domains/tests/GatewayRolloutSchemas.test.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {
- GatewayRolloutConfigSchema,
- GatewayRolloutConfigUpdateRequest,
-} from '@fluxer/schema/src/domains/admin/GatewayRolloutSchemas';
-import {describe, expect, test} from 'vitest';
-
-describe('gateway rollout schemas', () => {
- test('full config applies defaults for omitted values', () => {
- expect(GatewayRolloutConfigSchema.parse({})).toMatchObject({
- session_rollout_percentage: 100,
- session_rollout_mode: 'modulo',
- rpc_request_timeout_ms: 10000,
- gateway_dispatch_relay_shards: 32,
- gateway_dispatch_relay_max_queue: 50000,
- voice_e2ee_scope: 'guild_feature_only',
- });
- });
- test('update request remains partial and does not inject defaults', () => {
- expect(
- GatewayRolloutConfigUpdateRequest.parse({
- rpc_request_timeout_ms: 5000,
- gateway_dispatch_relay_shards: 16,
- }),
- ).toEqual({
- rpc_request_timeout_ms: 5000,
- gateway_dispatch_relay_shards: 16,
- });
- });
- test('voice e2ee scope accepts only known modes', () => {
- expect(GatewayRolloutConfigUpdateRequest.parse({voice_e2ee_scope: 'platform_wide'})).toEqual({
- voice_e2ee_scope: 'platform_wide',
- });
- expect(() => GatewayRolloutConfigUpdateRequest.parse({voice_e2ee_scope: 'guilds'})).toThrow();
- });
-});
diff --git a/packages/schema/src/domains/tests/GuildRequestSchemas.test.ts b/packages/schema/src/domains/tests/GuildRequestSchemas.test.ts
deleted file mode 100644
index 53d5f483b..000000000
--- a/packages/schema/src/domains/tests/GuildRequestSchemas.test.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {TemplateChannel} from '@fluxer/schema/src/domains/guild/GuildTemplateSchemas';
-import {describe, expect, it} from 'vitest';
-
-describe('TemplateChannel permission overwrites', () => {
- it.each([
- ['role', 0],
- ['member', 1],
- ['0', 0],
- [1, 1],
- [42, 42],
- ])('normalizes the imported overwrite type %j', (type, expected) => {
- const channel = TemplateChannel.parse({
- id: '1',
- type: 0,
- position: 0,
- permission_overwrites: [{id: '2', type, allow: '8', deny: '0'}],
- });
- expect(channel.permission_overwrites).toEqual([{id: '2', type: expected, allow: '8', deny: '0'}]);
- });
-
- it.each(['invalid', 'NaN', 'Infinity', Number.NaN, Number.POSITIVE_INFINITY])(
- 'rejects nonfinite overwrite type %j',
- (type) => {
- expect(
- TemplateChannel.safeParse({
- id: '1',
- type: 0,
- position: 0,
- permission_overwrites: [{id: '2', type, allow: '8', deny: '0'}],
- }).success,
- ).toBe(false);
- },
- );
-});
diff --git a/packages/schema/src/domains/tests/UserRequestSchemas.test.ts b/packages/schema/src/domains/tests/UserRequestSchemas.test.ts
deleted file mode 100644
index e5d0901f7..000000000
--- a/packages/schema/src/domains/tests/UserRequestSchemas.test.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {create} from '@bufbuild/protobuf';
-import {MAX_GROUP_DM_OTHER_RECIPIENTS} from '@fluxer/constants/src/LimitConstants';
-import {
- encodeSyncedPreferences,
- SYNCED_PREFERENCES_MAX_ENCODED_LENGTH,
- SyncedPreferencesSchema,
-} from '@fluxer/schema/src/domains/user/SyncedPreferencesCodec';
-import {
- CreatePrivateChannelRequest,
- CustomStatusPayload,
- UserSettingsUpdateRequest,
-} from '@fluxer/schema/src/domains/user/UserRequestSchemas';
-import {SearchEngineSettingsSchema} from '@fluxer/schema/src/gen/fluxer/user/preferences/v1/preferences_pb';
-import {describe, expect, it} from 'vitest';
-
-describe('CustomStatusPayload', () => {
- it('accepts single-codepoint unicode emoji names', () => {
- expect(
- CustomStatusPayload.parse({
- text: 'Coffee time',
- emoji_name: '☕',
- }),
- ).toEqual({text: 'Coffee time', emoji_name: '☕'});
- });
- it('ignores emoji_name when emoji_id is provided', () => {
- expect(
- CustomStatusPayload.parse({
- text: 'Custom emoji status',
- emoji_id: '123456789012345678',
- emoji_name: 'not-a-unicode-emoji-and-way-too-long-to-validate-in-this-path',
- }),
- ).toEqual({text: 'Custom emoji status', emoji_id: 123456789012345678n});
- });
-});
-
-describe('UserSettingsUpdateRequest synced_preferences', () => {
- it('accepts a base64-encoded snapshot', () => {
- const encoded = encodeSyncedPreferences(
- create(SyncedPreferencesSchema, {
- searchEngines: create(SearchEngineSettingsSchema, {textSearchEngineId: 'google'}),
- }),
- );
- expect(UserSettingsUpdateRequest.parse({synced_preferences: encoded})).toEqual({synced_preferences: encoded});
- });
- it.each([
- {name: 'empty snapshot', value: ''},
- {name: 'cleared snapshot', value: null},
- {name: 'exact size cap', value: 'A'.repeat(SYNCED_PREFERENCES_MAX_ENCODED_LENGTH)},
- ])('preserves $name', ({value}) => {
- expect(UserSettingsUpdateRequest.parse({synced_preferences: value})).toEqual({synced_preferences: value});
- });
- it.each([
- {name: 'non-base64 string', value: 'not_base64!!!'},
- {name: 'raw object', value: {textSearchEngineId: 'google'}},
- {name: 'above size cap', value: 'A'.repeat(SYNCED_PREFERENCES_MAX_ENCODED_LENGTH + 1)},
- ])('rejects $name', ({value}) => {
- expect(UserSettingsUpdateRequest.safeParse({synced_preferences: value}).success).toBe(false);
- });
-});
-
-describe('CreatePrivateChannelRequest', () => {
- it('allows the maximum other recipients for a 50-member group DM', () => {
- const recipients = Array.from({length: MAX_GROUP_DM_OTHER_RECIPIENTS}, (_, index) =>
- String(100000000000000000n + BigInt(index)),
- );
- expect(CreatePrivateChannelRequest.parse({recipients})).toEqual({recipients: recipients.map(BigInt)});
- });
- it('rejects group DM requests above the member limit', () => {
- const recipients = Array.from({length: MAX_GROUP_DM_OTHER_RECIPIENTS + 1}, (_, index) =>
- String(100000000000000000n + BigInt(index)),
- );
- expect(CreatePrivateChannelRequest.safeParse({recipients}).success).toBe(false);
- });
- it('allows DM requests to the system user id 0', () => {
- expect(CreatePrivateChannelRequest.parse({recipient_id: '0'})).toEqual({recipient_id: 0n});
- });
- it.each([{}, {recipient_id: '0', recipients: []}])('requires exactly one recipient form for %j', (input) => {
- expect(CreatePrivateChannelRequest.safeParse(input)).toMatchObject({
- success: false,
- error: {issues: [{message: 'Either recipient_id or recipients must be provided, but not both'}]},
- });
- });
-});
diff --git a/packages/schema/src/primitives/tests/AuditLogValidators.test.ts b/packages/schema/src/primitives/tests/AuditLogValidators.test.ts
deleted file mode 100644
index 69adb7efb..000000000
--- a/packages/schema/src/primitives/tests/AuditLogValidators.test.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {AuditLogActionType} from '@fluxer/constants/src/AuditLogActionType';
-import {AuditLogActionTypeSchema} from '@fluxer/schema/src/primitives/AuditLogValidators';
-import {describe, expect, it} from 'vitest';
-
-describe('AuditLogActionTypeSchema', () => {
- it.each(Object.values(AuditLogActionType).filter((value) => typeof value === 'number'))(
- 'accepts registered action %i',
- (value) => {
- expect(AuditLogActionTypeSchema.parse(value)).toBe(value);
- },
- );
-
- it.each([0, 9, 999, -1, 1.5, '1', 'GUILD_UPDATE', null])('rejects unknown or nonnumeric action %j', (value) => {
- expect(AuditLogActionTypeSchema.safeParse(value).success).toBe(false);
- });
-});
diff --git a/packages/schema/src/primitives/tests/ChannelValidators.test.ts b/packages/schema/src/primitives/tests/ChannelValidators.test.ts
deleted file mode 100644
index c37c9ca7d..000000000
--- a/packages/schema/src/primitives/tests/ChannelValidators.test.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
-import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
-import {ChannelTypeSchema, VanityURLCodeType} from '@fluxer/schema/src/primitives/ChannelValidators';
-import {describe, expect, it} from 'vitest';
-
-describe('ChannelTypeSchema', () => {
- it.each(Object.values(ChannelTypes))('accepts channel type %i', (value) => {
- expect(ChannelTypeSchema.parse(value)).toBe(value);
- });
-
- it.each([9, 13, 14, 17, -1, '0', null])('rejects unknown channel type %j', (value) => {
- expect(ChannelTypeSchema.safeParse(value).success).toBe(false);
- });
-});
-
-describe('VanityURLCodeType', () => {
- it.each([
- ['myserver', 'myserver'],
- ['my-server', 'my-server'],
- ['server123', 'server123'],
- ['MyServer', 'myserver'],
- ['my server', 'my-server'],
- ['my--server', 'my-server'],
- [' My \u202EServer ', 'my-server'],
- ['ab', 'ab'],
- ['a'.repeat(32), 'a'.repeat(32)],
- ])('normalizes %j to %j', (input, expected) => {
- expect(VanityURLCodeType.parse(input)).toBe(expected);
- });
-
- it.each(['a', 'a'.repeat(33)])('rejects an out-of-range code %j', (input) => {
- expect(VanityURLCodeType.safeParse(input)).toMatchObject({
- success: false,
- error: {issues: [{message: ValidationErrorCodes.VANITY_URL_CODE_LENGTH_INVALID}]},
- });
- });
-
- it.each(['', '-myserver', 'myserver-', 'my_server', '日本語'])('rejects invalid characters in %j', (input) => {
- expect(VanityURLCodeType.safeParse(input)).toMatchObject({
- success: false,
- error: {issues: [{message: ValidationErrorCodes.VANITY_URL_INVALID_CHARACTERS}]},
- });
- });
-});
diff --git a/packages/schema/src/primitives/tests/EmojiValidators.test.ts b/packages/schema/src/primitives/tests/EmojiValidators.test.ts
deleted file mode 100644
index 0b0a41f1c..000000000
--- a/packages/schema/src/primitives/tests/EmojiValidators.test.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {isValidSingleUnicodeEmoji} from '@fluxer/schema/src/primitives/EmojiValidators';
-import {describe, expect, it} from 'vitest';
-
-describe('isValidSingleUnicodeEmoji', () => {
- describe('invalid inputs', () => {
- it('rejects empty string', () => {
- expect(isValidSingleUnicodeEmoji('')).toBe(false);
- });
- it('rejects plain text', () => {
- expect(isValidSingleUnicodeEmoji('hello')).toBe(false);
- expect(isValidSingleUnicodeEmoji('abc')).toBe(false);
- });
- it('rejects single ascii characters', () => {
- expect(isValidSingleUnicodeEmoji('a')).toBe(false);
- expect(isValidSingleUnicodeEmoji('1')).toBe(false);
- expect(isValidSingleUnicodeEmoji('#')).toBe(false);
- expect(isValidSingleUnicodeEmoji(' ')).toBe(false);
- });
- it('rejects multiple emojis', () => {
- expect(isValidSingleUnicodeEmoji('👍👍')).toBe(false);
- expect(isValidSingleUnicodeEmoji('🎉🎊')).toBe(false);
- expect(isValidSingleUnicodeEmoji('👨‍👩‍👧‍👦👨‍👩‍👧')).toBe(false);
- });
- it('rejects multiple regional indicator symbols', () => {
- expect(isValidSingleUnicodeEmoji('\u{1F1E6}\u{1F1E7}')).toBe(false);
- });
- it('rejects emoji with trailing text', () => {
- expect(isValidSingleUnicodeEmoji('👍abc')).toBe(false);
- expect(isValidSingleUnicodeEmoji('🎉!')).toBe(false);
- });
- it('rejects emoji with leading text', () => {
- expect(isValidSingleUnicodeEmoji('abc👍')).toBe(false);
- expect(isValidSingleUnicodeEmoji('!🎉')).toBe(false);
- });
- it('rejects unicode characters that are not emoji', () => {
- expect(isValidSingleUnicodeEmoji('é')).toBe(false);
- expect(isValidSingleUnicodeEmoji('中')).toBe(false);
- expect(isValidSingleUnicodeEmoji('α')).toBe(false);
- });
- it('rejects regional indicator with trailing text', () => {
- expect(isValidSingleUnicodeEmoji('\u{1F1F5}abc')).toBe(false);
- });
- it('rejects regional indicator with leading text', () => {
- expect(isValidSingleUnicodeEmoji('abc\u{1F1F5}')).toBe(false);
- });
- });
- describe('malformed emoji sequences', () => {
- it('rejects skin tone at wrong position in ZWJ sequence', () => {
- expect(isValidSingleUnicodeEmoji('🧑‍🎄🏿')).toBe(false);
- });
- it('rejects standalone ZWJ character', () => {
- expect(isValidSingleUnicodeEmoji('\u200D')).toBe(false);
- });
- it('rejects emoji followed by standalone skin tone', () => {
- expect(isValidSingleUnicodeEmoji('🎄🏿')).toBe(false);
- });
- it('rejects double skin tone modifiers', () => {
- expect(isValidSingleUnicodeEmoji('👍🏿🏻')).toBe(false);
- });
- });
-});
diff --git a/packages/schema/src/primitives/tests/GuildValidators.test.ts b/packages/schema/src/primitives/tests/GuildValidators.test.ts
deleted file mode 100644
index bd04ee403..000000000
--- a/packages/schema/src/primitives/tests/GuildValidators.test.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {
- GuildExplicitContentFilterTypes,
- GuildMFALevel,
- GuildNSFWLevel,
- GuildSplashCardAlignment,
- GuildVerificationLevel,
- JoinSourceTypes,
-} from '@fluxer/constants/src/GuildConstants';
-import {MessageNotifications} from '@fluxer/constants/src/NotificationConstants';
-import {
- DefaultMessageNotificationsSchema,
- GuildExplicitContentFilterSchema,
- GuildMFALevelSchema,
- GuildVerificationLevelInputSchema,
- GuildVerificationLevelSchema,
- JoinSourceTypeSchema,
- NSFWLevelSchema,
- SplashCardAlignmentSchema,
-} from '@fluxer/schema/src/primitives/GuildValidators';
-import {describe, expect, it} from 'vitest';
-
-describe.each([
- {name: 'verification level', schema: GuildVerificationLevelSchema, values: Object.values(GuildVerificationLevel)},
- {name: 'MFA level', schema: GuildMFALevelSchema, values: Object.values(GuildMFALevel)},
- {
- name: 'content filter',
- schema: GuildExplicitContentFilterSchema,
- values: Object.values(GuildExplicitContentFilterTypes),
- },
- {
- name: 'default notifications',
- schema: DefaultMessageNotificationsSchema,
- values: [MessageNotifications.ALL_MESSAGES, MessageNotifications.ONLY_MENTIONS],
- },
- {name: 'NSFW level', schema: NSFWLevelSchema, values: Object.values(GuildNSFWLevel)},
- {name: 'splash alignment', schema: SplashCardAlignmentSchema, values: Object.values(GuildSplashCardAlignment)},
- {name: 'join source', schema: JoinSourceTypeSchema, values: Object.values(JoinSourceTypes)},
-])('$name', ({schema, values}) => {
- it.each(values)('accepts registered value %i', (value) => {
- expect(schema.parse(value)).toBe(value);
- });
-
- it.each([-1, 999, 0.5, '0', null])('rejects invalid value %j', (value) => {
- expect(schema.safeParse(value).success).toBe(false);
- });
-});
-
-it('rejects verification level 4 on output', () => {
- expect(GuildVerificationLevelSchema.safeParse(4).success).toBe(false);
-});
-
-it('stores verification level 4 on input as high', () => {
- expect(GuildVerificationLevelInputSchema.parse(4)).toBe(GuildVerificationLevel.HIGH);
-});
-
-it.each(Object.values(GuildVerificationLevel))('keeps input verification level %i', (value) => {
- expect(GuildVerificationLevelInputSchema.parse(value)).toBe(value);
-});
-
-it.each([-1, 5, '4', null])('rejects input verification level %j', (value) => {
- expect(GuildVerificationLevelInputSchema.safeParse(value).success).toBe(false);
-});
-
-it.each([1, 2])('rejects legacy NSFW level %i', (value) => {
- expect(NSFWLevelSchema.safeParse(value).success).toBe(false);
-});
-
-it.each([MessageNotifications.NULL, MessageNotifications.NO_MESSAGES, MessageNotifications.INHERIT])(
- 'rejects channel-only notification setting %i as a guild default',
- (value) => {
- expect(DefaultMessageNotificationsSchema.safeParse(value).success).toBe(false);
- },
-);
diff --git a/packages/schema/src/primitives/tests/MessageValidators.test.ts b/packages/schema/src/primitives/tests/MessageValidators.test.ts
deleted file mode 100644
index 11ba6eb94..000000000
--- a/packages/schema/src/primitives/tests/MessageValidators.test.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {MessageReferenceTypes, MessageTypes} from '@fluxer/constants/src/ChannelConstants';
-import {MessageReferenceTypeSchema, MessageTypeSchema} from '@fluxer/schema/src/primitives/MessageValidators';
-import {describe, expect, it} from 'vitest';
-
-describe('MessageTypeSchema', () => {
- it.each(Object.values(MessageTypes).filter((value) => value !== MessageTypes.CLIENT_SYSTEM))(
- 'accepts wire message type %i',
- (value) => {
- expect(MessageTypeSchema.parse(value)).toBe(value);
- },
- );
-
- it.each([MessageTypes.THREAD_CREATED, MessageTypes.THREAD_STARTER_MESSAGE])(
- 'accepts thread message type %i',
- (value) => {
- expect(MessageTypeSchema.parse(value)).toBe(value);
- },
- );
-
- it.each([MessageTypes.CLIENT_SYSTEM, 8, 20, -1, 0.5, '0', null])('rejects non-wire message type %j', (value) => {
- expect(MessageTypeSchema.safeParse(value).success).toBe(false);
- });
-});
-
-describe('MessageReferenceTypeSchema', () => {
- it.each(Object.values(MessageReferenceTypes))('accepts reference type %i', (value) => {
- expect(MessageReferenceTypeSchema.parse(value)).toBe(value);
- });
-
- it.each([2, -1, 0.5, '0', null])('rejects invalid reference type %j', (value) => {
- expect(MessageReferenceTypeSchema.safeParse(value).success).toBe(false);
- });
-});
diff --git a/packages/schema/src/primitives/tests/SchemaPrimitives.test.ts b/packages/schema/src/primitives/tests/SchemaPrimitives.test.ts
index 1ecb717b8..31065c962 100644
--- a/packages/schema/src/primitives/tests/SchemaPrimitives.test.ts
+++ b/packages/schema/src/primitives/tests/SchemaPrimitives.test.ts
@@ -3,7 +3,6 @@
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {
coerceNumberFromString,
- createInt32EnumType,
createStringType,
Int32Type,
Int64StringType,
@@ -16,10 +15,7 @@ import {
stripInvisibles,
stripVariationSelectors,
UnsignedInt64Type,
- withFieldDescription,
- withOpenApiType,
} from '@fluxer/schema/src/primitives/SchemaPrimitives';
-import {schemaMetadata} from '@fluxer/schema/src/SchemaMetadata';
import {describe, expect, it} from 'vitest';
import {z} from 'zod';
@@ -241,38 +237,3 @@ describe('stripVariationSelectors', () => {
expect(() => stripVariationSelectors(longString)).toThrow(ValidationErrorCodes.STRING_LENGTH_INVALID);
});
});
-
-describe('named enum metadata', () => {
- const schema = createInt32EnumType(
- [
- [0, 'NONE', 'No selection'],
- [2, 'SECOND'],
- ],
- 'Selection',
- 'OriginalSelection',
- );
- it.each([0, 2])('preserves enum member %i', (value) => {
- expect(schema.parse(value)).toBe(value);
- });
- it('retains the custom error for an unrecognized integer', () => {
- expect(schema.safeParse(1).error?.issues).toEqual([{code: 'custom', message: 'Expected one of [0, 2]', path: []}]);
- });
- it.each([-1, 0.5, '0'])('does not loosen integer validation for %j', (value) => {
- expect(schema.safeParse(value).success).toBe(false);
- });
- it('retains enum metadata when describing and renaming a clone', () => {
- const described = withFieldDescription(schema, 'Field selection');
- const renamed = withOpenApiType(described, 'FieldSelection');
- expect(schema.description).toBe('Selection');
- expect(schemaMetadata.get(schema)?.name).toBe('OriginalSelection');
- expect(renamed.description).toBe('Field selection');
- expect(schemaMetadata.get(renamed)).toEqual({
- name: 'FieldSelection',
- format: 'int32',
- enumEntries: [
- {value: 0, name: 'NONE', description: 'No selection'},
- {value: 2, name: 'SECOND'},
- ],
- });
- });
-});
diff --git a/packages/schema/src/primitives/tests/UserValidators.test.ts b/packages/schema/src/primitives/tests/UserValidators.test.ts
index 567d996b4..43df42412 100644
--- a/packages/schema/src/primitives/tests/UserValidators.test.ts
+++ b/packages/schema/src/primitives/tests/UserValidators.test.ts
@@ -5,40 +5,6 @@ import {GlobalNameType, PasswordType, UsernameType} from '@fluxer/schema/src/pri
import {describe, expect, it} from 'vitest';
describe('UsernameType', () => {
- it('accepts valid alphanumeric usernames', () => {
- const result = UsernameType.parse('testuser');
- expect(result).toBe('testuser');
- });
- it('accepts usernames with underscores', () => {
- const result = UsernameType.safeParse('test_user');
- expect(result.success).toBe(true);
- });
- it('accepts usernames with numbers', () => {
- const result = UsernameType.safeParse('user123');
- expect(result.success).toBe(true);
- });
- it('trims whitespace', () => {
- const result = UsernameType.parse(' testuser ');
- expect(result).toBe('testuser');
- });
- it('rejects empty usernames', () => {
- const result = UsernameType.safeParse('');
- expect(result.success).toBe(false);
- });
- it('rejects usernames exceeding max length', () => {
- const result = UsernameType.safeParse('a'.repeat(33));
- expect(result.success).toBe(false);
- if (!result.success) {
- expect(result.error.issues[0].message).toBe(ValidationErrorCodes.USERNAME_LENGTH_INVALID);
- }
- });
- it('rejects usernames with invalid characters', () => {
- const result = UsernameType.safeParse('test-user');
- expect(result.success).toBe(false);
- if (!result.success) {
- expect(result.error.issues[0].message).toBe(ValidationErrorCodes.USERNAME_INVALID_CHARACTERS);
- }
- });
it('rejects "everyone" as username', () => {
const result = UsernameType.safeParse('everyone');
expect(result.success).toBe(false);
@@ -91,10 +57,6 @@ describe('GlobalNameType', () => {
});
describe('PasswordType', () => {
- it('accepts valid passwords', () => {
- const result = PasswordType.parse('securepassword123');
- expect(result).toBe('securepassword123');
- });
it('accepts passwords at minimum length', () => {
const result = PasswordType.safeParse('12345678');
expect(result.success).toBe(true);