Files
NapCatQQ/packages/napcat-test/setGroupLeaveDismiss.test.ts
TanTan f954252a34
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
Release Tag / validate-version (push) Waiting to run
NapCatQQ source snapshot
2026-11-13 09:01:47 +08:00

67 lines
2.2 KiB
TypeScript

// StreamBasic must be evaluated before OneBotAction: the two modules import each other,
// and loading OneBotAction first leaves BasicStream extending an uninitialized binding.
import '../napcat-onebot/action/stream/StreamBasic';
import { describe, expect, test, vi } from 'vitest';
import SetGroupLeave from '../napcat-onebot/action/group/SetGroupLeave';
function createAction () {
const quitGroup = vi.fn().mockResolvedValue(undefined);
const destroyGroup = vi.fn().mockResolvedValue(undefined);
const action = new SetGroupLeave(
undefined as never,
{
apis: {
GroupApi: { quitGroup, destroyGroup },
},
} as never
);
return { action, quitGroup, destroyGroup };
}
describe('set_group_leave is_dismiss', () => {
test('leaves the group when is_dismiss is absent', async () => {
const { action, quitGroup, destroyGroup } = createAction();
await action._handle({ group_id: '123' });
expect(quitGroup).toHaveBeenCalledWith('123');
expect(destroyGroup).not.toHaveBeenCalled();
});
test('leaves the group when is_dismiss is false', async () => {
const { action, quitGroup, destroyGroup } = createAction();
await action._handle({ group_id: '123', is_dismiss: false });
expect(quitGroup).toHaveBeenCalledWith('123');
expect(destroyGroup).not.toHaveBeenCalled();
});
test("leaves the group when is_dismiss is the string 'false'", async () => {
const { action, quitGroup, destroyGroup } = createAction();
await action._handle({ group_id: '123', is_dismiss: 'false' });
expect(quitGroup).toHaveBeenCalledWith('123');
expect(destroyGroup).not.toHaveBeenCalled();
});
test('destroys the group when is_dismiss is true', async () => {
const { action, quitGroup, destroyGroup } = createAction();
await action._handle({ group_id: '123', is_dismiss: true });
expect(destroyGroup).toHaveBeenCalledWith('123');
expect(quitGroup).not.toHaveBeenCalled();
});
test("destroys the group when is_dismiss is the string 'true'", async () => {
const { action, quitGroup, destroyGroup } = createAction();
await action._handle({ group_id: '123', is_dismiss: 'true' });
expect(destroyGroup).toHaveBeenCalledWith('123');
expect(quitGroup).not.toHaveBeenCalled();
});
});