125 lines
3.4 KiB
TypeScript
125 lines
3.4 KiB
TypeScript
/**
|
|
* Server Connection E2E Tests
|
|
*
|
|
* Tests for gRPC server connection management.
|
|
*/
|
|
|
|
/// <reference path="./globals.d.ts" />
|
|
|
|
import { executeInApp, waitForAppReady } from './fixtures';
|
|
|
|
describe('Server Connection', () => {
|
|
before(async () => {
|
|
await waitForAppReady();
|
|
});
|
|
|
|
describe('isConnected', () => {
|
|
it('should return connection status', async () => {
|
|
const result = await executeInApp<{ success?: boolean; connected?: boolean; error?: string }>({
|
|
type: 'isConnected',
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(typeof result.connected).toBe('boolean');
|
|
});
|
|
});
|
|
|
|
describe('getServerInfo', () => {
|
|
it('should return server information when connected', async () => {
|
|
const result = await executeInApp<{ success?: boolean; info?: Record<string, unknown>; error?: string }>({
|
|
type: 'getServerInfo',
|
|
});
|
|
|
|
expect(result).toBeDefined();
|
|
if (result.success) {
|
|
expect(result.info).toHaveProperty('version');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('connect', () => {
|
|
it('should connect to server with default URL', async () => {
|
|
const result = await executeInApp<{ success?: boolean; info?: Record<string, unknown>; error?: string }>({
|
|
type: 'connectDefault',
|
|
});
|
|
|
|
expect(result).toBeDefined();
|
|
// May fail if server not running, but should not crash
|
|
});
|
|
|
|
it('should handle invalid server URL gracefully', async () => {
|
|
const result = await executeInApp<{ success?: boolean; error?: string }>({
|
|
type: 'connect',
|
|
serverUrl: 'http://invalid-server:12345',
|
|
});
|
|
|
|
// Should fail for invalid server
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Identity', () => {
|
|
before(async () => {
|
|
await waitForAppReady();
|
|
});
|
|
|
|
describe('getCurrentUser', () => {
|
|
it('should return current user info', async () => {
|
|
const result = await executeInApp<{ success?: boolean; user?: Record<string, unknown>; error?: string }>({
|
|
type: 'getCurrentUser',
|
|
});
|
|
|
|
expect(result).toBeDefined();
|
|
if (result.success) {
|
|
if ('user' in result) {
|
|
expect(result).toHaveProperty('user');
|
|
} else {
|
|
expect(result).toHaveProperty('user_id');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('listWorkspaces', () => {
|
|
it('should list available workspaces', async () => {
|
|
const result = await executeInApp<{
|
|
success?: boolean;
|
|
workspaces?: unknown[];
|
|
error?: string;
|
|
}>({ type: 'listWorkspaces' });
|
|
|
|
expect(result).toBeDefined();
|
|
if (result.success) {
|
|
expect(result).toHaveProperty('workspaces');
|
|
expect(Array.isArray(result.workspaces)).toBe(true);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Projects', () => {
|
|
before(async () => {
|
|
await waitForAppReady();
|
|
});
|
|
|
|
describe('listProjects', () => {
|
|
it('should list projects', async () => {
|
|
const workspaces = await executeInApp<{ workspaces?: Array<{ id: string }>; error?: string }>({
|
|
type: 'listWorkspaces',
|
|
});
|
|
if (!workspaces?.workspaces?.length) {
|
|
return;
|
|
}
|
|
const result = await executeInApp<{ success?: boolean; error?: string }>({
|
|
type: 'listProjects',
|
|
workspaceId: workspaces.workspaces[0].id,
|
|
includeArchived: false,
|
|
limit: 10,
|
|
});
|
|
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|
|
});
|