@nestbox-ai/cli 1.0.48 → 1.0.49

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.
Files changed (100) hide show
  1. package/package.json +7 -1
  2. package/.github/workflows/generate-client.yml +0 -43
  3. package/.github/workflows/test.yml +0 -54
  4. package/.nestboxrc +0 -5
  5. package/src/commands/agent/apiUtils.ts +0 -113
  6. package/src/commands/agent/create.ts +0 -271
  7. package/src/commands/agent/deploy.ts +0 -523
  8. package/src/commands/agent/index.ts +0 -8
  9. package/src/commands/agent/list.ts +0 -104
  10. package/src/commands/agent/remove.ts +0 -103
  11. package/src/commands/agent/yaml-schema.ts +0 -57
  12. package/src/commands/agent.ts +0 -21
  13. package/src/commands/auth/index.ts +0 -3
  14. package/src/commands/auth/login.ts +0 -184
  15. package/src/commands/auth/logout.ts +0 -110
  16. package/src/commands/auth.ts +0 -12
  17. package/src/commands/compute/apiUtils.ts +0 -28
  18. package/src/commands/compute/create.ts +0 -195
  19. package/src/commands/compute/delete.ts +0 -147
  20. package/src/commands/compute/index.ts +0 -7
  21. package/src/commands/compute/list.ts +0 -117
  22. package/src/commands/compute.ts +0 -19
  23. package/src/commands/document/apiUtils.ts +0 -22
  24. package/src/commands/document/collectionCreate.ts +0 -46
  25. package/src/commands/document/collectionDelete.ts +0 -45
  26. package/src/commands/document/collectionGet.ts +0 -47
  27. package/src/commands/document/collectionList.ts +0 -52
  28. package/src/commands/document/collectionUpdate.ts +0 -53
  29. package/src/commands/document/docAdd.ts +0 -56
  30. package/src/commands/document/docDelete.ts +0 -47
  31. package/src/commands/document/docGet.ts +0 -49
  32. package/src/commands/document/docSearch.ts +0 -70
  33. package/src/commands/document/docUpdate.ts +0 -56
  34. package/src/commands/document/docUploadFile.ts +0 -55
  35. package/src/commands/document/index.ts +0 -17
  36. package/src/commands/document.ts +0 -48
  37. package/src/commands/generate/project.ts +0 -199
  38. package/src/commands/generate.ts +0 -15
  39. package/src/commands/image/apiUtils.ts +0 -22
  40. package/src/commands/image/display.ts +0 -34
  41. package/src/commands/image/index.ts +0 -4
  42. package/src/commands/image/list.ts +0 -61
  43. package/src/commands/image.ts +0 -15
  44. package/src/commands/project/add.ts +0 -47
  45. package/src/commands/project/apiUtils.ts +0 -20
  46. package/src/commands/project/index.ts +0 -5
  47. package/src/commands/project/list.ts +0 -78
  48. package/src/commands/project/use.ts +0 -45
  49. package/src/commands/project.ts +0 -19
  50. package/src/index.ts +0 -39
  51. package/src/types/agentType.ts +0 -7
  52. package/src/types/agentYaml.ts +0 -107
  53. package/src/types/auth.ts +0 -12
  54. package/src/types/statusMapping.ts +0 -8
  55. package/src/utils/agent.ts +0 -170
  56. package/src/utils/api.ts +0 -64
  57. package/src/utils/auth.ts +0 -140
  58. package/src/utils/config.ts +0 -37
  59. package/src/utils/error.ts +0 -168
  60. package/src/utils/plopGenerator.ts +0 -133
  61. package/src/utils/project.ts +0 -88
  62. package/src/utils/user.ts +0 -28
  63. package/src/utils/validation.ts +0 -22
  64. package/templates/base-js/index.js.hbs +0 -30
  65. package/templates/base-js/nestbox-agents.yaml.hbs +0 -12
  66. package/templates/base-js/package.json +0 -15
  67. package/templates/base-py/main.py.hbs +0 -42
  68. package/templates/base-py/nestbox-agents.yaml.hbs +0 -12
  69. package/templates/base-py/pyproject.toml +0 -19
  70. package/templates/base-ts/eslint.config.mjs +0 -27
  71. package/templates/base-ts/nestbox-agents.yaml.hbs +0 -12
  72. package/templates/base-ts/nestbox.config.json +0 -9
  73. package/templates/base-ts/package.json +0 -24
  74. package/templates/base-ts/src/index.ts.hbs +0 -29
  75. package/templates/base-ts/tsconfig.json +0 -14
  76. package/templates/chatbot-js/index.js.hbs +0 -18
  77. package/templates/chatbot-js/package-lock.json +0 -1571
  78. package/templates/chatbot-js/package.json +0 -15
  79. package/templates/chatbot-py/main.py.hbs +0 -42
  80. package/templates/chatbot-py/nestbox-agents.yaml.hbs +0 -12
  81. package/templates/chatbot-py/pyproject.toml +0 -19
  82. package/templates/chatbot-ts/eslint.config.mjs +0 -27
  83. package/templates/chatbot-ts/package.json +0 -24
  84. package/templates/chatbot-ts/src/index.ts.hbs +0 -18
  85. package/templates/chatbot-ts/tsconfig.json +0 -14
  86. package/test/README.md +0 -52
  87. package/test/agent.test.ts +0 -154
  88. package/test/auth.test.ts +0 -71
  89. package/test/compute.test.ts +0 -135
  90. package/test/document.test.ts +0 -217
  91. package/test/generate.test.ts +0 -67
  92. package/test/image.test.ts +0 -107
  93. package/test/mocks.ts +0 -122
  94. package/test/project.test.ts +0 -108
  95. package/test/setup.ts +0 -121
  96. package/tsconfig.json +0 -118
  97. package/vitest.config.d.ts +0 -2
  98. package/vitest.config.js +0 -23
  99. package/vitest.config.js.map +0 -1
  100. package/vitest.config.ts +0 -21
