Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add AgeRange options (#1379)

Leendert de Borst02575d73668f
diff --git a/apps/server/AliasVault.Client/Services/JsInterop/Models/AgeRangeOption.cs b/apps/server/AliasVault.Client/Services/JsInterop/Models/AgeRangeOption.cs
new file mode 100644
index 000000000..3883a21fe
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/JsInterop/Models/AgeRangeOption.cs
@@ -0,0 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="AgeRangeOption.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.JsInterop.Models;
+
+/// <summary>
+/// Represents an age range option for identity generation.
+/// </summary>
+public sealed class AgeRangeOption
+{
+ /// <summary>
+ /// Gets or sets the value to store (e.g., "21-25", "random").
+ /// </summary>
+ public string Value { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the display label (e.g., "21-25", "Random").
+ /// </summary>
+ public string Label { get; set; } = string.Empty;
+}
diff --git a/shared/identity-generator/src/__tests__/AgeRangeConverter.test.ts b/shared/identity-generator/src/__tests__/AgeRangeConverter.test.ts
index cb915efb9..a41e4aba7 100644
--- a/shared/identity-generator/src/__tests__/AgeRangeConverter.test.ts
+++ b/shared/identity-generator/src/__tests__/AgeRangeConverter.test.ts
@@ -1,8 +1,21 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
-import { convertAgeRangeToBirthdateOptions } from '../utils/AgeRangeConverter';
+import { convertAgeRangeToBirthdateOptions, getAvailableAgeRanges } from '../utils/AgeRangeConverter';
describe('AgeRangeConverter', () => {
+ describe('getAvailableAgeRanges', () => {
+ it('should return an array of age range options', () => {
+ const ranges = getAvailableAgeRanges();
+ expect(ranges).toBeInstanceOf(Array);
+ expect(ranges.length).toBeGreaterThan(0);
+ });
+
+ it('should include random option as first item', () => {
+ const ranges = getAvailableAgeRanges();
+ expect(ranges[0]).toEqual({ value: 'random', label: 'Random' });
+ });
+ });
+
// Mock Date to ensure consistent test results
const MOCK_CURRENT_YEAR = 2025;
let originalDate: DateConstructor;
diff --git a/shared/identity-generator/src/utils/AgeRangeConverter.ts b/shared/identity-generator/src/utils/AgeRangeConverter.ts
index c38ce5f38..fb148fef3 100644
--- a/shared/identity-generator/src/utils/AgeRangeConverter.ts
+++ b/shared/identity-generator/src/utils/AgeRangeConverter.ts
@@ -1,5 +1,39 @@
import type { IBirthdateOptions } from '../interfaces/IIdentityGenerator';
+/**
+ * Represents an age range option for identity generation.
+ */
+export interface IAgeRangeOption {
+ /**
+ * The value to store (e.g., "21-25", "random")
+ */
+ value: string;
+
+ /**
+ * The display label (e.g., "21-25", "Random")
+ */
+ label: string;
+}
+
+/**
+ * Gets all available age range options for identity generation.
+ * @returns Array of age range options
+ */
+export function getAvailableAgeRanges(): IAgeRangeOption[] {
+ return [
+ { value: 'random', label: 'Random' },
+ { value: '21-25', label: '21-25' },
+ { value: '26-30', label: '26-30' },
+ { value: '31-35', label: '31-35' },
+ { value: '36-40', label: '36-40' },
+ { value: '41-45', label: '41-45' },
+ { value: '46-50', label: '46-50' },
+ { value: '51-55', label: '51-55' },
+ { value: '56-60', label: '56-60' },
+ { value: '61-65', label: '61-65' }
+ ];
+}
+
/**
* Converts an age range string (e.g., "21-25", "30-35", or "random") to birthdate options.
* @param ageRange - The age range string