Files
SnowLuma/packages/onebot/tests/action-kit-returns-schema.test.ts
T
TanTan fa9c73363d
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
SnowLuma v2.4.2 source snapshot
2026-11-13 09:02:00 +08:00

49 lines
1.7 KiB
TypeScript

// Tests the optional returnsSchema doc metadata: it must round-trip through
// describe() (on both defineAction and the group* presets) and stay absent
// when not provided. Semantics: returnsSchema describes the `data` payload
// inside the OneBot envelope, not the envelope.
import { describe, it, expect } from 'vitest';
import { defineAction, groupAction, f } from '../src/action-kit';
import { okResponse } from '../src/types';
describe('returnsSchema', () => {
const dataSchema = {
type: 'object',
properties: { group_id: { type: 'integer' }, group_name: { type: 'string' } },
required: ['group_id', 'group_name'],
};
it('round-trips returnsSchema through describe() on defineAction', () => {
const spec = defineAction({
name: 'demo_get',
summary: 'demo',
readOnly: true,
returns: '群信息对象',
returnsSchema: dataSchema,
params: { x: f.uint() },
run: () => okResponse({ ok: true }),
});
expect(spec.describe().returnsSchema).toEqual(dataSchema);
expect(spec.describe().returns).toBe('群信息对象');
});
it('omits returnsSchema when not provided', () => {
const spec = defineAction({
name: 'demo_noschema',
params: {},
run: () => okResponse(null),
});
expect(spec.describe().returnsSchema).toBeUndefined();
});
it('carries returnsSchema through groupAction preset', () => {
const spec = groupAction({
name: 'demo_group_get',
readOnly: true,
returnsSchema: dataSchema,
run: () => okResponse({}),
});
expect(spec.describe().returnsSchema).toEqual(dataSchema);
});
});