@@ -1,217 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { Command } from 'commander';
3
- import { registerDocumentCommands } from '../src/commands/document';
4
-
5
- describe('Document Commands', () => {
6
- let program: Command;
7
-
8
- beforeEach(() => {
9
- program = new Command();
10
- vi.clearAllMocks();
11
- });
12
-
13
- describe('registerDocumentCommands', () => {
14
- it('should register document command group', () => {
15
- registerDocumentCommands(program);
16
-
17
- const commands = program.commands;
18
- const documentCommand = commands.find(cmd => cmd.name() === 'document');
19
-
20
- expect(documentCommand).toBeDefined();
21
- expect(documentCommand?.description()).toBe('Manage Nestbox documents');
22
- });
23
-
24
- it('should register doc subcommand group', () => {
25
- registerDocumentCommands(program);
26
-
27
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
28
- const subCommands = documentCommand?.commands || [];
29
- const docCommand = subCommands.find(cmd => cmd.name() === 'doc');
30
-
31
- expect(docCommand).toBeDefined();
32
- expect(docCommand?.description()).toBe('Manage individual documents');
33
- });
34
-
35
- it('should register collection subcommand group', () => {
36
- registerDocumentCommands(program);
37
-
38
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
39
- const subCommands = documentCommand?.commands || [];
40
- const collectionCommand = subCommands.find(cmd => cmd.name() === 'collection');
41
-
42
- expect(collectionCommand).toBeDefined();
43
- expect(collectionCommand?.description()).toBe('Manage document collections');
44
- });
45
-
46
- it('should register doc list subcommand', () => {
47
- registerDocumentCommands(program);
48
-
49
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
50
- const collectionCommand = documentCommand?.commands.find(cmd => cmd.name() === 'collection');
51
- const collectionSubCommands = collectionCommand?.commands || [];
52
- const listCommand = collectionSubCommands.find(cmd => cmd.name() === 'list');
53
-
54
- expect(listCommand).toBeDefined();
55
- expect(listCommand?.description()).toBe('List document collections for a specific instance');
56
-
57
- // Check options
58
- const options = listCommand?.options || [];
59
- const instanceOption = options.find(opt => opt.long === '--instance');
60
- const projectOption = options.find(opt => opt.long === '--project');
61
-
62
- expect(instanceOption).toBeDefined();
63
- expect(projectOption).toBeDefined();
64
- });
65
-
66
- it('should register doc create subcommand', () => {
67
- registerDocumentCommands(program);
68
-
69
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
70
- const collectionCommand = documentCommand?.commands.find(cmd => cmd.name() === 'collection');
71
- const collectionSubCommands = collectionCommand?.commands || [];
72
- const createCommand = collectionSubCommands.find(cmd => cmd.name() === 'create');
73
-
74
- expect(createCommand).toBeDefined();
75
- expect(createCommand?.description()).toBe('Create a new document collection for a specific instance');
76
-
77
- // Check options
78
- const options = createCommand?.options || [];
79
- const instanceOption = options.find(opt => opt.long === '--instance');
80
- const projectOption = options.find(opt => opt.long === '--project');
81
-
82
- expect(instanceOption).toBeDefined();
83
- expect(projectOption).toBeDefined();
84
- });
85
-
86
- it('should register doc get subcommand', () => {
87
- registerDocumentCommands(program);
88
-
89
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
90
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
91
- const docSubCommands = docCommand?.commands || [];
92
- const getCommand = docSubCommands.find(cmd => cmd.name() === 'get');
93
-
94
- expect(getCommand).toBeDefined();
95
- expect(getCommand?.description()).toBe('Get a document from a collection');
96
-
97
- // Arguments are part of the command definition, not in args array
98
- expect(getCommand?.name()).toBe('get');
99
- });
100
-
101
- it('should register doc delete subcommand', () => {
102
- registerDocumentCommands(program);
103
-
104
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
105
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
106
- const docSubCommands = docCommand?.commands || [];
107
- const deleteCommand = docSubCommands.find(cmd => cmd.name() === 'delete');
108
-
109
- expect(deleteCommand).toBeDefined();
110
- expect(deleteCommand?.description()).toBe('Delete a document from a collection');
111
-
112
- // Arguments are part of the command definition, not in args array
113
- expect(deleteCommand?.name()).toBe('delete');
114
- });
115
-
116
- it('should register doc update subcommand', () => {
117
- registerDocumentCommands(program);
118
-
119
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
120
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
121
- const docSubCommands = docCommand?.commands || [];
122
- const updateCommand = docSubCommands.find(cmd => cmd.name() === 'update');
123
-
124
- expect(updateCommand).toBeDefined();
125
- expect(updateCommand?.description()).toBe('Update a document in a collection');
126
-
127
- // Arguments are part of the command definition, not in args array
128
- expect(updateCommand?.name()).toBe('update');
129
- });
130
-
131
- it('should register collection add subcommand', () => {
132
- registerDocumentCommands(program);
133
-
134
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
135
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
136
- const docSubCommands = docCommand?.commands || [];
137
- const addCommand = docSubCommands.find(cmd => cmd.name() === 'add');
138
-
139
- expect(addCommand).toBeDefined();
140
- expect(addCommand?.description()).toBe('Add a new document to a collection');
141
-
142
- // Check options
143
- const options = addCommand?.options || [];
144
- const instanceOption = options.find(opt => opt.long === '--instance');
145
- const collectionOption = options.find(opt => opt.long === '--collection');
146
-
147
- expect(instanceOption).toBeDefined();
148
- expect(collectionOption).toBeDefined();
149
- });
150
-
151
- it('should register collection search subcommand', () => {
152
- registerDocumentCommands(program);
153
-
154
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
155
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
156
- const docSubCommands = docCommand?.commands || [];
157
- const searchCommand = docSubCommands.find(cmd => cmd.name() === 'search');
158
-
159
- expect(searchCommand).toBeDefined();
160
- expect(searchCommand?.description()).toBe('Search for documents in a collection');
161
-
162
- // Check arguments and options
163
- expect(searchCommand?.name()).toBe('search');
164
- });
165
-
166
- it('should have all expected doc subcommands', () => {
167
- registerDocumentCommands(program);
168
-
169
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
170
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
171
- const docSubCommandNames = docCommand?.commands.map(cmd => cmd.name()) || [];
172
-
173
- expect(docSubCommandNames).toContain('add');
174
- expect(docSubCommandNames).toContain('get');
175
- expect(docSubCommandNames).toContain('delete');
176
- expect(docSubCommandNames).toContain('update');
177
- expect(docSubCommandNames).toContain('upload-file');
178
- expect(docSubCommandNames).toContain('search');
179
- expect(docSubCommandNames).toHaveLength(6);
180
- });
181
-
182
- it('should have all expected collection subcommands', () => {
183
- registerDocumentCommands(program);
184
-
185
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
186
- const collectionCommand = documentCommand?.commands.find(cmd => cmd.name() === 'collection');
187
- const collectionSubCommandNames = collectionCommand?.commands.map(cmd => cmd.name()) || [];
188
-
189
- expect(collectionSubCommandNames).toContain('list');
190
- expect(collectionSubCommandNames).toContain('create');
191
- expect(collectionSubCommandNames).toContain('get');
192
- expect(collectionSubCommandNames).toContain('delete');
193
- expect(collectionSubCommandNames).toContain('update');
194
- expect(collectionSubCommandNames).toHaveLength(5);
195
- });
196
-
197
- it('should have proper action functions for all subcommands', () => {
198
- registerDocumentCommands(program);
199
-
200
- const documentCommand = program.commands.find(cmd => cmd.name() === 'document');
201
- const docCommand = documentCommand?.commands.find(cmd => cmd.name() === 'doc');
202
- const collectionCommand = documentCommand?.commands.find(cmd => cmd.name() === 'collection');
203
-
204
- // Check doc subcommands
205
- const docSubCommands = docCommand?.commands || [];
206
- docSubCommands.forEach(cmd => {
207
- expect(typeof cmd.action).toBe('function');
208
- });
209
-
210
- // Check collection subcommands
211
- const collectionSubCommands = collectionCommand?.commands || [];
212
- collectionSubCommands.forEach(cmd => {
213
- expect(typeof cmd.action).toBe('function');
214
- });
215
- });
216
- });
217
- });
@@ -1,67 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { Command } from 'commander';
3
- import { registerGenerateCommands } from '../src/commands/generate';
4
-
5
- describe('Generate Commands', () => {
6
- let program: Command;
7
-
8
- beforeEach(() => {
9
- program = new Command();
10
- vi.clearAllMocks();
11
- });
12
-
13
- describe('registerGenerateCommands', () => {
14
- it('should register generate command group', () => {
15
- registerGenerateCommands(program);
16
-
17
- const commands = program.commands;
18
- const generateCommand = commands.find(cmd => cmd.name() === 'generate');
19
-
20
- expect(generateCommand).toBeDefined();
21
- expect(generateCommand?.description()).toBe('Generate new projects and components');
22
- });
23
-
24
- it('should register generate project subcommand', () => {
25
- registerGenerateCommands(program);
26
-
27
- const generateCommand = program.commands.find(cmd => cmd.name() === 'generate');
28
- const subCommands = generateCommand?.commands || [];
29
- const projectCommand = subCommands.find(cmd => cmd.name() === 'project');
30
-
31
- expect(projectCommand).toBeDefined();
32
- expect(projectCommand?.description()).toBe('Generate a new project from templates');
33
-
34
- // Check that folder is an argument (it's in command name: "project <folder>")
35
- expect(projectCommand?.name()).toBe('project');
36
-
37
- // Check options
38
- const options = projectCommand?.options || [];
39
- const langOption = options.find(opt => opt.long === '--lang');
40
- const templateOption = options.find(opt => opt.long === '--template');
41
- const nameOption = options.find(opt => opt.long === '--name');
42
- const projectOption = options.find(opt => opt.long === '--project');
43
-
44
- expect(langOption).toBeDefined();
45
- expect(langOption?.description).toBe('Project language (ts|js)');
46
-
47
- expect(templateOption).toBeDefined();
48
- expect(templateOption?.description).toBe('Template type (agent|chatbot)');
49
-
50
- expect(nameOption).toBeDefined();
51
- expect(nameOption?.description).toBe('Agent/Chatbot name (must be a valid function name)');
52
-
53
- expect(projectOption).toBeDefined();
54
- expect(projectOption?.description).toBe('Project ID');
55
- });
56
-
57
- it('should contain expected subcommands', () => {
58
- registerGenerateCommands(program);
59
-
60
- const generateCommand = program.commands.find(cmd => cmd.name() === 'generate');
61
- const subCommands = generateCommand?.commands || [];
62
- const subCommandNames = subCommands.map(cmd => cmd.name());
63
-
64
- expect(subCommandNames).toContain('project');
65
- });
66
- });
67
- });
@@ -1,107 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { Command } from 'commander';
3
- import { registerImageCommands } from '../src/commands/image';
4
-
5
- describe('Image Commands', () => {
6
- let program: Command;
7
-
8
- beforeEach(() => {
9
- program = new Command();
10
- vi.clearAllMocks();
11
- });
12
-
13
- describe('registerImageCommands', () => {
14
- it('should register image command group', () => {
15
- registerImageCommands(program);
16
-
17
- const commands = program.commands;
18
- const imageCommand = commands.find(cmd => cmd.name() === 'image');
19
-
20
- expect(imageCommand).toBeDefined();
21
- expect(imageCommand?.description()).toBe('Manage Nestbox images');
22
- });
23
-
24
- it('should register image list subcommand', () => {
25
- registerImageCommands(program);
26
-
27
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
28
- const subCommands = imageCommand?.commands || [];
29
- const listCommand = subCommands.find(cmd => cmd.name() === 'list');
30
-
31
- expect(listCommand).toBeDefined();
32
- expect(listCommand?.description()).toBe('List images for a project');
33
-
34
- // Check options
35
- const options = listCommand?.options || [];
36
- const projectOption = options.find(opt => opt.long === '--project');
37
- expect(projectOption).toBeDefined();
38
- expect(projectOption?.description).toBe('Project ID or name (defaults to the current project)');
39
- });
40
-
41
- it('should have all expected image subcommands', () => {
42
- registerImageCommands(program);
43
-
44
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
45
- const subCommandNames = imageCommand?.commands.map(cmd => cmd.name()) || [];
46
-
47
- expect(subCommandNames).toContain('list');
48
- expect(subCommandNames).toHaveLength(1);
49
- });
50
-
51
- it('should have proper action functions for all subcommands', () => {
52
- registerImageCommands(program);
53
-
54
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
55
- const subCommands = imageCommand?.commands || [];
56
-
57
- subCommands.forEach(cmd => {
58
- expect(typeof cmd.action).toBe('function');
59
- });
60
- });
61
-
62
- it('should register image list command with correct structure', () => {
63
- registerImageCommands(program);
64
-
65
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
66
- const listCommand = imageCommand?.commands.find(cmd => cmd.name() === 'list');
67
-
68
- expect(listCommand?.name()).toBe('list');
69
- expect(listCommand?.description()).toBe('List images for a project');
70
- expect(typeof listCommand?.action).toBe('function');
71
- });
72
-
73
- it('should have project option with correct configuration', () => {
74
- registerImageCommands(program);
75
-
76
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
77
- const listCommand = imageCommand?.commands.find(cmd => cmd.name() === 'list');
78
- const options = listCommand?.options || [];
79
- const projectOption = options.find(opt => opt.long === '--project');
80
-
81
- expect(projectOption).toBeDefined();
82
- expect(projectOption?.description).toBe('Project ID or name (defaults to the current project)');
83
- expect(projectOption?.long).toBe('--project');
84
- });
85
-
86
- it('should properly initialize when auth token is available', () => {
87
- // This test verifies that the command registration doesn't fail when auth token is available
88
- expect(() => {
89
- registerImageCommands(program);
90
- }).not.toThrow();
91
-
92
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
93
- expect(imageCommand).toBeDefined();
94
- });
95
-
96
- it('should handle the case when createApis function is called within command actions', () => {
97
- registerImageCommands(program);
98
-
99
- const imageCommand = program.commands.find(cmd => cmd.name() === 'image');
100
- const listCommand = imageCommand?.commands.find(cmd => cmd.name() === 'list');
101
-
102
- // Verify that the action function exists and is callable
103
- expect(listCommand?.action).toBeDefined();
104
- expect(typeof listCommand?.action).toBe('function');
105
- });
106
- });
107
- });
package/test/mocks.ts DELETED
@@ -1,122 +0,0 @@
1
- import { vi } from 'vitest';
2
-
3
- // Mock external dependencies that are commonly used across all test files
4
- export const setupCommonMocks = () => {
5
- // Mock utils/error
6
- vi.mock('../src/utils/error', () => ({
7
- withTokenRefresh: vi.fn(),
8
- handle401Error: vi.fn()
9
- }));
10
-
11
- // Mock utils/auth
12
- vi.mock('../src/utils/auth', () => ({
13
- getAuthToken: vi.fn().mockReturnValue({
14
- token: 'mock-token',
15
- serverUrl: 'http://localhost:3000'
16
- }),
17
- listCredentials: vi.fn(),
18
- removeCredentials: vi.fn()
19
- }));
20
-
21
- // Mock @nestbox-ai/admin
22
- vi.mock('@nestbox-ai/admin', () => ({
23
- Configuration: vi.fn(),
24
- AuthApi: vi.fn(),
25
- ProjectsApi: vi.fn(),
26
- MachineAgentApi: vi.fn(),
27
- MachineInstancesApi: vi.fn(),
28
- MiscellaneousApi: vi.fn(),
29
- DocumentsApi: vi.fn(),
30
- OAuthLoginRequestDTOTypeEnum: {}
31
- }));
32
-
33
- // Mock utils/project
34
- vi.mock('../src/utils/project', () => ({
35
- resolveProject: vi.fn()
36
- }));
37
-
38
- // Mock utils/agent
39
- vi.mock('../src/utils/agent', () => ({
40
- createNestboxConfig: vi.fn(),
41
- createZipFromDirectory: vi.fn(),
42
- extractZip: vi.fn(),
43
- findProjectRoot: vi.fn(),
44
- isTypeScriptProject: vi.fn(),
45
- loadNestboxConfig: vi.fn(),
46
- runPredeployScripts: vi.fn()
47
- }));
48
-
49
- // Mock utils/user
50
- vi.mock('../src/utils/user', () => ({
51
- userData: vi.fn()
52
- }));
53
-
54
- // Mock chalk
55
- vi.mock('chalk', () => ({
56
- default: {
57
- green: vi.fn((text) => text),
58
- red: vi.fn((text) => text),
59
- yellow: vi.fn((text) => text),
60
- blue: vi.fn((text) => text)
61
- }
62
- }));
63
-
64
- // Mock ora
65
- vi.mock('ora', () => ({
66
- default: vi.fn(() => ({
67
- start: vi.fn().mockReturnThis(),
68
- succeed: vi.fn().mockReturnThis(),
69
- fail: vi.fn().mockReturnThis(),
70
- text: ''
71
- }))
72
- }));
73
-
74
- // Mock cli-table3
75
- vi.mock('cli-table3', () => ({
76
- default: vi.fn()
77
- }));
78
-
79
- // Mock inquirer
80
- vi.mock('inquirer', () => ({
81
- default: {
82
- prompt: vi.fn()
83
- }
84
- }));
85
-
86
- // Mock fs
87
- vi.mock('fs', () => ({
88
- default: {
89
- existsSync: vi.fn(),
90
- readFileSync: vi.fn(),
91
- writeFileSync: vi.fn()
92
- }
93
- }));
94
-
95
- // Mock yaml
96
- vi.mock('yaml', () => ({
97
- default: {
98
- load: vi.fn()
99
- }
100
- }));
101
-
102
- // Mock axios
103
- vi.mock('axios', () => ({
104
- default: {
105
- get: vi.fn(),
106
- post: vi.fn()
107
- }
108
- }));
109
-
110
- // Mock open
111
- vi.mock('open', () => ({
112
- default: vi.fn()
113
- }));
114
-
115
- // Mock path
116
- vi.mock('path', () => ({
117
- default: {
118
- join: vi.fn(),
119
- resolve: vi.fn()
120
- }
121
- }));
122
- };
@@ -1,108 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { Command } from 'commander';
3
- import { registerProjectCommands } from '../src/commands/project';
4
-
5
- describe('Project Commands', () => {
6
- let program: Command;
7
-
8
- beforeEach(() => {
9
- program = new Command();
10
- vi.clearAllMocks();
11
- });
12
-
13
- describe('registerProjectCommands', () => {
14
- it('should register project command group', () => {
15
- registerProjectCommands(program);
16
-
17
- const commands = program.commands;
18
- const projectCommand = commands.find(cmd => cmd.name() === 'project');
19
-
20
- expect(projectCommand).toBeDefined();
21
- expect(projectCommand?.description()).toBe('Manage Nestbox projects');
22
- });
23
-
24
- it('should register project use subcommand', () => {
25
- registerProjectCommands(program);
26
-
27
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
28
- const subCommands = projectCommand?.commands || [];
29
- const useCommand = subCommands.find(cmd => cmd.name() === 'use');
30
-
31
- expect(useCommand).toBeDefined();
32
- expect(useCommand?.description()).toBe('Set default project for all commands');
33
-
34
- // The command uses a required argument <project-name> which is part of the command definition
35
- expect(useCommand?.name()).toBe('use');
36
- });
37
-
38
- it('should register project add subcommand', () => {
39
- registerProjectCommands(program);
40
-
41
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
42
- const subCommands = projectCommand?.commands || [];
43
- const addCommand = subCommands.find(cmd => cmd.name() === 'add');
44
-
45
- expect(addCommand).toBeDefined();
46
- expect(addCommand?.description()).toBe('Add a project with optional alias');
47
-
48
- // The command uses required and optional arguments which are part of the command definition
49
- expect(addCommand?.name()).toBe('add');
50
- });
51
-
52
- it('should register project list subcommand', () => {
53
- registerProjectCommands(program);
54
-
55
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
56
- const subCommands = projectCommand?.commands || [];
57
- const listCommand = subCommands.find(cmd => cmd.name() === 'list');
58
-
59
- expect(listCommand).toBeDefined();
60
- expect(listCommand?.description()).toBe('List all projects');
61
- });
62
-
63
- it('should have all expected project subcommands', () => {
64
- registerProjectCommands(program);
65
-
66
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
67
- const subCommandNames = projectCommand?.commands.map(cmd => cmd.name()) || [];
68
-
69
- expect(subCommandNames).toContain('use');
70
- expect(subCommandNames).toContain('add');
71
- expect(subCommandNames).toContain('list');
72
- expect(subCommandNames).toHaveLength(3);
73
- });
74
-
75
- it('should have proper action functions for all commands', () => {
76
- registerProjectCommands(program);
77
-
78
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
79
- const subCommands = projectCommand?.commands || [];
80
-
81
- subCommands.forEach(cmd => {
82
- expect(typeof cmd.action).toBe('function');
83
- });
84
- });
85
-
86
- it('should register project use command with correct structure', () => {
87
- registerProjectCommands(program);
88
-
89
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
90
- const useCommand = projectCommand?.commands.find(cmd => cmd.name() === 'use');
91
-
92
- expect(useCommand?.name()).toBe('use');
93
- expect(useCommand?.description()).toBe('Set default project for all commands');
94
- expect(typeof useCommand?.action).toBe('function');
95
- });
96
-
97
- it('should register project add command with correct structure', () => {
98
- registerProjectCommands(program);
99
-
100
- const projectCommand = program.commands.find(cmd => cmd.name() === 'project');
101
- const addCommand = projectCommand?.commands.find(cmd => cmd.name() === 'add');
102
-
103
- expect(addCommand?.name()).toBe('add');
104
- expect(addCommand?.description()).toBe('Add a project with optional alias');
105
- expect(typeof addCommand?.action).toBe('function');
106
- });
107
- });
108
- });