Files
redis-gui-foundation/apps/desktop/src/lib/operator-notices.test.ts
Senior Frontend Engineer e83c518081 feat(core): add bounded key creation contract
Expose create_redis_value through the Tauri bridge, add NX-based string creation in redis-core, and surface duplicate-key handling through stable operator notices.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-03-31 10:14:13 +00:00

112 lines
3.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
createAccentNotice,
createNeutralNotice,
toBackendError,
toBackendErrorNotice,
} from "./operator-notices";
describe("operator notices", () => {
it("creates explicit accent notices for successful actions", () => {
expect(createAccentNotice("Saved")).toEqual({
tone: "accent",
message: "Saved",
});
});
it("normalizes unknown thrown values into internal backend errors", () => {
expect(toBackendError(new Error("boom"))).toEqual({
code: "internal",
message: "boom",
detail: null,
});
});
it("maps authentication failures to a consistent operator-facing notice", () => {
expect(
toBackendErrorNotice(
{
code: "authentication_failed",
message: "Authentication failed.",
detail: "WRONGPASS invalid username-password pair",
},
{
operation: "connection_test",
connectionName: "redis-local-fixture",
databaseLabel: "db0",
},
),
).toEqual({
tone: "danger",
message:
"Redis rejected the credentials used while testing redis-local-fixture on db0. Verify username, password, and ACL scope for the selected connection. Backend detail: Authentication failed. (WRONGPASS invalid username-password pair).",
});
});
it("keeps unsupported operations in a non-destructive neutral notice", () => {
expect(
toBackendErrorNotice(
{
code: "unsupported_operation",
message: "Only string replacement is supported in V1.",
detail: null,
},
{
operation: "value_write",
connectionName: "redis-local-fixture",
databaseLabel: "db0",
keyName: "session:42",
},
),
).toEqual(
createNeutralNotice(
"The current desktop contract does not allow saving session:42 on redis-local-fixture / db0 yet. Stay on the visible read-only path or wait for a backend contract change before retrying. Backend detail: Only string replacement is supported in V1.",
),
);
});
it("maps duplicate key creation into a stable neutral notice", () => {
expect(
toBackendErrorNotice(
{
code: "already_exists",
message: "Redis key creation does not overwrite an existing key.",
detail: "key `draft:key` already exists",
},
{
operation: "key_create",
connectionName: "redis-local-fixture",
databaseLabel: "db0",
keyName: "draft:key",
},
),
).toEqual(
createNeutralNotice(
"Redis refused to proceed while creating draft:key on redis-local-fixture / db0 because the key already exists. Choose a new key name or inspect the existing key before retrying. Backend detail: Redis key creation does not overwrite an existing key. (key `draft:key` already exists).",
),
);
});
it("describes command failures with command and scope context", () => {
expect(
toBackendErrorNotice(
{
code: "command_failed",
message: "ERR unknown command 'FOOO'",
detail: null,
},
{
operation: "command_execution",
connectionName: "redis-local-fixture",
databaseLabel: "db0",
commandName: "fooo",
},
),
).toEqual({
tone: "danger",
message:
"Redis returned an error while running FOOO on redis-local-fixture / db0. Adjust the Redis input first; retrying the same command unchanged is unlikely to help. Backend detail: ERR unknown command 'FOOO'.",
});
});
});