|
7 | 7 | import {expect} from 'chai'; |
8 | 8 | import {z} from 'zod'; |
9 | 9 | import {B2CDxMcpServer} from '../src/server.js'; |
| 10 | +import type {Telemetry} from '@salesforce/b2c-tooling-sdk/telemetry'; |
| 11 | + |
| 12 | +/** |
| 13 | + * Mock telemetry for testing. |
| 14 | + */ |
| 15 | +class MockTelemetry { |
| 16 | + public attributes: Record<string, unknown> = {}; |
| 17 | + public events: Array<{name: string; attributes: Record<string, unknown>}> = []; |
| 18 | + public started = false; |
| 19 | + public stopped = false; |
| 20 | + |
| 21 | + addAttributes(attrs: Record<string, unknown>): void { |
| 22 | + this.attributes = {...this.attributes, ...attrs}; |
| 23 | + } |
| 24 | + |
| 25 | + sendEvent(name: string, attributes: Record<string, unknown> = {}): void { |
| 26 | + this.events.push({name, attributes}); |
| 27 | + } |
| 28 | + |
| 29 | + async start(): Promise<void> { |
| 30 | + this.started = true; |
| 31 | + } |
| 32 | + |
| 33 | + stop(): void { |
| 34 | + this.stopped = true; |
| 35 | + } |
| 36 | +} |
10 | 37 |
|
11 | 38 | // Handlers extracted to module scope to reduce callback nesting depth |
12 | 39 | const simpleHandler = async () => ({content: [{type: 'text' as const, text: 'ok'}]}); |
@@ -79,4 +106,30 @@ describe('B2CDxMcpServer', () => { |
79 | 106 | expect(server.isConnected()).to.be.false; |
80 | 107 | }); |
81 | 108 | }); |
| 109 | + |
| 110 | + describe('telemetry integration', () => { |
| 111 | + it('should accept telemetry in options', () => { |
| 112 | + const mockTelemetry = new MockTelemetry(); |
| 113 | + |
| 114 | + const server = new B2CDxMcpServer( |
| 115 | + {name: 'test-server', version: '1.0.0'}, |
| 116 | + {telemetry: mockTelemetry as unknown as Telemetry}, |
| 117 | + ); |
| 118 | + |
| 119 | + expect(server).to.be.instanceOf(B2CDxMcpServer); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should work without telemetry (telemetry disabled)', () => { |
| 123 | + // When telemetry is undefined, server should still work |
| 124 | + const server = new B2CDxMcpServer({name: 'test-server', version: '1.0.0'}, {telemetry: undefined}); |
| 125 | + |
| 126 | + expect(server).to.be.instanceOf(B2CDxMcpServer); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should create server without options (no telemetry)', () => { |
| 130 | + const server = new B2CDxMcpServer({name: 'test-server', version: '1.0.0'}); |
| 131 | + |
| 132 | + expect(server).to.be.instanceOf(B2CDxMcpServer); |
| 133 | + }); |
| 134 | + }); |
82 | 135 | }); |
0 commit comments