mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
chore(repo): remove dead code and useless tests (#3375)
This commit is contained in:
1 parent
7e177a1c90
commit
1cd62eb661
1391 files changed
+783
-120415
No files matched your search
@@ -1,33 +0,0 @@
|
||||
import {chunkArray} from '@app/api/utils/ArrayUtils';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('chunkArray', () => {
|
||||
it.each([
|
||||
{size: 1, expected: [[1], [2], [3], [4], [5]]},
|
||||
{size: 2, expected: [[1, 2], [3, 4], [5]]},
|
||||
{size: 5, expected: [[1, 2, 3, 4, 5]]},
|
||||
{size: 10, expected: [[1, 2, 3, 4, 5]]},
|
||||
])('partitions input into chunks of at most $size', ({size, expected}) => {
|
||||
expect(chunkArray([1, 2, 3, 4, 5], size)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('preserves the input and returns independent chunk arrays', () => {
|
||||
const items = Object.freeze([1, 2, 3]);
|
||||
const chunks = chunkArray(items, 2);
|
||||
chunks[0]!.push(4);
|
||||
expect(items).toEqual([1, 2, 3]);
|
||||
expect(chunks).toEqual([[1, 2, 4], [3]]);
|
||||
});
|
||||
|
||||
it('returns no chunks for empty input', () => {
|
||||
expect(chunkArray([], 2)).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY, Number.MAX_SAFE_INTEGER + 1])(
|
||||
'rejects invalid chunk size %j even for empty input',
|
||||
(size) => {
|
||||
expect(() => chunkArray([1], size)).toThrow('Chunk size must be a positive safe integer');
|
||||
expect(() => chunkArray([], size)).toThrow('Chunk size must be a positive safe integer');
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -29,68 +29,6 @@ describe('getCurrencyPreferences first choice', () => {
|
||||
expect(getCurrencyPreferences('CH')[0]).toBe('USD');
|
||||
});
|
||||
});
|
||||
describe('returns EUR for EEA countries', () => {
|
||||
it('returns EUR for Germany', () => {
|
||||
expect(getCurrencyPreferences('DE')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for France', () => {
|
||||
expect(getCurrencyPreferences('FR')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Italy', () => {
|
||||
expect(getCurrencyPreferences('IT')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Spain', () => {
|
||||
expect(getCurrencyPreferences('ES')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Netherlands', () => {
|
||||
expect(getCurrencyPreferences('NL')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Belgium', () => {
|
||||
expect(getCurrencyPreferences('BE')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Austria', () => {
|
||||
expect(getCurrencyPreferences('AT')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Portugal', () => {
|
||||
expect(getCurrencyPreferences('PT')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Ireland', () => {
|
||||
expect(getCurrencyPreferences('IE')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Finland', () => {
|
||||
expect(getCurrencyPreferences('FI')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns SEK for Sweden', () => {
|
||||
expect(getCurrencyPreferences('SE')[0]).toBe('SEK');
|
||||
});
|
||||
it('returns DKK for Denmark', () => {
|
||||
expect(getCurrencyPreferences('DK')[0]).toBe('DKK');
|
||||
});
|
||||
it('returns PLN for Poland', () => {
|
||||
expect(getCurrencyPreferences('PL')[0]).toBe('PLN');
|
||||
});
|
||||
it('returns EUR for Greece', () => {
|
||||
expect(getCurrencyPreferences('GR')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Czech Republic', () => {
|
||||
expect(getCurrencyPreferences('CZ')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Hungary', () => {
|
||||
expect(getCurrencyPreferences('HU')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns EUR for Romania', () => {
|
||||
expect(getCurrencyPreferences('RO')[0]).toBe('EUR');
|
||||
});
|
||||
it('returns NOK for Norway (EEA but not EU)', () => {
|
||||
expect(getCurrencyPreferences('NO')[0]).toBe('NOK');
|
||||
});
|
||||
it('returns ISK for Iceland (EEA but not EU)', () => {
|
||||
expect(getCurrencyPreferences('IS')[0]).toBe('ISK');
|
||||
});
|
||||
it('returns EUR for Liechtenstein (EEA but not EU)', () => {
|
||||
expect(getCurrencyPreferences('LI')[0]).toBe('EUR');
|
||||
});
|
||||
});
|
||||
describe('handles case insensitivity', () => {
|
||||
it('returns EUR for lowercase country code', () => {
|
||||
expect(getCurrencyPreferences('de')[0]).toBe('EUR');
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {toIdString, toSortedIdArray} from '@app/api/utils/IdUtils';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('toIdString', () => {
|
||||
it.each([
|
||||
[null, null],
|
||||
[undefined, null],
|
||||
[123456789012345678n, '123456789012345678'],
|
||||
['123456789012345678', '123456789012345678'],
|
||||
[0n, '0'],
|
||||
[999999999999999999999999999999n, '999999999999999999999999999999'],
|
||||
[-1n, '-1'],
|
||||
['0', '0'],
|
||||
['00123', '00123'],
|
||||
])('preserves the exact ID representation of %s', (input, expected) => {
|
||||
expect(toIdString(input)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toSortedIdArray', () => {
|
||||
it.each([
|
||||
{input: null, expected: []},
|
||||
{input: undefined, expected: []},
|
||||
{input: [], expected: []},
|
||||
{input: new Set<bigint>(), expected: []},
|
||||
{input: [300n, 100n, 200n], expected: ['100', '200', '300']},
|
||||
{input: ['300', '100', '200'], expected: ['100', '200', '300']},
|
||||
{input: new Set([300n, 100n, 200n]), expected: ['100', '200', '300']},
|
||||
{input: [42n], expected: ['42']},
|
||||
{input: new Set([123n]), expected: ['123']},
|
||||
{input: [100n, 200n, 300n], expected: ['100', '200', '300']},
|
||||
{input: [300n, 200n, 100n], expected: ['100', '200', '300']},
|
||||
{input: [2n, 10n, 1n], expected: ['1', '10', '2']},
|
||||
{input: [100n, 100n, 200n], expected: ['100', '100', '200']},
|
||||
])('stringifies and lexicographically sorts case %#', ({input, expected}) => {
|
||||
expect(toSortedIdArray<bigint | string>(input)).toEqual(expected);
|
||||
});
|
||||
|
||||
it('does not reorder the caller-owned array', () => {
|
||||
const input = [300n, 100n, 200n];
|
||||
toSortedIdArray(input);
|
||||
expect(input).toEqual([300n, 100n, 200n]);
|
||||
});
|
||||
});
|
||||
@@ -1,190 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {
|
||||
isFluxerNativeUserAgent,
|
||||
parseReportedClientOs,
|
||||
resolveSessionClientInfo,
|
||||
type SessionClientInfo,
|
||||
} from '@app/api/utils/SessionClientIdentity';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
const ELECTRON_MAC_UA =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) FluxerStable/2026.614.83512 Chrome/126.0.0.0 Electron/31.0.0 Safari/537.36';
|
||||
const ELECTRON_WINDOWS_UA =
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) FluxerCanary/2026.614.83512 Chrome/126.0.0.0 Electron/31.0.0 Safari/537.36';
|
||||
const CHROME_MAC_UA =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36';
|
||||
const SAFARI_IPHONE_UA =
|
||||
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1';
|
||||
|
||||
const resolve = (userAgent: string | null, reportedOs: string | null, productName = 'Fluxer'): SessionClientInfo =>
|
||||
resolveSessionClientInfo({userAgent, reportedOs, productName});
|
||||
|
||||
describe('resolveSessionClientInfo', () => {
|
||||
it('labels the Flutter mobile clients by their operating system', () => {
|
||||
expect(resolve('Fluxer iOS/1.4.2 (stable)', 'ios')).toEqual({
|
||||
platform: 'Fluxer iOS',
|
||||
os: 'iOS',
|
||||
browser: null,
|
||||
device: 'mobile',
|
||||
});
|
||||
expect(resolve('Fluxer Android/1.4.2 (stable)', 'android')).toEqual({
|
||||
platform: 'Fluxer Android',
|
||||
os: 'Android',
|
||||
browser: null,
|
||||
device: 'mobile',
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts the versionless user agent emitted before package info loads', () => {
|
||||
expect(resolve('Fluxer iOS (stable)', 'ios')).toEqual({
|
||||
platform: 'Fluxer iOS',
|
||||
os: 'iOS',
|
||||
browser: null,
|
||||
device: 'mobile',
|
||||
});
|
||||
});
|
||||
|
||||
it('labels Flutter desktop builds as Lite and distinguishes them by reported operating system', () => {
|
||||
expect(resolve('Fluxer Desktop/1.4.2 (stable)', 'macos')).toEqual({
|
||||
platform: 'Fluxer Lite macOS',
|
||||
os: 'macOS',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
expect(resolve('Fluxer Desktop/1.4.2 (stable)', 'windows')).toEqual({
|
||||
platform: 'Fluxer Lite Windows',
|
||||
os: 'Windows',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
expect(resolve('Fluxer Desktop/1.4.2 (stable)', 'linux')).toEqual({
|
||||
platform: 'Fluxer Lite Linux',
|
||||
os: 'Linux',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
});
|
||||
|
||||
it('treats a narrow Linux window as a desktop because the product token cannot include form factor', () => {
|
||||
expect(resolve('Fluxer Linux/1.4.2 (stable)', 'linux')).toEqual({
|
||||
platform: 'Fluxer Lite Linux',
|
||||
os: 'Linux',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves legacy rows that predate the reported operating system', () => {
|
||||
expect(resolve('Fluxer iOS/1.4.2 (stable)', null)).toEqual({
|
||||
platform: 'Fluxer iOS',
|
||||
os: 'iOS',
|
||||
browser: null,
|
||||
device: 'mobile',
|
||||
});
|
||||
expect(resolve('Fluxer Desktop/1.4.2 (stable)', null)).toEqual({
|
||||
platform: 'Fluxer Lite',
|
||||
os: null,
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores a corrupt reported operating system instead of rendering it', () => {
|
||||
expect(resolve('Fluxer Desktop/1.4.2 (stable)', 'Windows 11')).toEqual({
|
||||
platform: 'Fluxer Lite',
|
||||
os: null,
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
});
|
||||
|
||||
it('labels the desktop application by operating system without naming a browser', () => {
|
||||
expect(resolve(ELECTRON_MAC_UA, null)).toEqual({
|
||||
platform: 'Fluxer macOS',
|
||||
os: 'macOS',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
expect(resolve(ELECTRON_WINDOWS_UA, null)).toEqual({
|
||||
platform: 'Fluxer Windows',
|
||||
os: 'Windows',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps browser sessions reporting their browser', () => {
|
||||
expect(resolve(CHROME_MAC_UA, null)).toEqual({
|
||||
platform: 'Chrome',
|
||||
os: 'macOS',
|
||||
browser: 'Chrome',
|
||||
device: 'desktop',
|
||||
});
|
||||
expect(resolve(SAFARI_IPHONE_UA, null)).toEqual({
|
||||
platform: 'Safari',
|
||||
os: 'iOS',
|
||||
browser: 'Safari',
|
||||
device: 'mobile',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the operating system when the browser cannot be named', () => {
|
||||
expect(resolve('SomeBot (Windows NT 10.0; Win64; x64)', null)).toEqual({
|
||||
platform: 'Windows',
|
||||
os: 'Windows',
|
||||
browser: null,
|
||||
device: 'desktop',
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects a product token that only prefixes a real one', () => {
|
||||
const resolved = resolve('Fluxer iOS-not-really/6.6.6', 'ios');
|
||||
expect(resolved.platform).not.toBe('Fluxer iOS');
|
||||
expect(resolved.browser).toBe(resolved.platform);
|
||||
});
|
||||
|
||||
it('never emits an Unknown literal when the user agent is absent', () => {
|
||||
expect(resolve(null, null)).toEqual({platform: null, os: null, browser: null, device: 'desktop'});
|
||||
expect(resolve('', null)).toEqual({platform: null, os: null, browser: null, device: 'desktop'});
|
||||
});
|
||||
|
||||
it('uses instance branding for the product word', () => {
|
||||
expect(resolve('Fluxer iOS/1.4.2 (stable)', 'ios', 'Acme').platform).toBe('Acme iOS');
|
||||
expect(resolve('Fluxer Desktop/1.4.2 (stable)', 'windows', 'Acme').platform).toBe('Acme Lite Windows');
|
||||
expect(resolve(ELECTRON_MAC_UA, null, 'Acme').platform).toBe('Acme macOS');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isFluxerNativeUserAgent', () => {
|
||||
it('matches only the Fluxer native product tokens', () => {
|
||||
expect(isFluxerNativeUserAgent('Fluxer iOS/1.4.2 (stable)')).toBe(true);
|
||||
expect(isFluxerNativeUserAgent('Fluxer Desktop (canary)')).toBe(true);
|
||||
expect(isFluxerNativeUserAgent(ELECTRON_MAC_UA)).toBe(false);
|
||||
expect(isFluxerNativeUserAgent(CHROME_MAC_UA)).toBe(false);
|
||||
expect(isFluxerNativeUserAgent(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseReportedClientOs', () => {
|
||||
const encode = (value: unknown): string => Buffer.from(JSON.stringify(value), 'utf8').toString('base64');
|
||||
|
||||
it('reads the operating system from the client properties header', () => {
|
||||
expect(parseReportedClientOs(encode({os: 'macos', device: 'mobile'}))).toBe('macos');
|
||||
expect(parseReportedClientOs(encode({os: 'ios'}))).toBe('ios');
|
||||
});
|
||||
|
||||
it('rejects anything outside the known operating systems', () => {
|
||||
expect(parseReportedClientOs(null)).toBeNull();
|
||||
expect(parseReportedClientOs('')).toBeNull();
|
||||
expect(parseReportedClientOs('not base64 $$$')).toBeNull();
|
||||
expect(parseReportedClientOs(encode([1, 2]))).toBeNull();
|
||||
expect(parseReportedClientOs(encode({os: 'solaris'}))).toBeNull();
|
||||
expect(parseReportedClientOs(encode({os: 42}))).toBeNull();
|
||||
expect(parseReportedClientOs(encode({}))).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects an oversized header without decoding it', () => {
|
||||
expect(parseReportedClientOs('a'.repeat(4097))).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,41 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {hasVisibleContent, parseString} from '@app/api/utils/StringUtils';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('parseString', () => {
|
||||
it.each([
|
||||
{input: 'Hello World', max: 50, expected: 'Hello World'},
|
||||
{input: ' Hello World ', max: 50, expected: 'Hello World'},
|
||||
{input: 'This is a very long string that needs truncation', max: 20, expected: 'This is a very lo...'},
|
||||
{input: '12345', max: 5, expected: '12345'},
|
||||
{input: 'Hello & World', max: 50, expected: 'Hello & World'},
|
||||
{input: '<script>', max: 50, expected: '<script>'},
|
||||
{input: '', max: 50, expected: ''},
|
||||
{input: ' ', max: 50, expected: ''},
|
||||
{input: 'Hello 😀 World', max: 50, expected: 'Hello 😀 World'},
|
||||
{input: 'This is a test string for truncation', max: 15, expected: 'This is a te...'},
|
||||
{input: 'Hello', max: 0, expected: '...'},
|
||||
{input: 'Hello', max: 1, expected: '...'},
|
||||
{input: 'Hello', max: 3, expected: '...'},
|
||||
{input: 'Hello', max: 4, expected: 'H...'},
|
||||
{input: 'Hello\nWorld\tTab', max: 50, expected: 'Hello\nWorld\tTab'},
|
||||
{input: '&&&abc', max: 5, expected: '&&...'},
|
||||
{input: '😀abcd', max: 4, expected: '😀...'},
|
||||
])('decodes, trims, and truncates $input to $expected', ({input, max, expected}) => {
|
||||
expect(parseString(input, max)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasVisibleContent', () => {
|
||||
it.each(['', ' \t\n', '\u200e \u200b\ufeff', '\u2800\u3164\u{e0100}'])(
|
||||
'rejects whitespace or invisible-only input %j',
|
||||
(input) => {
|
||||
expect(hasVisibleContent(input)).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(['hello', '\u200e hello', '🙂', '` `'])('accepts visible input %j', (input) => {
|
||||
expect(hasVisibleContent(input)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,33 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {sanitizeOptionalAbsoluteUrl, sanitizeOptionalAbsoluteUrlOrNull} from '@app/api/utils/UrlSanitizer';
|
||||
import {describe, expect, it} from 'vitest';
|
||||
|
||||
describe('sanitizeOptionalAbsoluteUrl', () => {
|
||||
it('returns undefined for nullish values', () => {
|
||||
expect(sanitizeOptionalAbsoluteUrl(undefined)).toBeUndefined();
|
||||
expect(sanitizeOptionalAbsoluteUrl(null)).toBeUndefined();
|
||||
});
|
||||
it('returns undefined for empty or whitespace-only values', () => {
|
||||
expect(sanitizeOptionalAbsoluteUrl('')).toBeUndefined();
|
||||
expect(sanitizeOptionalAbsoluteUrl(' ')).toBeUndefined();
|
||||
});
|
||||
it('returns undefined for invalid URLs', () => {
|
||||
expect(sanitizeOptionalAbsoluteUrl('not-a-valid-url')).toBeUndefined();
|
||||
});
|
||||
it('trims and normalises valid absolute URLs', () => {
|
||||
expect(sanitizeOptionalAbsoluteUrl(' https://example.com/path ')).toBe('https://example.com/path');
|
||||
expect(sanitizeOptionalAbsoluteUrl('https://example.com')).toBe('https://example.com/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitizeOptionalAbsoluteUrlOrNull', () => {
|
||||
it('returns null for invalid inputs', () => {
|
||||
expect(sanitizeOptionalAbsoluteUrlOrNull(undefined)).toBeNull();
|
||||
expect(sanitizeOptionalAbsoluteUrlOrNull(null)).toBeNull();
|
||||
expect(sanitizeOptionalAbsoluteUrlOrNull('not-a-valid-url')).toBeNull();
|
||||
});
|
||||
it('returns normalised URLs for valid inputs', () => {
|
||||
expect(sanitizeOptionalAbsoluteUrlOrNull(' https://example.com/path ')).toBe('https://example.com/path');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user