96 lines
2.9 KiB
TypeScript
96 lines
2.9 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { CorpConfig } from "../config/types.js";
|
|
import { getNativeSealSession } from "./native.js";
|
|
|
|
describe("getNativeSealSession", () => {
|
|
test("resolves native Seal source session correctly", async () => {
|
|
const corp: CorpConfig = {
|
|
id: "corp-native-1",
|
|
name: "Native Seal Corp",
|
|
environment: "production",
|
|
seal: {
|
|
url: "https://seal.example.com",
|
|
tenantSlug: "native-slug",
|
|
endpoints: {
|
|
approvalStylePreferences: "api/v1/agent/ai-approval/config"
|
|
}
|
|
},
|
|
source: {
|
|
type: "seal",
|
|
token: "bearer-token-native",
|
|
sealUrl: "https://seal.example.com",
|
|
expiresIn: 3600,
|
|
staffId: "staff-123",
|
|
corpId: "corp-native-1"
|
|
},
|
|
auth: {
|
|
refreshTtl: 300
|
|
}
|
|
};
|
|
|
|
const session = await getNativeSealSession(corp);
|
|
expect(session.token).toBe("bearer-token-native");
|
|
expect(session.enterprise).toEqual({
|
|
provider: "seal",
|
|
corpId: "corp-native-1",
|
|
staffId: "staff-123",
|
|
sealUrl: "https://seal.example.com",
|
|
tenantId: undefined,
|
|
tenantSlug: "native-slug",
|
|
tenantName: undefined,
|
|
raw: {
|
|
sourceType: "seal"
|
|
}
|
|
});
|
|
expect(session.expiresAt).toBeGreaterThan(Date.now());
|
|
});
|
|
|
|
test("resolves native seal source session correctly", async () => {
|
|
const corp: CorpConfig = {
|
|
id: "corp-native-1",
|
|
name: "Native Seal Corp",
|
|
environment: "production",
|
|
seal: {
|
|
url: "https://tenant.sealai.cc",
|
|
tenantSlug: "tenant-slug",
|
|
endpoints: {
|
|
approvalStylePreferences: "api/v1/agent/ai-approval/config"
|
|
}
|
|
},
|
|
source: {
|
|
type: "seal",
|
|
token: "bearer-token-native",
|
|
sealUrl: "https://tenant.sealai.cc",
|
|
expiresIn: 7200,
|
|
expiresAt: "2026-09-22T05:30:00Z",
|
|
staffId: "seal-admin",
|
|
tenantId: "tenant-100",
|
|
tenantSlug: "tenant-slug",
|
|
tenantName: "Tenant 100 Name"
|
|
},
|
|
auth: {
|
|
refreshTtl: 300
|
|
}
|
|
};
|
|
|
|
const session = await getNativeSealSession(corp);
|
|
expect(session.token).toBe("bearer-token-native");
|
|
expect(session.enterprise.provider).toBe("seal");
|
|
expect(session.enterprise.tenantId).toBe("tenant-100");
|
|
expect(session.enterprise.tenantName).toBe("Tenant 100 Name");
|
|
expect(session.expiresAt).toBe(new Date("2026-09-22T05:30:00Z").getTime());
|
|
});
|
|
|
|
test("throws error for unsupported source type", async () => {
|
|
const invalidCorp = {
|
|
id: "corp-invalid",
|
|
name: "Invalid",
|
|
seal: { endpoints: { approvalStylePreferences: "" } },
|
|
source: { type: "hose" as const, domain: "https://app.ekuaibao.com", staffId: "a", corpId: "b" },
|
|
auth: { refreshTtl: 300 }
|
|
} as unknown as CorpConfig;
|
|
|
|
expect(getNativeSealSession(invalidCorp)).rejects.toThrow("Unsupported Seal source");
|
|
});
|
|
});
|