|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { z } from "zod"; |
| 3 | +import { |
| 4 | + isAliFullStackProEnabled, |
| 5 | + hasAliFullStackProKey, |
| 6 | + ChatSummarySchema, |
| 7 | + AppSearchResultSchema, |
| 8 | +} from "./schemas"; |
| 9 | + |
| 10 | +describe("isAliFullStackProEnabled", () => { |
| 11 | + it("returns false when enableAliFullStackPro is false", () => { |
| 12 | + const settings = { |
| 13 | + enableAliFullStackPro: false, |
| 14 | + providerSettings: { auto: { apiKey: { value: "key" } } }, |
| 15 | + } as any; |
| 16 | + expect(isAliFullStackProEnabled(settings)).toBe(false); |
| 17 | + }); |
| 18 | + |
| 19 | + it("returns false when enableAliFullStackPro is undefined", () => { |
| 20 | + const settings = { |
| 21 | + providerSettings: { auto: { apiKey: { value: "key" } } }, |
| 22 | + } as any; |
| 23 | + expect(isAliFullStackProEnabled(settings)).toBe(false); |
| 24 | + }); |
| 25 | + |
| 26 | + it("returns false when apiKey is missing", () => { |
| 27 | + const settings = { |
| 28 | + enableAliFullStackPro: true, |
| 29 | + providerSettings: { auto: { apiKey: {} } }, |
| 30 | + } as any; |
| 31 | + expect(isAliFullStackProEnabled(settings)).toBe(false); |
| 32 | + }); |
| 33 | + |
| 34 | + it("returns true when enabled and apiKey exists", () => { |
| 35 | + const settings = { |
| 36 | + enableAliFullStackPro: true, |
| 37 | + providerSettings: { auto: { apiKey: { value: "key" } } }, |
| 38 | + } as any; |
| 39 | + expect(isAliFullStackProEnabled(settings)).toBe(true); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +describe("hasAliFullStackProKey", () => { |
| 44 | + it("returns true when apiKey value is present", () => { |
| 45 | + const settings = { |
| 46 | + providerSettings: { auto: { apiKey: { value: "key" } } }, |
| 47 | + } as any; |
| 48 | + expect(hasAliFullStackProKey(settings)).toBe(true); |
| 49 | + }); |
| 50 | + |
| 51 | + it("returns false when providerSettings is missing", () => { |
| 52 | + const settings = {} as any; |
| 53 | + expect(hasAliFullStackProKey(settings)).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it("returns false when apiKey is empty string", () => { |
| 57 | + const settings = { |
| 58 | + providerSettings: { auto: { apiKey: { value: "" } } }, |
| 59 | + } as any; |
| 60 | + expect(hasAliFullStackProKey(settings)).toBe(false); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +describe("Zod schemas", () => { |
| 65 | + it("ChatSummarySchema parses valid data", () => { |
| 66 | + const data = { |
| 67 | + id: 1, |
| 68 | + appId: 2, |
| 69 | + title: "Test Chat", |
| 70 | + createdAt: new Date(), |
| 71 | + }; |
| 72 | + expect(() => ChatSummarySchema.parse(data)).not.toThrow(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("ChatSummarySchema rejects missing id", () => { |
| 76 | + expect(() => |
| 77 | + ChatSummarySchema.parse({ |
| 78 | + appId: 2, |
| 79 | + title: "Test", |
| 80 | + createdAt: new Date(), |
| 81 | + }), |
| 82 | + ).toThrow(); |
| 83 | + }); |
| 84 | + |
| 85 | + it("AppSearchResultSchema parses valid data", () => { |
| 86 | + const data = { |
| 87 | + id: 1, |
| 88 | + name: "My App", |
| 89 | + createdAt: new Date(), |
| 90 | + matchedChatTitle: null, |
| 91 | + matchedChatMessage: null, |
| 92 | + }; |
| 93 | + expect(() => AppSearchResultSchema.parse(data)).not.toThrow(); |
| 94 | + }); |
| 95 | +}); |
0 commit comments