Skip to content

Commit 034b905

Browse files
committed
test(rpc-client): update tests for correct response structure
Update test expectations to match the actual server response structure where `data` is a direct property of the response, not nested under `actionsRpcResponse`. Changes: - Access response.data directly instead of response.actionsRpcResponse - Add explicit assertions for response data content - Rename test to clarify array data handling - Add comments explaining response structure alignment with server
1 parent c3b30e0 commit 034b905

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/rpc-client.spec.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ test('should successfully execute an RPC action', async () => {
1212
path: { id: 'emp-123' },
1313
});
1414

15-
expect(response.actionsRpcResponse).toBeDefined();
16-
expect(response.actionsRpcResponse).toHaveProperty('data');
15+
// Response matches server's ActionsRpcResponseApiModel structure
16+
expect(response).toHaveProperty('data');
17+
expect(response.data).toMatchObject({
18+
id: 'emp-123',
19+
name: 'Test Employee',
20+
});
1721
});
1822

1923
test('should send correct payload structure', async () => {
@@ -29,20 +33,19 @@ test('should send correct payload structure', async () => {
2933
query: { filter: 'active' },
3034
});
3135

32-
expect(response.actionsRpcResponse).toMatchObject({
33-
data: {
34-
action: 'custom_action',
35-
received: {
36-
body: { key: 'value' },
37-
headers: { 'x-custom': 'header' },
38-
path: { id: '123' },
39-
query: { filter: 'active' },
40-
},
36+
// Response matches server's ActionsRpcResponseApiModel structure
37+
expect(response.data).toMatchObject({
38+
action: 'custom_action',
39+
received: {
40+
body: { key: 'value' },
41+
headers: { 'x-custom': 'header' },
42+
path: { id: '123' },
43+
query: { filter: 'active' },
4144
},
4245
});
4346
});
4447

45-
test('should handle list actions', async () => {
48+
test('should handle list actions with array data', async () => {
4649
const client = new RpcClient({
4750
security: { username: 'test-api-key' },
4851
});
@@ -51,12 +54,12 @@ test('should handle list actions', async () => {
5154
action: 'hris_list_employees',
5255
});
5356

54-
expect(response.actionsRpcResponse).toMatchObject({
55-
data: [
56-
{ id: expect.any(String), name: expect.any(String) },
57-
{ id: expect.any(String), name: expect.any(String) },
58-
],
59-
});
57+
// Response data can be an array (matches RpcActionResponseData union type)
58+
expect(Array.isArray(response.data)).toBe(true);
59+
expect(response.data).toMatchObject([
60+
{ id: expect.any(String), name: expect.any(String) },
61+
{ id: expect.any(String), name: expect.any(String) },
62+
]);
6063
});
6164

6265
test('should throw StackOneAPIError on server error', async () => {
@@ -96,5 +99,6 @@ test('should work with only action parameter', async () => {
9699
action: 'simple_action',
97100
});
98101

99-
expect(response.actionsRpcResponse).toBeDefined();
102+
// Response has data field (server returns { data: { action, received } })
103+
expect(response).toHaveProperty('data');
100104
});

src/toolsets/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Arrayable } from 'type-fest';
22
import { createMCPClient } from '../mcp-client';
3-
import { RpcClient, type RpcActionResponse } from '../rpc-client';
3+
import { type RpcActionResponse, RpcClient } from '../rpc-client';
44
import { BaseTool, Tools } from '../tool';
55
import type {
66
ExecuteOptions,

0 commit comments

Comments
 (0)