Skip to content

Commit 1a02a6f

Browse files
committed
Bonus tests: ensure applyDefaults works
1 parent fd5b26e commit 1a02a6f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/client/index.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,70 @@ test('should reject URL-mode elicitation when client only supports form mode', a
839839
await client.close();
840840
});
841841

842+
test('should apply defaults for form-mode elicitation when applyDefaults is enabled', async () => {
843+
const server = new Server(
844+
{
845+
name: 'test server',
846+
version: '1.0'
847+
},
848+
{
849+
capabilities: {
850+
prompts: {},
851+
resources: {},
852+
tools: {},
853+
logging: {}
854+
}
855+
}
856+
);
857+
858+
const client = new Client(
859+
{
860+
name: 'test client',
861+
version: '1.0'
862+
},
863+
{
864+
capabilities: {
865+
elicitation: {
866+
form: {},
867+
applyDefaults: true
868+
}
869+
}
870+
}
871+
);
872+
873+
client.setRequestHandler(ElicitRequestSchema, request => {
874+
expect(request.params.mode).toBe('form');
875+
return {
876+
action: 'accept',
877+
content: {}
878+
};
879+
});
880+
881+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
882+
883+
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
884+
885+
const result = await server.elicitFormInput({
886+
message: 'Please confirm your preferences',
887+
requestedSchema: {
888+
type: 'object',
889+
properties: {
890+
confirmed: {
891+
type: 'boolean',
892+
default: true
893+
}
894+
}
895+
}
896+
});
897+
898+
expect(result.action).toBe('accept');
899+
expect(result.content).toEqual({
900+
confirmed: true
901+
});
902+
903+
await client.close();
904+
});
905+
842906
/***
843907
* Test: Type Checking
844908
* Test that custom request/notification/result schemas can be used with the Client class.

0 commit comments

Comments
 (0)