forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient-id-validation.test.ts
More file actions
41 lines (35 loc) · 1.95 KB
/
Copy pathclient-id-validation.test.ts
File metadata and controls
41 lines (35 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { describe, expect, it, vi } from "vitest";
import { AgentClient } from "../src/clients/agent-client";
import { WalletClient } from "../src/clients/wallet-client";
import { PaymentClient } from "../src/clients/payment-client";
import { LilyValidationError } from "../src/errors/sdk-error";
import { createMockHttpClient } from "./helpers/mock-http-client";
describe("client-id-validation", () => {
it("agent.get rejects empty string", () => {
const c = new AgentClient(createMockHttpClient(() => Promise.resolve({ status: 200, headers: new Headers(), data: null })));
expect(() => c.get("")).toThrow(LilyValidationError);
expect(() => c.get(" ")).toThrow(LilyValidationError);
});
it("agent.update rejects empty string", () => {
const c = new AgentClient(createMockHttpClient(() => Promise.resolve({ status: 200, headers: new Headers(), data: null })));
expect(() => c.update("", { name: "x" })).toThrow(LilyValidationError);
});
it("agent.delete rejects empty string", () => {
const c = new AgentClient(createMockHttpClient(() => Promise.resolve({ status: 200, headers: new Headers(), data: null })));
expect(() => c.delete("")).toThrow(LilyValidationError);
});
it("wallet.get rejects empty string", () => {
const c = new WalletClient(createMockHttpClient(() => Promise.resolve({ status: 200, headers: new Headers(), data: null })));
expect(() => c.get("")).toThrow(LilyValidationError);
});
it("payment.get rejects empty string", () => {
const c = new PaymentClient(createMockHttpClient(() => Promise.resolve({ status: 200, headers: new Headers(), data: null })));
expect(() => c.get("")).toThrow(LilyValidationError);
});
it("non-empty ids are unaffected", async () => {
const spy = vi.fn().mockResolvedValue({ status: 200, headers: new Headers(), data: { id: "a1" } });
const c = new AgentClient(createMockHttpClient(spy));
await c.get("agent_123");
expect(spy).toHaveBeenCalledOnce();
});
});