getConnectorCredential, setConnectorCredential and setConnectorCredentialBundle are now plain functions over a SecretStore in packages/agent/src/connectors/connector-credentials.ts. The secret names, metadata layout and the rule that tokens never go into plaintext metadata are unchanged, so existing vault files keep working. A bundle still lands as one update: SecretStore gains writeBatch, which VaultStore applies with a single vault-file replacement. Connector tests seed a Map-backed SecretStore instead of mocking VaultStore methods; the helper tests from core and server moved to the agent package.
122 lines
4.1 KiB
TypeScript
122 lines
4.1 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { JiraConnector } from '../../src/connectors/jira-connector.js';
|
|
import { createMemorySecretStore, type MockSecretStore } from '../helpers/memory-secret-store.js';
|
|
|
|
function createMockVault(opts?: { token?: string; email?: string; baseUrl?: string }): MockSecretStore {
|
|
const secrets: Record<string, string> = {};
|
|
if (opts?.email) secrets['connector:jira:email'] = opts.email;
|
|
if (opts?.baseUrl) secrets['connector:jira:base_url'] = opts.baseUrl;
|
|
return createMemorySecretStore({
|
|
connectors: opts?.token ? { jira: { type: 'bearer', value: opts.token } } : {},
|
|
secrets,
|
|
});
|
|
}
|
|
|
|
describe('JiraConnector', () => {
|
|
let connector: JiraConnector;
|
|
let originalFetch: typeof globalThis.fetch;
|
|
|
|
beforeEach(() => {
|
|
connector = new JiraConnector();
|
|
originalFetch = globalThis.fetch;
|
|
});
|
|
|
|
afterEach(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
it('implements WaggleConnector interface', () => {
|
|
expect(connector.id).toBe('jira');
|
|
expect(connector.name).toBe('Jira');
|
|
expect(connector.actions).toHaveLength(5);
|
|
});
|
|
|
|
it('connect() builds basic auth from email + API token', async () => {
|
|
const vault = createMockVault({
|
|
token: 'jira-api-token',
|
|
email: 'user@example.com',
|
|
baseUrl: 'https://mycompany.atlassian.net',
|
|
});
|
|
await connector.connect(vault);
|
|
expect(vault.get).toHaveBeenCalledWith('connector:jira');
|
|
expect(vault.get).toHaveBeenCalledWith('connector:jira:email');
|
|
});
|
|
|
|
it('healthCheck() returns connected when API responds OK', async () => {
|
|
const vault = createMockVault({
|
|
token: 'jira-api-token',
|
|
email: 'user@example.com',
|
|
baseUrl: 'https://mycompany.atlassian.net',
|
|
});
|
|
await connector.connect(vault);
|
|
|
|
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
ok: true, json: async () => ({ displayName: 'Test User' }),
|
|
}) as unknown as typeof fetch;
|
|
|
|
const health = await connector.healthCheck();
|
|
expect(health.status).toBe('connected');
|
|
});
|
|
|
|
it('execute(create_issue) creates issue', async () => {
|
|
const vault = createMockVault({
|
|
token: 'jira-api-token',
|
|
email: 'user@example.com',
|
|
baseUrl: 'https://mycompany.atlassian.net',
|
|
});
|
|
await connector.connect(vault);
|
|
|
|
const mockIssue = { key: 'PROJ-42', id: '10042' };
|
|
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
ok: true, json: async () => mockIssue,
|
|
}) as unknown as typeof fetch;
|
|
|
|
const result = await connector.execute('create_issue', {
|
|
project: 'PROJ',
|
|
summary: 'Test issue',
|
|
issuetype: 'Bug',
|
|
});
|
|
expect(result.success).toBe(true);
|
|
expect(result.data).toEqual(mockIssue);
|
|
});
|
|
|
|
it('execute(transition_issue) transitions issue', async () => {
|
|
const vault = createMockVault({
|
|
token: 'jira-api-token',
|
|
email: 'user@example.com',
|
|
baseUrl: 'https://mycompany.atlassian.net',
|
|
});
|
|
await connector.connect(vault);
|
|
|
|
// First call: get transitions. Second call: do transition.
|
|
globalThis.fetch = vi.fn()
|
|
.mockResolvedValueOnce({
|
|
ok: true, json: async () => ({ transitions: [{ id: '31', name: 'Done' }, { id: '21', name: 'In Progress' }] }),
|
|
})
|
|
.mockResolvedValueOnce({
|
|
ok: true, json: async () => ({}), text: async () => '',
|
|
}) as unknown as typeof fetch;
|
|
|
|
const result = await connector.execute('transition_issue', {
|
|
issueKey: 'PROJ-42',
|
|
transitionName: 'Done',
|
|
});
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it('execute() returns error when not connected', async () => {
|
|
const result = await connector.execute('list_issues', {});
|
|
expect(result.success).toBe(false);
|
|
expect(result.error).toContain('Not connected');
|
|
});
|
|
|
|
it('toDefinition() maps correctly', () => {
|
|
const def = connector.toDefinition('disconnected');
|
|
expect(def.id).toBe('jira');
|
|
expect(def.status).toBe('disconnected');
|
|
expect(def.tools).toContain('connector_jira_create_issue');
|
|
expect(def.tools).toContain('connector_jira_transition_issue');
|
|
expect(def.tools).toHaveLength(5);
|
|
});
|
|
});
|