Skip to content

Commit 70191de

Browse files
committed
test(toolsets): add tests for accountIds constructor option
Add comprehensive tests verifying the new accountIds configuration: - Test initialising with multiple account IDs from constructor - Test default empty array when accountIds not provided - Test coexistence of accountId and accountIds in constructor - Test fetchTools uses constructor accountIds when present - Test setAccounts() overrides constructor accountIds These tests ensure accountIds from the constructor integrates correctly with existing setAccounts() and fetchTools() behaviours.
1 parent dc9f6e5 commit 70191de

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

src/toolsets.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ describe('StackOneToolSet', () => {
8383
expect(toolset.accountIds).toEqual(['account-1', 'account-2']);
8484
});
8585

86+
it('should initialise with multiple account IDs from constructor', () => {
87+
const toolset = new StackOneToolSet({
88+
apiKey: 'custom_key',
89+
accountIds: ['account-1', 'account-2', 'account-3'],
90+
});
91+
92+
// @ts-expect-error - Accessing private property for testing
93+
expect(toolset.accountIds).toEqual(['account-1', 'account-2', 'account-3']);
94+
});
95+
96+
it('should initialise with empty accountIds array when not provided', () => {
97+
const toolset = new StackOneToolSet({ apiKey: 'custom_key' });
98+
99+
// @ts-expect-error - Accessing private property for testing
100+
expect(toolset.accountIds).toEqual([]);
101+
});
102+
103+
it('should allow both accountId and accountIds in constructor', () => {
104+
const toolset = new StackOneToolSet({
105+
apiKey: 'custom_key',
106+
accountId: 'primary-account',
107+
accountIds: ['account-1', 'account-2'],
108+
});
109+
110+
// Single accountId should be set in headers
111+
// @ts-expect-error - Accessing private property for testing
112+
expect(toolset.headers['x-account-id']).toBe('primary-account');
113+
// Multiple accountIds should be stored separately
114+
// @ts-expect-error - Accessing private property for testing
115+
expect(toolset.accountIds).toEqual(['account-1', 'account-2']);
116+
});
117+
86118
it('should set baseUrl from config', () => {
87119
const toolset = new StackOneToolSet({
88120
apiKey: 'custom_key',
@@ -283,6 +315,51 @@ describe('StackOneToolSet', () => {
283315
expect(toolNames).toContain('meta_collect_tool_feedback');
284316
});
285317

318+
it('uses accountIds from constructor when no accountIds provided in fetchTools', async () => {
319+
const toolset = new StackOneToolSet({
320+
baseUrl: 'https://api.stackone-dev.com',
321+
apiKey: 'test-key',
322+
accountIds: ['acc1', 'acc2'],
323+
});
324+
325+
// Fetch without accountIds - should use constructor accountIds
326+
const tools = await toolset.fetchTools();
327+
328+
// Should fetch tools for 2 accounts from constructor
329+
// acc1 has 2 tools, acc2 has 2 tools, + 1 feedback tool = 5
330+
expect(tools.length).toBe(5);
331+
const toolNames = tools.toArray().map((t) => t.name);
332+
expect(toolNames).toContain('acc1_tool_1');
333+
expect(toolNames).toContain('acc1_tool_2');
334+
expect(toolNames).toContain('acc2_tool_1');
335+
expect(toolNames).toContain('acc2_tool_2');
336+
expect(toolNames).toContain('meta_collect_tool_feedback');
337+
});
338+
339+
it('setAccounts overrides constructor accountIds', async () => {
340+
const toolset = new StackOneToolSet({
341+
baseUrl: 'https://api.stackone-dev.com',
342+
apiKey: 'test-key',
343+
accountIds: ['acc1'],
344+
});
345+
346+
// Override with setAccounts
347+
toolset.setAccounts(['acc2', 'acc3']);
348+
349+
// Fetch without accountIds - should use setAccounts, not constructor
350+
const tools = await toolset.fetchTools();
351+
352+
// Should fetch tools for acc2 and acc3 (not acc1)
353+
// acc2 has 2 tools, acc3 has 1 tool, + 1 feedback tool = 4
354+
expect(tools.length).toBe(4);
355+
const toolNames = tools.toArray().map((t) => t.name);
356+
expect(toolNames).not.toContain('acc1_tool_1');
357+
expect(toolNames).toContain('acc2_tool_1');
358+
expect(toolNames).toContain('acc2_tool_2');
359+
expect(toolNames).toContain('acc3_tool_1');
360+
expect(toolNames).toContain('meta_collect_tool_feedback');
361+
});
362+
286363
it('overrides setAccounts when accountIds provided in fetchTools', async () => {
287364
const toolset = new StackOneToolSet({
288365
baseUrl: 'https://api.stackone-dev.com',

0 commit comments

Comments
 (0)