This commit is contained in:
2026-03-13 10:28:10 +08:00
parent f53f43a6b9
commit 4ec09661cd
9 changed files with 1071 additions and 18 deletions

View File

@@ -0,0 +1,147 @@
/**
* Kintone API Integration Tests
* Tests actual API connectivity to verify the client works correctly
*
* Test credentials:
* - Domain: https://alicorn.cybozu.com
* - Username: maxz
* - Password: 7ld7i8vd
*/
import { describe, expect, it, beforeAll, afterAll } from "vitest";
import { SelfKintoneClient, createKintoneClient } from "@main/kintone-api";
import type { DomainWithPassword } from "@shared/types/domain";
// Test configuration
const TEST_CONFIG: DomainWithPassword = {
id: "test-domain-id",
name: "Test Domain",
domain: "alicorn.cybozu.com",
username: "maxz",
password: "7ld7i8vd",
authType: "password",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
describe("SelfKintoneClient - API Integration Tests", () => {
let client: SelfKintoneClient;
beforeAll(() => {
// Create client with test credentials
client = createKintoneClient(TEST_CONFIG);
console.log(`Testing connection to: https://${TEST_CONFIG.domain}`);
});
describe("Connection Tests", () => {
it("should successfully test connection", async () => {
const result = await client.testConnection();
console.log("Test connection result:", result);
expect(result).toBeDefined();
expect(result.success).toBe(true);
expect(result.error).toBeUndefined();
});
it("should return the correct domain", () => {
const domain = client.getDomain();
expect(domain).toBe(TEST_CONFIG.domain);
});
});
describe("Get Apps Tests", () => {
it("should fetch apps successfully", async () => {
const apps = await client.getApps();
console.log(`Fetched ${apps.length} apps`);
if (apps.length > 0) {
console.log("First app:", JSON.stringify(apps[0], null, 2));
}
expect(apps).toBeDefined();
expect(Array.isArray(apps)).toBe(true);
});
it("should fetch apps with pagination (limit=5)", async () => {
const apps = await client.getApps({ limit: 5 });
console.log(`Fetched ${apps.length} apps with limit=5`);
expect(apps).toBeDefined();
expect(Array.isArray(apps)).toBe(true);
expect(apps.length).toBeLessThanOrEqual(5);
});
});
describe("Get App Detail Tests", () => {
let firstAppId: string | null = null;
beforeAll(async () => {
// Get an app ID to test with
const apps = await client.getApps({ limit: 1 });
if (apps.length > 0 && apps[0].appId) {
firstAppId = String(apps[0].appId);
console.log(`Using app ID for detail test: ${firstAppId}`);
}
});
it("should fetch app detail if apps exist", async () => {
if (!firstAppId) {
console.log("Skipping: No apps available to test");
return;
}
const detail = await client.getAppDetail(firstAppId);
console.log("App detail:", JSON.stringify(detail, null, 2).slice(0, 500));
expect(detail).toBeDefined();
expect(detail.appId).toBe(firstAppId);
expect(detail.name).toBeDefined();
expect(detail.customization).toBeDefined();
});
});
describe("Error Handling Tests", () => {
it("should handle invalid credentials gracefully", async () => {
const invalidConfig: DomainWithPassword = {
...TEST_CONFIG,
password: "invalid-password-12345",
};
const invalidClient = createKintoneClient(invalidConfig);
const result = await invalidClient.testConnection();
console.log("Invalid credentials test result:", result);
expect(result.success).toBe(false);
expect(result.error).toBeDefined();
});
it("should handle invalid domain gracefully", async () => {
const invalidConfig: DomainWithPassword = {
...TEST_CONFIG,
domain: "non-existent-domain-12345.cybozu.com",
};
const invalidClient = createKintoneClient(invalidConfig);
const result = await invalidClient.testConnection();
// testConnection catches errors and returns { success: false }
expect(result.success).toBe(false);
expect(result.error).toBeDefined();
});
});
});
describe("Create Kintone Client Factory", () => {
it("should create a client instance", () => {
const client = createKintoneClient(TEST_CONFIG);
expect(client).toBeInstanceOf(SelfKintoneClient);
});
it("should return the correct domain", () => {
const client = createKintoneClient(TEST_CONFIG);
expect(client.getDomain()).toBe(TEST_CONFIG.domain);
});
});