users.test.ts
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { describe, it, expect } from 'vitest';
import { usersApi } from './users';
import { BizError } from './errors';
describe('usersApi', () => {
it('list returns PageResult with records', async () => {
const result = await usersApi.list();
expect(result.total).toBeGreaterThan(0);
expect(result.records[0].username).toBeDefined();
expect(result.page).toBe(1);
});
it('list with queryField=username queryValue=ali returns filtered results', async () => {
const result = await usersApi.list({ queryField: 'username', queryValue: 'ali' });
expect(result.total).toBe(1);
expect(result.records[0].username).toBe('alice');
});
it('get returns UserDetail', async () => {
const detail = await usersApi.get(1);
expect(detail.userId).toBe(1);
expect(detail.permissionCategoryIds).toEqual([1, 2]);
});
it('get unknown userId throws BizError 40401', async () => {
await expect(usersApi.get(99999)).rejects.toMatchObject({ code: 40401 });
});
it('create returns CreateUserVo on success', async () => {
const vo = await usersApi.create({
username: 'newbie',
userCode: 'U010',
userType: 'NORMAL',
language: 'zh-CN',
canEditDocument: false,
});
expect(vo.userId).toBe(42);
expect(vo.username).toBe('newbie');
});
it('create with duplicate username throws BizError 40901', async () => {
await expect(
usersApi.create({
username: 'dup',
userCode: 'U011',
userType: 'NORMAL',
language: 'zh-CN',
canEditDocument: false,
}),
).rejects.toMatchObject({ code: 40901 });
});
it('update returns UserDetail with patched fields', async () => {
const detail = await usersApi.update(1, { userCode: 'U_NEW' });
expect(detail.userCode).toBe('U_NEW');
});
});