feat(onebot): accept join question and answer on set_group_add_option
add_type 4 takes group_question and group_answer. add_type 5 (and 55) takes group_question. get_group_admin_settings also returns both. Fixes #383
This commit is contained in:
8 files changed
+148
-9
No files matched your search
@@ -454,18 +454,18 @@ describe('set_group_add_option parse', () => {
|
||||
it('defaults add_type to 0 and keeps a present 0', () => {
|
||||
expect(setGroupAddOption.parse({ group_id: 12345 })).toEqual({
|
||||
ok: true,
|
||||
value: { group_id: 12345, add_type: 0 },
|
||||
value: { group_id: 12345, add_type: 0, group_question: undefined, group_answer: undefined },
|
||||
});
|
||||
expect(setGroupAddOption.parse({ group_id: 12345, add_type: 0 })).toEqual({
|
||||
ok: true,
|
||||
value: { group_id: 12345, add_type: 0 },
|
||||
value: { group_id: 12345, add_type: 0, group_question: undefined, group_answer: undefined },
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts a positive add_type and rejects a negative one', () => {
|
||||
expect(setGroupAddOption.parse({ group_id: 12345, add_type: '2' })).toEqual({
|
||||
ok: true,
|
||||
value: { group_id: 12345, add_type: 2 },
|
||||
value: { group_id: 12345, add_type: 2, group_question: undefined, group_answer: undefined },
|
||||
});
|
||||
expect(setGroupAddOption.parse({ group_id: 12345, add_type: -1 })).toEqual({
|
||||
ok: false,
|
||||
@@ -473,6 +473,23 @@ describe('set_group_add_option parse', () => {
|
||||
reason: 'must be >= 0',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps optional question and answer when present', () => {
|
||||
expect(setGroupAddOption.parse({
|
||||
group_id: 12345,
|
||||
add_type: 4,
|
||||
group_question: 'q',
|
||||
group_answer: 'a',
|
||||
})).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
group_id: 12345,
|
||||
add_type: 4,
|
||||
group_question: 'q',
|
||||
group_answer: 'a',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('set_group_add_option toHandler', () => {
|
||||
@@ -483,7 +500,7 @@ describe('set_group_add_option toHandler', () => {
|
||||
await expect(setGroupAddOption.toHandler(ctx)({ group_id: 12345 }))
|
||||
.resolves.toEqual({ status: 'ok', retcode: 0, data: null });
|
||||
|
||||
expect(setAddOption.mock.calls).toEqual([[12345, 0]]);
|
||||
expect(setAddOption.mock.calls).toEqual([[12345, 0, undefined, undefined]]);
|
||||
});
|
||||
|
||||
it('forwards an explicit add_type', async () => {
|
||||
@@ -495,7 +512,21 @@ describe('set_group_add_option toHandler', () => {
|
||||
add_type: 3,
|
||||
})).resolves.toEqual({ status: 'ok', retcode: 0, data: null });
|
||||
|
||||
expect(setAddOption.mock.calls).toEqual([[941657197, 3]]);
|
||||
expect(setAddOption.mock.calls).toEqual([[941657197, 3, undefined, undefined]]);
|
||||
});
|
||||
|
||||
it('forwards question and answer', async () => {
|
||||
const setAddOption = vi.fn(async () => {});
|
||||
const { ctx } = adminCtx({ setAddOption });
|
||||
|
||||
await expect(setGroupAddOption.toHandler(ctx)({
|
||||
group_id: 941657197,
|
||||
add_type: 4,
|
||||
group_question: 'q',
|
||||
group_answer: 'a',
|
||||
})).resolves.toEqual({ status: 'ok', retcode: 0, data: null });
|
||||
|
||||
expect(setAddOption.mock.calls).toEqual([[941657197, 4, 'q', 'a']]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -780,6 +811,8 @@ describe('get_group_admin_settings toHandler', () => {
|
||||
it('forwards group_id and returns the current settings', async () => {
|
||||
const settings = {
|
||||
add_type: 2,
|
||||
group_question: 'q',
|
||||
group_answer: 'a',
|
||||
robot_member_switch: 1,
|
||||
robot_member_examine: 0,
|
||||
member_invite_policy: 'require_approval',
|
||||
|
||||
Reference in new issue
Block a user