35 lines
2.3 KiB
TypeScript
35 lines
2.3 KiB
TypeScript
import type { TFunction } from "i18next";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
translateIpAddressLogAction,
|
|
translateIpAddressLogDescription,
|
|
translateIpAddressLogError,
|
|
} from "./ipAddressLogLabels";
|
|
|
|
const t = ((key: string, options?: Record<string, unknown>) => (options?.value ? `${key}:${String(options.value)}` : key)) as TFunction;
|
|
|
|
describe("IP address log labels", () => {
|
|
it("translates known action codes and wraps unknown values in a semantic key", () => {
|
|
expect(translateIpAddressLogAction(t, "login")).toBe("admin.accounts.ipAddresses.logs.actions.login");
|
|
expect(translateIpAddressLogAction(t, "register")).toBe("admin.accounts.ipAddresses.logs.actions.register");
|
|
expect(translateIpAddressLogAction(t, "reset")).toBe("admin.accounts.ipAddresses.logs.actions.reset");
|
|
expect(translateIpAddressLogAction(t, "forgot-password")).toBe("admin.accounts.ipAddresses.logs.actions.forgotPassword");
|
|
expect(translateIpAddressLogAction(t, "reset-password")).toBe("admin.accounts.ipAddresses.logs.actions.resetPassword");
|
|
expect(translateIpAddressLogAction(t, " custom-action ")).toBe("admin.accounts.ipAddresses.logs.actions.unknownWithValue:custom-action");
|
|
expect(translateIpAddressLogAction(t, " ")).toBe("");
|
|
});
|
|
|
|
it("translates known description codes and wraps unknown values in a semantic key", () => {
|
|
expect(translateIpAddressLogDescription(t, "registration-attempt")).toBe("admin.accounts.ipAddresses.logs.descriptions.registrationAttempt");
|
|
expect(translateIpAddressLogDescription(t, "{empty email}")).toBe("admin.accounts.ipAddresses.logs.descriptions.emptyEmail");
|
|
expect(translateIpAddressLogDescription(t, "custom description")).toBe("admin.accounts.ipAddresses.logs.descriptions.unknownWithValue:custom description");
|
|
expect(translateIpAddressLogDescription(t, null)).toBe("");
|
|
});
|
|
|
|
it("translates known error codes and wraps unknown values in a semantic key", () => {
|
|
expect(translateIpAddressLogError(t, "blacklisted")).toBe("admin.accounts.ipAddresses.errors.blacklisted");
|
|
expect(translateIpAddressLogError(t, "Unauthorized.")).toBe("admin.accounts.ipAddresses.errors.unauthorized");
|
|
expect(translateIpAddressLogError(t, "provider error")).toBe("admin.accounts.ipAddresses.errors.unknownWithValue:provider error");
|
|
});
|
|
});
|