Skip to content

Commit 67df815

Browse files
committed
Add tests, fix existing tests
1 parent 2629418 commit 67df815

File tree

8 files changed

+588
-56
lines changed

8 files changed

+588
-56
lines changed

packages/b2c-cli/test/commands/docs/search.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('docs search', () => {
4343
const listStub = sinon.stub().returns([{id: 'a', title: 'A', filePath: 'a.md'}]);
4444
command.operations = {...command.operations, listDocs: listStub};
4545

46-
const result = await runSilent(() => command.run());
46+
const result = (await runSilent(() => command.run())) as {entries: unknown[]};
4747

4848
expect(result.entries).to.have.length(1);
4949
});
@@ -69,7 +69,7 @@ describe('docs search', () => {
6969
const searchStub = sinon.stub().returns([{entry: {id: 'a', title: 'A', filePath: 'a.md'}, score: 0.1}]);
7070
command.operations = {...command.operations, searchDocs: searchStub};
7171

72-
const result = await runSilent(() => command.run());
72+
const result = (await runSilent(() => command.run())) as {results: unknown[]};
7373

7474
expect(result.results).to.have.length(1);
7575
});

packages/b2c-cli/test/commands/ecdn/security/get.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ describe('ecdn security get', () => {
9898
}),
9999
});
100100

101-
const result = await runSilent(() => command.run());
101+
const result = (await runSilent(() => command.run())) as {
102+
settings: {securityLevel: string; wafEnabled: boolean};
103+
};
102104

103105
expect(result.settings.securityLevel).to.equal('high');
104106
expect(result.settings.wafEnabled).to.be.true;

packages/b2c-cli/test/commands/ecdn/zones/list.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ describe('ecdn zones list', () => {
129129
}),
130130
});
131131

132-
const result = await runSilent(() => command.run());
132+
const result = (await runSilent(() => command.run())) as {
133+
total: number;
134+
zones: Array<{name: string}>;
135+
};
133136

134137
expect(result).to.have.property('total', 1);
135138
expect(result.zones).to.have.lengthOf(1);

packages/b2c-dx-mcp/src/commands/mcp.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';
148148
import {B2CDxMcpServer} from '../server.js';
149149
import {Services} from '../services.js';
150150
import {registerToolsets} from '../registry.js';
151-
import {TOOLSETS, type StartupFlags, loadAppInsightsKey} from '../utils/index.js';
151+
import {APPLICATION_INSIGHTS_CONNECTION_STRING} from '../config.js';
152+
import {TOOLSETS, type StartupFlags} from '../utils/index.js';
152153

153154
/**
154155
* oclif Command that starts the B2C DX MCP server.
@@ -292,7 +293,7 @@ export default class McpServerCommand extends BaseCommand<typeof McpServerComman
292293
if (process.env.SFCC_TELEMETRY !== 'false') {
293294
telemetry = createTelemetry({
294295
project: 'b2c-dx-mcp',
295-
appInsightsKey: loadAppInsightsKey(),
296+
appInsightsKey: APPLICATION_INSIGHTS_CONNECTION_STRING,
296297
version: this.config.version,
297298
initialAttributes: {
298299
toolsets: (startupFlags.toolsets ?? []).join(', '),

packages/b2c-dx-mcp/src/utils/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
66

7-
import {APPLICATION_INSIGHTS_CONNECTION_STRING} from '../config.js';
8-
97
/**
108
* Utility modules for the B2C DX MCP server.
119
*
@@ -17,11 +15,3 @@ import {APPLICATION_INSIGHTS_CONNECTION_STRING} from '../config.js';
1715
// output needs .js extensions to work at runtime with Node.js ESM.
1816
export * from './constants.js';
1917
export * from './types.js';
20-
21-
/**
22-
* Load the Application Insights connection string.
23-
* @returns The connection string or undefined if not configured
24-
*/
25-
export function loadAppInsightsKey(): string | undefined {
26-
return APPLICATION_INSIGHTS_CONNECTION_STRING;
27-
}

packages/b2c-dx-mcp/test/server.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ describe('B2CDxMcpServer', () => {
143143
expect(server).to.be.instanceOf(B2CDxMcpServer);
144144
});
145145

146+
it('should call telemetry.start() before passing to server (simulated lifecycle)', async () => {
147+
// This test verifies the expected telemetry lifecycle:
148+
// 1. Create telemetry instance
149+
// 2. Call telemetry.start() to initialize the reporter
150+
// 3. Pass started telemetry to server
151+
const mockTelemetry = new MockTelemetry();
152+
153+
// Verify telemetry is not started initially
154+
expect(mockTelemetry.started).to.be.false;
155+
156+
// Simulate what mcp.ts does: start telemetry before creating server
157+
await mockTelemetry.start();
158+
expect(mockTelemetry.started).to.be.true;
159+
160+
// Now pass to server (as mcp.ts does)
161+
const server = new B2CDxMcpServer(
162+
{name: 'test-server', version: '1.0.0'},
163+
{telemetry: mockTelemetry as unknown as Telemetry},
164+
);
165+
166+
expect(server).to.be.instanceOf(B2CDxMcpServer);
167+
expect(mockTelemetry.started).to.be.true;
168+
});
169+
146170
it('should create server without options (no telemetry)', () => {
147171
const server = new B2CDxMcpServer({name: 'test-server', version: '1.0.0'});
148172

packages/b2c-dx-mcp/test/utils/index.test.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)