@nexical/cli 0.1.7 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/deploy.yml +3 -3
- package/README.md +317 -104
- package/dist/chunk-JYASTIIW.js +42 -0
- package/dist/chunk-JYASTIIW.js.map +1 -0
- package/dist/chunk-LZ3YQWAR.js +2204 -0
- package/dist/chunk-LZ3YQWAR.js.map +1 -0
- package/dist/chunk-OKXOCNXP.js +105 -0
- package/dist/chunk-OKXOCNXP.js.map +1 -0
- package/dist/chunk-OYFWMYPG.js +52 -0
- package/dist/chunk-OYFWMYPG.js.map +1 -0
- package/dist/chunk-WKERTCM6.js +74 -0
- package/dist/chunk-WKERTCM6.js.map +1 -0
- package/dist/index.js +32 -5
- package/dist/index.js.map +1 -1
- package/dist/src/commands/init.d.ts +11 -0
- package/dist/src/commands/init.js +88 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/module/add.d.ts +14 -0
- package/dist/src/commands/module/add.js +136 -0
- package/dist/src/commands/module/add.js.map +1 -0
- package/dist/src/commands/module/list.d.ts +10 -0
- package/dist/src/commands/module/list.js +73 -0
- package/dist/src/commands/module/list.js.map +1 -0
- package/dist/src/commands/module/remove.d.ts +12 -0
- package/dist/src/commands/module/remove.js +71 -0
- package/dist/src/commands/module/remove.js.map +1 -0
- package/dist/src/commands/module/update.d.ts +11 -0
- package/dist/src/commands/module/update.js +52 -0
- package/dist/src/commands/module/update.js.map +1 -0
- package/dist/src/commands/run.d.ts +11 -0
- package/dist/src/commands/run.js +93 -0
- package/dist/src/commands/run.js.map +1 -0
- package/dist/src/utils/discovery.d.ts +13 -0
- package/dist/src/utils/discovery.js +9 -0
- package/dist/src/utils/git.d.ts +16 -0
- package/dist/src/utils/git.js +29 -0
- package/dist/src/utils/git.js.map +1 -0
- package/dist/src/utils/url-resolver.d.ts +15 -0
- package/dist/src/utils/url-resolver.js +9 -0
- package/dist/src/utils/url-resolver.js.map +1 -0
- package/index.ts +29 -5
- package/package.json +33 -31
- package/src/commands/init.ts +85 -0
- package/src/commands/module/add.ts +169 -0
- package/src/commands/module/list.ts +69 -0
- package/src/commands/module/remove.ts +74 -0
- package/src/commands/module/update.ts +50 -0
- package/src/commands/run.ts +98 -0
- package/src/utils/discovery.ts +134 -0
- package/src/utils/git.ts +65 -0
- package/src/utils/url-resolver.ts +57 -0
- package/test/e2e/lifecycle.e2e.test.ts +152 -0
- package/test/integration/commands/init.integration.test.ts +82 -0
- package/test/integration/commands/module.integration.test.ts +144 -0
- package/test/integration/commands/run.integration.test.ts +90 -0
- package/test/integration/utils/command-loading.integration.test.ts +80 -0
- package/test/unit/commands/init.test.ts +153 -0
- package/test/unit/commands/module/add.test.ts +262 -0
- package/test/unit/commands/module/list.test.ts +115 -0
- package/test/unit/commands/module/remove.test.ts +89 -0
- package/test/unit/commands/module/update.test.ts +91 -0
- package/test/unit/commands/run.test.ts +252 -0
- package/test/unit/utils/command-discovery.test.ts +176 -0
- package/test/unit/utils/git.test.ts +152 -0
- package/test/unit/utils/integration-helpers.test.ts +72 -0
- package/test/unit/utils/url-resolver.test.ts +39 -0
- package/test/utils/integration-helpers.ts +66 -0
- package/vitest.e2e.config.ts +0 -1
- package/dist/chunk-JDRAVUKK.js +0 -48
- package/dist/chunk-JDRAVUKK.js.map +0 -1
- package/dist/src/commands/admin/create-user.d.ts +0 -15
- package/dist/src/commands/admin/create-user.js +0 -49
- package/dist/src/commands/admin/create-user.js.map +0 -1
- package/dist/src/commands/branch/create.d.ts +0 -19
- package/dist/src/commands/branch/create.js +0 -59
- package/dist/src/commands/branch/create.js.map +0 -1
- package/dist/src/commands/branch/delete.d.ts +0 -15
- package/dist/src/commands/branch/delete.js +0 -50
- package/dist/src/commands/branch/delete.js.map +0 -1
- package/dist/src/commands/branch/get.d.ts +0 -15
- package/dist/src/commands/branch/get.js +0 -53
- package/dist/src/commands/branch/get.js.map +0 -1
- package/dist/src/commands/branch/list.d.ts +0 -15
- package/dist/src/commands/branch/list.js +0 -51
- package/dist/src/commands/branch/list.js.map +0 -1
- package/dist/src/commands/job/get.d.ts +0 -15
- package/dist/src/commands/job/get.js +0 -62
- package/dist/src/commands/job/get.js.map +0 -1
- package/dist/src/commands/job/list.d.ts +0 -15
- package/dist/src/commands/job/list.js +0 -57
- package/dist/src/commands/job/list.js.map +0 -1
- package/dist/src/commands/job/logs.d.ts +0 -15
- package/dist/src/commands/job/logs.js +0 -67
- package/dist/src/commands/job/logs.js.map +0 -1
- package/dist/src/commands/job/trigger.d.ts +0 -19
- package/dist/src/commands/job/trigger.js +0 -74
- package/dist/src/commands/job/trigger.js.map +0 -1
- package/dist/src/commands/login.d.ts +0 -8
- package/dist/src/commands/login.js +0 -31
- package/dist/src/commands/login.js.map +0 -1
- package/dist/src/commands/project/create.d.ts +0 -24
- package/dist/src/commands/project/create.js +0 -63
- package/dist/src/commands/project/create.js.map +0 -1
- package/dist/src/commands/project/delete.d.ts +0 -20
- package/dist/src/commands/project/delete.js +0 -58
- package/dist/src/commands/project/delete.js.map +0 -1
- package/dist/src/commands/project/get.d.ts +0 -15
- package/dist/src/commands/project/get.js +0 -49
- package/dist/src/commands/project/get.js.map +0 -1
- package/dist/src/commands/project/list.d.ts +0 -15
- package/dist/src/commands/project/list.js +0 -45
- package/dist/src/commands/project/list.js.map +0 -1
- package/dist/src/commands/project/update.d.ts +0 -19
- package/dist/src/commands/project/update.js +0 -66
- package/dist/src/commands/project/update.js.map +0 -1
- package/dist/src/commands/team/create.d.ts +0 -19
- package/dist/src/commands/team/create.js +0 -45
- package/dist/src/commands/team/create.js.map +0 -1
- package/dist/src/commands/team/delete.d.ts +0 -20
- package/dist/src/commands/team/delete.js +0 -52
- package/dist/src/commands/team/delete.js.map +0 -1
- package/dist/src/commands/team/get.d.ts +0 -15
- package/dist/src/commands/team/get.js +0 -42
- package/dist/src/commands/team/get.js.map +0 -1
- package/dist/src/commands/team/list.d.ts +0 -8
- package/dist/src/commands/team/list.js +0 -30
- package/dist/src/commands/team/list.js.map +0 -1
- package/dist/src/commands/team/member/invite.d.ts +0 -20
- package/dist/src/commands/team/member/invite.js +0 -54
- package/dist/src/commands/team/member/invite.js.map +0 -1
- package/dist/src/commands/team/member/remove.d.ts +0 -15
- package/dist/src/commands/team/member/remove.js +0 -43
- package/dist/src/commands/team/member/remove.js.map +0 -1
- package/dist/src/commands/team/update.d.ts +0 -19
- package/dist/src/commands/team/update.js +0 -55
- package/dist/src/commands/team/update.js.map +0 -1
- package/dist/src/commands/token/generate.d.ts +0 -19
- package/dist/src/commands/token/generate.js +0 -48
- package/dist/src/commands/token/generate.js.map +0 -1
- package/dist/src/commands/token/list.d.ts +0 -8
- package/dist/src/commands/token/list.js +0 -31
- package/dist/src/commands/token/list.js.map +0 -1
- package/dist/src/commands/token/revoke.d.ts +0 -15
- package/dist/src/commands/token/revoke.js +0 -38
- package/dist/src/commands/token/revoke.js.map +0 -1
- package/dist/src/commands/whoami.d.ts +0 -8
- package/dist/src/commands/whoami.js +0 -26
- package/dist/src/commands/whoami.js.map +0 -1
- package/dist/src/utils/nexical-client.d.ts +0 -10
- package/dist/src/utils/nexical-client.js +0 -12
- package/src/commands/admin/create-user.ts +0 -46
- package/src/commands/branch/create.ts +0 -57
- package/src/commands/branch/delete.ts +0 -47
- package/src/commands/branch/get.ts +0 -50
- package/src/commands/branch/list.ts +0 -50
- package/src/commands/job/get.ts +0 -59
- package/src/commands/job/list.ts +0 -56
- package/src/commands/job/logs.ts +0 -67
- package/src/commands/job/trigger.ts +0 -73
- package/src/commands/login.ts +0 -31
- package/src/commands/project/create.ts +0 -61
- package/src/commands/project/delete.ts +0 -56
- package/src/commands/project/get.ts +0 -46
- package/src/commands/project/list.ts +0 -44
- package/src/commands/project/update.ts +0 -63
- package/src/commands/team/create.ts +0 -43
- package/src/commands/team/delete.ts +0 -50
- package/src/commands/team/get.ts +0 -39
- package/src/commands/team/list.ts +0 -26
- package/src/commands/team/member/invite.ts +0 -56
- package/src/commands/team/member/remove.ts +0 -40
- package/src/commands/team/update.ts +0 -53
- package/src/commands/token/generate.ts +0 -45
- package/src/commands/token/list.ts +0 -27
- package/src/commands/token/revoke.ts +0 -35
- package/src/commands/whoami.ts +0 -21
- package/src/utils/nexical-client.ts +0 -47
- package/test/e2e/auth.e2e.test.ts +0 -46
- package/test/e2e/job-workflow.e2e.test.ts +0 -33
- package/test/e2e/project-lifecycle.e2e.test.ts +0 -48
- package/test/e2e/setup.ts +0 -237
- package/test/e2e/utils.ts +0 -33
- package/test/integration/commands/admin/create-user.test.ts +0 -51
- package/test/integration/commands/branch/create.test.ts +0 -51
- package/test/integration/commands/branch/delete.test.ts +0 -43
- package/test/integration/commands/branch/get.test.ts +0 -49
- package/test/integration/commands/branch/list.test.ts +0 -47
- package/test/integration/commands/job/get.test.ts +0 -54
- package/test/integration/commands/job/list.test.ts +0 -47
- package/test/integration/commands/job/logs.test.ts +0 -47
- package/test/integration/commands/job/trigger.test.ts +0 -57
- package/test/integration/commands/login.test.ts +0 -62
- package/test/integration/commands/project/create.test.ts +0 -53
- package/test/integration/commands/project/delete.test.ts +0 -43
- package/test/integration/commands/project/get.test.ts +0 -51
- package/test/integration/commands/project/list.test.ts +0 -47
- package/test/integration/commands/project/update.test.ts +0 -53
- package/test/integration/commands/team/create.test.ts +0 -53
- package/test/integration/commands/team/delete.test.ts +0 -43
- package/test/integration/commands/team/get.test.ts +0 -50
- package/test/integration/commands/team/list.test.ts +0 -47
- package/test/integration/commands/team/member/invite.test.ts +0 -46
- package/test/integration/commands/team/member/remove.test.ts +0 -43
- package/test/integration/commands/team/update.test.ts +0 -50
- package/test/integration/commands/token/generate.test.ts +0 -51
- package/test/integration/commands/token/list.test.ts +0 -47
- package/test/integration/commands/token/revoke.test.ts +0 -43
- package/test/integration/commands/whoami.test.ts +0 -49
- package/test/unit/commands/admin/create-user.test.ts +0 -51
- package/test/unit/commands/branch/create.test.ts +0 -57
- package/test/unit/commands/branch/delete.test.ts +0 -49
- package/test/unit/commands/branch/get.test.ts +0 -67
- package/test/unit/commands/branch/list.test.ts +0 -62
- package/test/unit/commands/job/get.test.ts +0 -76
- package/test/unit/commands/job/list.test.ts +0 -62
- package/test/unit/commands/job/logs.test.ts +0 -60
- package/test/unit/commands/job/trigger.test.ts +0 -75
- package/test/unit/commands/login.test.ts +0 -64
- package/test/unit/commands/project/create.test.ts +0 -64
- package/test/unit/commands/project/delete.test.ts +0 -72
- package/test/unit/commands/project/get.test.ts +0 -73
- package/test/unit/commands/project/list.test.ts +0 -62
- package/test/unit/commands/project/update.test.ts +0 -58
- package/test/unit/commands/team/create.test.ts +0 -68
- package/test/unit/commands/team/delete.test.ts +0 -71
- package/test/unit/commands/team/get.test.ts +0 -70
- package/test/unit/commands/team/list.test.ts +0 -56
- package/test/unit/commands/team/member/invite.test.ts +0 -52
- package/test/unit/commands/team/member/remove.test.ts +0 -49
- package/test/unit/commands/team/update.test.ts +0 -63
- package/test/unit/commands/token/generate.test.ts +0 -65
- package/test/unit/commands/token/list.test.ts +0 -58
- package/test/unit/commands/token/revoke.test.ts +0 -49
- package/test/unit/commands/whoami.test.ts +0 -49
- package/test/unit/utils/nexical-client.test.ts +0 -113
- /package/dist/src/utils/{nexical-client.js.map → discovery.js.map} +0 -0
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import ProjectsListCommand from '../../../../src/commands/project/list.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('ProjectsListCommand', () => {
|
|
9
|
-
let command: ProjectsListCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
projects: {
|
|
17
|
-
list: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new ProjectsListCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should list projects successfully', async () => {
|
|
28
|
-
mockClient.projects.list.mockResolvedValue([
|
|
29
|
-
{ id: '200', name: 'Project A', repoUrl: 'http://a.git' },
|
|
30
|
-
{ id: '201', name: 'Project B' }
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
await command.run({ teamId: '1' });
|
|
34
|
-
|
|
35
|
-
expect(mockClient.projects.list).toHaveBeenCalledWith(1);
|
|
36
|
-
expect(command.info).toHaveBeenCalledWith('Projects in Team 1:');
|
|
37
|
-
expect(command.info).toHaveBeenCalledWith('- Project A (ID: 200) [http://a.git]');
|
|
38
|
-
expect(command.info).toHaveBeenCalledWith('- Project B (ID: 201) [No Repo]');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should handle empty list', async () => {
|
|
42
|
-
mockClient.projects.list.mockResolvedValue([]);
|
|
43
|
-
|
|
44
|
-
await command.run({ teamId: '1' });
|
|
45
|
-
|
|
46
|
-
expect(command.info).toHaveBeenCalledWith('No projects found in team 1.');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should validate Team ID', async () => {
|
|
50
|
-
await command.run({ teamId: 'invalid' });
|
|
51
|
-
expect(command.error).toHaveBeenCalledWith('Team ID must be a number.');
|
|
52
|
-
expect(mockClient.projects.list).not.toHaveBeenCalled();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should handle list failure', async () => {
|
|
56
|
-
mockClient.projects.list.mockRejectedValue(new Error('Network error'));
|
|
57
|
-
|
|
58
|
-
await command.run({ teamId: '1' });
|
|
59
|
-
|
|
60
|
-
expect(command.error).toHaveBeenCalledWith('Failed to list projects: Network error');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import ProjectsUpdateCommand from '../../../../src/commands/project/update.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('ProjectsUpdateCommand', () => {
|
|
9
|
-
let command: ProjectsUpdateCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
projects: {
|
|
17
|
-
update: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new ProjectsUpdateCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should update project successfully', async () => {
|
|
28
|
-
mockClient.projects.update.mockResolvedValue({ id: '200' });
|
|
29
|
-
|
|
30
|
-
await command.run({
|
|
31
|
-
teamId: '1',
|
|
32
|
-
projectId: '200',
|
|
33
|
-
name: 'Updated Name',
|
|
34
|
-
repo: 'http://new.git'
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
expect(mockClient.projects.update).toHaveBeenCalledWith(1, 200, {
|
|
38
|
-
name: 'Updated Name',
|
|
39
|
-
repoUrl: 'http://new.git',
|
|
40
|
-
productionUrl: undefined,
|
|
41
|
-
});
|
|
42
|
-
expect(command.success).toHaveBeenCalledWith('Project 200 updated!');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should validate IDs', async () => {
|
|
46
|
-
await command.run({ teamId: 'invalid', projectId: '200' });
|
|
47
|
-
expect(command.error).toHaveBeenCalledWith('IDs must be numbers.');
|
|
48
|
-
expect(mockClient.projects.update).not.toHaveBeenCalled();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should handle update failure', async () => {
|
|
52
|
-
mockClient.projects.update.mockRejectedValue(new Error('Not found'));
|
|
53
|
-
|
|
54
|
-
await command.run({ teamId: '1', projectId: '200' });
|
|
55
|
-
|
|
56
|
-
expect(command.error).toHaveBeenCalledWith('Failed to update project: Not found');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsCreateCommand from '../../../../src/commands/team/create.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsCreateCommand', () => {
|
|
9
|
-
let command: TeamsCreateCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
create: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsCreateCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
25
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should create team successfully', async () => {
|
|
29
|
-
mockClient.teams.create.mockResolvedValue({
|
|
30
|
-
name: 'My Team',
|
|
31
|
-
id: '1',
|
|
32
|
-
slug: 'my-team'
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await command.run({ name: 'My Team' });
|
|
36
|
-
|
|
37
|
-
expect(mockClient.teams.create).toHaveBeenCalledWith({
|
|
38
|
-
name: 'My Team',
|
|
39
|
-
slug: 'my-team' // derived slug
|
|
40
|
-
});
|
|
41
|
-
expect(command.success).toHaveBeenCalledWith('Team "My Team" created successfully!');
|
|
42
|
-
expect(command.info).toHaveBeenCalledWith('ID: 1');
|
|
43
|
-
expect(command.info).toHaveBeenCalledWith('Slug: my-team');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should create team with custom slug', async () => {
|
|
47
|
-
mockClient.teams.create.mockResolvedValue({
|
|
48
|
-
name: 'My Team',
|
|
49
|
-
id: '1',
|
|
50
|
-
slug: 'custom-slug'
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
await command.run({ name: 'My Team', slug: 'custom-slug' });
|
|
54
|
-
|
|
55
|
-
expect(mockClient.teams.create).toHaveBeenCalledWith({
|
|
56
|
-
name: 'My Team',
|
|
57
|
-
slug: 'custom-slug'
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should handle creation failure', async () => {
|
|
62
|
-
mockClient.teams.create.mockRejectedValue(new Error('Slug taken'));
|
|
63
|
-
|
|
64
|
-
await command.run({ name: 'My Team' });
|
|
65
|
-
|
|
66
|
-
expect(command.error).toHaveBeenCalledWith('Failed to create team: Slug taken');
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsDeleteCommand from '../../../../src/commands/team/delete.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsDeleteCommand', () => {
|
|
9
|
-
let command: TeamsDeleteCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
delete: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsDeleteCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
25
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
26
|
-
(command as any).prompt = vi.fn();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should delete team successfully with confirmation', async () => {
|
|
30
|
-
mockClient.teams.delete.mockResolvedValue({});
|
|
31
|
-
(command as any).prompt.mockResolvedValue('yes');
|
|
32
|
-
|
|
33
|
-
await command.run({ teamId: '1', confirm: false });
|
|
34
|
-
|
|
35
|
-
expect((command as any).prompt).toHaveBeenCalled();
|
|
36
|
-
expect(mockClient.teams.delete).toHaveBeenCalledWith(1);
|
|
37
|
-
expect(command.success).toHaveBeenCalledWith('Team 1 deleted.');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should delete team successfully with --confirm flag', async () => {
|
|
41
|
-
mockClient.teams.delete.mockResolvedValue({});
|
|
42
|
-
|
|
43
|
-
await command.run({ teamId: '1', confirm: true });
|
|
44
|
-
|
|
45
|
-
expect((command as any).prompt).not.toHaveBeenCalled();
|
|
46
|
-
expect(mockClient.teams.delete).toHaveBeenCalledWith(1);
|
|
47
|
-
expect(command.success).toHaveBeenCalledWith('Team 1 deleted.');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should abort deletion if user says no', async () => {
|
|
51
|
-
(command as any).prompt.mockResolvedValue('no');
|
|
52
|
-
|
|
53
|
-
await command.run({ teamId: '1', confirm: false });
|
|
54
|
-
|
|
55
|
-
expect(mockClient.teams.delete).not.toHaveBeenCalled();
|
|
56
|
-
expect(command.info).toHaveBeenCalledWith('Aborted.');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should validate Team ID', async () => {
|
|
60
|
-
await command.run({ teamId: 'invalid' });
|
|
61
|
-
expect(command.error).toHaveBeenCalledWith('Team ID must be a number.');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should handle deletion failure', async () => {
|
|
65
|
-
mockClient.teams.delete.mockRejectedValue(new Error('Team not found'));
|
|
66
|
-
|
|
67
|
-
await command.run({ teamId: '1', confirm: true });
|
|
68
|
-
|
|
69
|
-
expect(command.error).toHaveBeenCalledWith('Failed to delete team: Team not found');
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsGetCommand from '../../../../src/commands/team/get.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsGetCommand', () => {
|
|
9
|
-
let command: TeamsGetCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
get: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsGetCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should get team details successfully', async () => {
|
|
28
|
-
mockClient.teams.get.mockResolvedValue({
|
|
29
|
-
id: '1',
|
|
30
|
-
name: 'My Team',
|
|
31
|
-
slug: 'my-team',
|
|
32
|
-
role: 'owner'
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await command.run({ teamId: '1' });
|
|
36
|
-
|
|
37
|
-
expect(mockClient.teams.get).toHaveBeenCalledWith(1);
|
|
38
|
-
expect(command.info).toHaveBeenCalledWith('Team Details:');
|
|
39
|
-
expect(command.info).toHaveBeenCalledWith(' ID: 1');
|
|
40
|
-
expect(command.info).toHaveBeenCalledWith(' Name: My Team');
|
|
41
|
-
expect(command.info).toHaveBeenCalledWith(' Slug: my-team');
|
|
42
|
-
expect(command.info).toHaveBeenCalledWith(' Role: owner');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should show default role', async () => {
|
|
46
|
-
mockClient.teams.get.mockResolvedValue({
|
|
47
|
-
id: '1',
|
|
48
|
-
name: 'My Team',
|
|
49
|
-
slug: 'my-team'
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
await command.run({ teamId: '1' });
|
|
53
|
-
|
|
54
|
-
expect(command.info).toHaveBeenCalledWith(' Role: member');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should validate Team ID', async () => {
|
|
58
|
-
await command.run({ teamId: 'invalid' });
|
|
59
|
-
expect(command.error).toHaveBeenCalledWith('Team ID must be a number.');
|
|
60
|
-
expect(mockClient.teams.get).not.toHaveBeenCalled();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should handle get failure', async () => {
|
|
64
|
-
mockClient.teams.get.mockRejectedValue(new Error('Team not found'));
|
|
65
|
-
|
|
66
|
-
await command.run({ teamId: '1' });
|
|
67
|
-
|
|
68
|
-
expect(command.error).toHaveBeenCalledWith('Failed to get team: Team not found');
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsListCommand from '../../../../src/commands/team/list.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsListCommand', () => {
|
|
9
|
-
let command: TeamsListCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
list: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsListCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should list teams successfully', async () => {
|
|
28
|
-
mockClient.teams.list.mockResolvedValue([
|
|
29
|
-
{ name: 'Team A', slug: 'team-a', role: 'admin' },
|
|
30
|
-
{ name: 'Team B', slug: 'team-b', role: undefined } // default to member
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
await command.run();
|
|
34
|
-
|
|
35
|
-
expect(mockClient.teams.list).toHaveBeenCalled();
|
|
36
|
-
expect(command.info).toHaveBeenCalledWith('Your Teams:');
|
|
37
|
-
expect(command.info).toHaveBeenCalledWith('- Team A (team-a) [admin]');
|
|
38
|
-
expect(command.info).toHaveBeenCalledWith('- Team B (team-b) [member]');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should handle empty list', async () => {
|
|
42
|
-
mockClient.teams.list.mockResolvedValue([]);
|
|
43
|
-
|
|
44
|
-
await command.run();
|
|
45
|
-
|
|
46
|
-
expect(command.info).toHaveBeenCalledWith('You are not a member of any teams.');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should handle list failure', async () => {
|
|
50
|
-
mockClient.teams.list.mockRejectedValue(new Error('Network error'));
|
|
51
|
-
|
|
52
|
-
await command.run();
|
|
53
|
-
|
|
54
|
-
expect(command.error).toHaveBeenCalledWith('Failed to list teams: Network error');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsInviteCommand from '../../../../../src/commands/team/member/invite.js';
|
|
4
|
-
import { getClient } from '../../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsInviteCommand', () => {
|
|
9
|
-
let command: TeamsInviteCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
inviteMember: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsInviteCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should invite member successfully', async () => {
|
|
28
|
-
mockClient.teams.inviteMember.mockResolvedValue({});
|
|
29
|
-
|
|
30
|
-
await command.run({ teamId: '1', email: 'test@example.com', role: 'member' });
|
|
31
|
-
|
|
32
|
-
expect(mockClient.teams.inviteMember).toHaveBeenCalledWith(1, {
|
|
33
|
-
email: 'test@example.com',
|
|
34
|
-
role: 'member',
|
|
35
|
-
});
|
|
36
|
-
expect(command.success).toHaveBeenCalledWith('Invited test@example.com to team 1 as member.');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should validate Team ID', async () => {
|
|
40
|
-
await command.run({ teamId: 'invalid', email: 'test@example.com' });
|
|
41
|
-
expect(command.error).toHaveBeenCalledWith('Team ID must be a number.');
|
|
42
|
-
expect(mockClient.teams.inviteMember).not.toHaveBeenCalled();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should handle invite failure', async () => {
|
|
46
|
-
mockClient.teams.inviteMember.mockRejectedValue(new Error('Already member'));
|
|
47
|
-
|
|
48
|
-
await command.run({ teamId: '1', email: 'test@example.com', role: 'member' });
|
|
49
|
-
|
|
50
|
-
expect(command.error).toHaveBeenCalledWith('Failed to invite member: Already member');
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsMembersRemoveCommand from '../../../../../src/commands/team/member/remove.js';
|
|
4
|
-
import { getClient } from '../../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsMembersRemoveCommand', () => {
|
|
9
|
-
let command: TeamsMembersRemoveCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
removeMember: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsMembersRemoveCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should remove member successfully', async () => {
|
|
28
|
-
mockClient.teams.removeMember.mockResolvedValue({});
|
|
29
|
-
|
|
30
|
-
await command.run({ teamId: '1', userId: 'user-123' });
|
|
31
|
-
|
|
32
|
-
expect(mockClient.teams.removeMember).toHaveBeenCalledWith(1, 'user-123');
|
|
33
|
-
expect(command.success).toHaveBeenCalledWith('User user-123 removed from team 1.');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should validate Team ID', async () => {
|
|
37
|
-
await command.run({ teamId: 'invalid', userId: 'user-123' });
|
|
38
|
-
expect(command.error).toHaveBeenCalledWith('Team ID must be a number.');
|
|
39
|
-
expect(mockClient.teams.removeMember).not.toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should handle removal failure', async () => {
|
|
43
|
-
mockClient.teams.removeMember.mockRejectedValue(new Error('User not found'));
|
|
44
|
-
|
|
45
|
-
await command.run({ teamId: '1', userId: 'user-123' });
|
|
46
|
-
|
|
47
|
-
expect(command.error).toHaveBeenCalledWith('Failed to remove member: User not found');
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import TeamsUpdateCommand from '../../../../src/commands/team/update.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('TeamsUpdateCommand', () => {
|
|
9
|
-
let command: TeamsUpdateCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
teams: {
|
|
17
|
-
update: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new TeamsUpdateCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
25
|
-
vi.spyOn(command, 'warn').mockImplementation(() => { });
|
|
26
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should update team successfully', async () => {
|
|
30
|
-
mockClient.teams.update.mockResolvedValue({
|
|
31
|
-
id: '1',
|
|
32
|
-
name: 'New Name'
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await command.run({ teamId: '1', name: 'New Name' });
|
|
36
|
-
|
|
37
|
-
expect(mockClient.teams.update).toHaveBeenCalledWith(1, {
|
|
38
|
-
name: 'New Name',
|
|
39
|
-
});
|
|
40
|
-
expect(command.success).toHaveBeenCalledWith('Team 1 updated!');
|
|
41
|
-
expect(command.info).toHaveBeenCalledWith('Name: New Name');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should warn if no updates provided', async () => {
|
|
45
|
-
await command.run({ teamId: '1' });
|
|
46
|
-
expect(command.warn).toHaveBeenCalledWith('No updates provided. Use --name or --slug.');
|
|
47
|
-
expect(mockClient.teams.update).not.toHaveBeenCalled();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should validate Team ID', async () => {
|
|
51
|
-
await command.run({ teamId: 'invalid' });
|
|
52
|
-
expect(command.error).toHaveBeenCalledWith('Team ID must be a number.');
|
|
53
|
-
expect(mockClient.teams.update).not.toHaveBeenCalled();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should handle update failure', async () => {
|
|
57
|
-
mockClient.teams.update.mockRejectedValue(new Error('Update failed'));
|
|
58
|
-
|
|
59
|
-
await command.run({ teamId: '1', name: 'N' });
|
|
60
|
-
|
|
61
|
-
expect(command.error).toHaveBeenCalledWith('Failed to update team: Update failed');
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import AuthTokensGenerateCommand from '../../../../src/commands/token/generate.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('AuthTokensGenerateCommand', () => {
|
|
9
|
-
let command: AuthTokensGenerateCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
auth: {
|
|
17
|
-
generateToken: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new AuthTokensGenerateCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'success').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'warn').mockImplementation(() => { });
|
|
25
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should generate token successfully', async () => {
|
|
29
|
-
mockClient.auth.generateToken.mockResolvedValue({
|
|
30
|
-
name: 'My Token',
|
|
31
|
-
token: 'secret-token-value'
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
await command.run({ name: 'My Token', scopes: 'read,write' });
|
|
35
|
-
|
|
36
|
-
expect(mockClient.auth.generateToken).toHaveBeenCalledWith({
|
|
37
|
-
name: 'My Token',
|
|
38
|
-
scopes: ['read', 'write'],
|
|
39
|
-
});
|
|
40
|
-
expect(command.success).toHaveBeenCalledWith('Token "My Token" generated!');
|
|
41
|
-
expect(command.warn).toHaveBeenCalledWith('Token: secret-token-value');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should generate token without scopes', async () => {
|
|
45
|
-
mockClient.auth.generateToken.mockResolvedValue({
|
|
46
|
-
name: 'My Token',
|
|
47
|
-
token: 'secret-token-value'
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
await command.run({ name: 'My Token' });
|
|
51
|
-
|
|
52
|
-
expect(mockClient.auth.generateToken).toHaveBeenCalledWith({
|
|
53
|
-
name: 'My Token',
|
|
54
|
-
scopes: undefined,
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should handle generation failure', async () => {
|
|
59
|
-
mockClient.auth.generateToken.mockRejectedValue(new Error('Limit reached'));
|
|
60
|
-
|
|
61
|
-
await command.run({ name: 'My Token' });
|
|
62
|
-
|
|
63
|
-
expect(command.error).toHaveBeenCalledWith('Failed to generate token: Limit reached');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import AuthTokensListCommand from '../../../../src/commands/token/list.js';
|
|
4
|
-
import { getClient } from '../../../../src/utils/nexical-client.js';
|
|
5
|
-
|
|
6
|
-
vi.mock('../../../../src/utils/nexical-client.js');
|
|
7
|
-
|
|
8
|
-
describe('AuthTokensListCommand', () => {
|
|
9
|
-
let command: AuthTokensListCommand;
|
|
10
|
-
let mockClient: any;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.resetAllMocks();
|
|
14
|
-
|
|
15
|
-
mockClient = {
|
|
16
|
-
auth: {
|
|
17
|
-
listTokens: vi.fn(),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
vi.mocked(getClient).mockReturnValue(mockClient);
|
|
21
|
-
|
|
22
|
-
command = new AuthTokensListCommand([], {} as any);
|
|
23
|
-
vi.spyOn(command, 'info').mockImplementation(() => { });
|
|
24
|
-
vi.spyOn(command, 'error').mockImplementation(() => { });
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should list tokens successfully', async () => {
|
|
28
|
-
mockClient.auth.listTokens.mockResolvedValue({
|
|
29
|
-
tokens: [
|
|
30
|
-
{ name: 'Token 1', tokenPrefix: 'abc', expiresAt: '2023-01-01' },
|
|
31
|
-
{ name: 'Token 2', tokenPrefix: 'def' }
|
|
32
|
-
]
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await command.run();
|
|
36
|
-
|
|
37
|
-
expect(mockClient.auth.listTokens).toHaveBeenCalled();
|
|
38
|
-
expect(command.info).toHaveBeenCalledWith('Your API Tokens:');
|
|
39
|
-
expect(command.info).toHaveBeenCalledWith('- Token 1 (abc...) [Expires: 2023-01-01]');
|
|
40
|
-
expect(command.info).toHaveBeenCalledWith('- Token 2 (def...) [Expires: Never]');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should handle empty list', async () => {
|
|
44
|
-
mockClient.auth.listTokens.mockResolvedValue({ tokens: [] });
|
|
45
|
-
|
|
46
|
-
await command.run();
|
|
47
|
-
|
|
48
|
-
expect(command.info).toHaveBeenCalledWith('No API tokens found.');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should handle list failure', async () => {
|
|
52
|
-
mockClient.auth.listTokens.mockRejectedValue(new Error('Network error'));
|
|
53
|
-
|
|
54
|
-
await command.run();
|
|
55
|
-
|
|
56
|
-
expect(command.error).toHaveBeenCalledWith('Failed to list tokens: Network error');
|
|
57
|
-
});
|
|
58
|
-
});
|