| 1 | import { describe, expect, it } from 'vitest';
|
| 2 | import { buildApi } from '../apps/api/src/app.js';
|
| 3 |
|
| 4 | describe('Botpress provider connection API', () => {
|
| 5 | it('issues a pairing code to an owner and accepts an agent-reported profile', async () => {
|
| 6 | const calls: Array<{ name: string; value: unknown }> = [];
|
| 7 | const repository = {
|
| 8 | createProviderConnection: async (owner: string, provider: string, agentName: string) => {
|
| 9 | calls.push({ name: 'create', value: { owner, provider, agentName } });
|
| 10 | return {
|
| 11 | connectionId: 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa',
|
| 12 | provider,
|
| 13 | agentName,
|
| 14 | status: 'pending',
|
| 15 | code: 'oc_bp_pairing-secret',
|
| 16 | expiresAt: new Date(Date.now() + 60_000).toISOString(),
|
| 17 | };
|
| 18 | },
|
| 19 | completeBotpressConnection: async (code: string, value: unknown) => {
|
| 20 | calls.push({ name: 'complete', value: { code, value } });
|
| 21 | return {
|
| 22 | status: 'connected',
|
| 23 | agentId: 'agent-botpress',
|
| 24 | credentialCiphertext: 'encrypted',
|
| 25 | };
|
| 26 | },
|
| 27 | } as any;
|
| 28 | const app = buildApi(undefined, undefined, repository);
|
| 29 | await app.ready();
|
| 30 |
|
| 31 | const start = await app.inject({
|
| 32 | method: 'POST',
|
| 33 | url: '/v0.1/provider-connections/botpress',
|
| 34 | headers: { 'x-openclasp-operator': 'owner-a' },
|
| 35 | payload: { agentName: 'Purchasing agent' },
|
| 36 | });
|
| 37 | expect(start.statusCode).toBe(200);
|
| 38 | expect(start.json()).toMatchObject({ code: 'oc_bp_pairing-secret', status: 'pending' });
|
| 39 |
|
| 40 | const complete = await app.inject({
|
| 41 | method: 'POST',
|
| 42 | url: '/v0.1/provider-connections/botpress/complete',
|
| 43 | headers: { 'x-openclasp-pairing-code': 'oc_bp_pairing-secret' },
|
| 44 | payload: {
|
| 45 | runtimeEndpoint: 'https://webhook.botpress.cloud/example',
|
| 46 | credentialPublicKey: 'public-key',
|
| 47 | profile: {
|
| 48 | description: 'Compares supplier quotes',
|
| 49 | framework: 'Botpress',
|
| 50 | agentVersion: '1.0.0',
|
| 51 | capabilities: ['compare quotes'],
|
| 52 | limitations: ['human approval before payment'],
|
| 53 | },
|
| 54 | },
|
| 55 | });
|
| 56 | expect(complete.statusCode).toBe(200);
|
| 57 | expect(complete.json()).toMatchObject({ status: 'connected', agentId: 'agent-botpress' });
|
| 58 | expect(calls).toHaveLength(2);
|
| 59 | await app.close();
|
| 60 | });
|
| 61 | });
|