@lobehub/lobehub 2.0.0-next.140 → 2.0.0-next.142

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 (30) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/Dockerfile +2 -0
  3. package/apps/desktop/src/main/controllers/__tests__/McpInstallCtr.test.ts +286 -0
  4. package/apps/desktop/src/main/controllers/__tests__/NotificationCtr.test.ts +347 -0
  5. package/apps/desktop/src/main/controllers/__tests__/RemoteServerConfigCtr.test.ts +645 -0
  6. package/apps/desktop/src/main/controllers/__tests__/RemoteServerSyncCtr.test.ts +372 -0
  7. package/apps/desktop/src/main/controllers/__tests__/SystemCtr.test.ts +276 -0
  8. package/apps/desktop/src/main/controllers/__tests__/UploadFileCtr.test.ts +171 -0
  9. package/apps/desktop/src/main/core/browser/__tests__/Browser.test.ts +573 -0
  10. package/apps/desktop/src/main/core/browser/__tests__/BrowserManager.test.ts +415 -0
  11. package/apps/desktop/src/main/core/infrastructure/__tests__/I18nManager.test.ts +353 -0
  12. package/apps/desktop/src/main/core/infrastructure/__tests__/IoCContainer.test.ts +156 -0
  13. package/apps/desktop/src/main/core/infrastructure/__tests__/ProtocolManager.test.ts +348 -0
  14. package/apps/desktop/src/main/core/infrastructure/__tests__/StaticFileServerManager.test.ts +481 -0
  15. package/apps/desktop/src/main/core/infrastructure/__tests__/StoreManager.test.ts +164 -0
  16. package/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts +513 -0
  17. package/changelog/v1.json +18 -0
  18. package/docs/development/database-schema.dbml +1 -2
  19. package/docs/self-hosting/environment-variables/model-provider.mdx +31 -0
  20. package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +30 -0
  21. package/package.json +1 -1
  22. package/packages/database/migrations/0055_rename_phone_number_to_phone.sql +4 -0
  23. package/packages/database/migrations/meta/0055_snapshot.json +8396 -0
  24. package/packages/database/migrations/meta/_journal.json +7 -0
  25. package/packages/database/src/core/migrations.json +11 -0
  26. package/packages/database/src/schemas/user.ts +1 -2
  27. package/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts +6 -3
  28. package/src/config/modelProviders/vertexai.ts +1 -1
  29. package/src/envs/llm.ts +4 -0
  30. package/src/server/modules/ModelRuntime/index.ts +4 -4
@@ -0,0 +1,171 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import type { App } from '@/core/App';
4
+
5
+ import UploadFileCtr from '../UploadFileCtr';
6
+
7
+ // Mock FileService module to prevent electron dependency issues
8
+ vi.mock('@/services/fileSrv', () => ({
9
+ default: class MockFileService {},
10
+ }));
11
+
12
+ // Mock FileService instance methods
13
+ const mockFileService = {
14
+ uploadFile: vi.fn(),
15
+ getFilePath: vi.fn(),
16
+ getFileHTTPURL: vi.fn(),
17
+ deleteFiles: vi.fn(),
18
+ };
19
+
20
+ const mockApp = {
21
+ getService: vi.fn(() => mockFileService),
22
+ } as unknown as App;
23
+
24
+ describe('UploadFileCtr', () => {
25
+ let controller: UploadFileCtr;
26
+
27
+ beforeEach(() => {
28
+ vi.clearAllMocks();
29
+ controller = new UploadFileCtr(mockApp);
30
+ });
31
+
32
+ describe('uploadFile', () => {
33
+ it('should upload file successfully', async () => {
34
+ const params = {
35
+ hash: 'abc123',
36
+ path: '/test/file.txt',
37
+ dataType: 'base64' as const,
38
+ data: 'dGVzdCBjb250ZW50',
39
+ filename: 'file.txt',
40
+ fileType: 'txt',
41
+ };
42
+ const expectedResult = { id: 'file-id-123', url: '/files/file-id-123' };
43
+ mockFileService.uploadFile.mockResolvedValue(expectedResult);
44
+
45
+ const result = await controller.uploadFile(params);
46
+
47
+ expect(result).toEqual(expectedResult);
48
+ expect(mockFileService.uploadFile).toHaveBeenCalledWith(params);
49
+ });
50
+
51
+ it('should handle upload error', async () => {
52
+ const params = {
53
+ hash: 'abc123',
54
+ path: '/test/file.txt',
55
+ dataType: 'base64' as const,
56
+ data: 'dGVzdCBjb250ZW50',
57
+ filename: 'file.txt',
58
+ fileType: 'txt',
59
+ };
60
+ const error = new Error('Upload failed');
61
+ mockFileService.uploadFile.mockRejectedValue(error);
62
+
63
+ await expect(controller.uploadFile(params)).rejects.toThrow('Upload failed');
64
+ });
65
+ });
66
+
67
+ describe('getFileUrlById', () => {
68
+ it('should get file path by id successfully', async () => {
69
+ const fileId = 'file-id-123';
70
+ const expectedPath = '/files/abc123.txt';
71
+ mockFileService.getFilePath.mockResolvedValue(expectedPath);
72
+
73
+ const result = await controller.getFileUrlById(fileId);
74
+
75
+ expect(result).toBe(expectedPath);
76
+ expect(mockFileService.getFilePath).toHaveBeenCalledWith(fileId);
77
+ });
78
+
79
+ it('should handle get file path error', async () => {
80
+ const fileId = 'non-existent-id';
81
+ const error = new Error('File not found');
82
+ mockFileService.getFilePath.mockRejectedValue(error);
83
+
84
+ await expect(controller.getFileUrlById(fileId)).rejects.toThrow('File not found');
85
+ });
86
+ });
87
+
88
+ describe('getFileHTTPURL', () => {
89
+ it('should get file HTTP URL successfully', async () => {
90
+ const filePath = '/files/abc123.txt';
91
+ const expectedUrl = 'http://localhost:3000/files/abc123.txt';
92
+ mockFileService.getFileHTTPURL.mockResolvedValue(expectedUrl);
93
+
94
+ const result = await controller.getFileHTTPURL(filePath);
95
+
96
+ expect(result).toBe(expectedUrl);
97
+ expect(mockFileService.getFileHTTPURL).toHaveBeenCalledWith(filePath);
98
+ });
99
+
100
+ it('should handle get HTTP URL error', async () => {
101
+ const filePath = '/files/abc123.txt';
102
+ const error = new Error('Failed to generate URL');
103
+ mockFileService.getFileHTTPURL.mockRejectedValue(error);
104
+
105
+ await expect(controller.getFileHTTPURL(filePath)).rejects.toThrow('Failed to generate URL');
106
+ });
107
+ });
108
+
109
+ describe('deleteFiles', () => {
110
+ it('should delete files successfully', async () => {
111
+ const paths = ['/files/file1.txt', '/files/file2.txt'];
112
+ mockFileService.deleteFiles.mockResolvedValue(undefined);
113
+
114
+ await controller.deleteFiles(paths);
115
+
116
+ expect(mockFileService.deleteFiles).toHaveBeenCalledWith(paths);
117
+ });
118
+
119
+ it('should handle delete files error', async () => {
120
+ const paths = ['/files/file1.txt'];
121
+ const error = new Error('Delete failed');
122
+ mockFileService.deleteFiles.mockRejectedValue(error);
123
+
124
+ await expect(controller.deleteFiles(paths)).rejects.toThrow('Delete failed');
125
+ });
126
+
127
+ it('should handle empty paths array', async () => {
128
+ const paths: string[] = [];
129
+ mockFileService.deleteFiles.mockResolvedValue(undefined);
130
+
131
+ await controller.deleteFiles(paths);
132
+
133
+ expect(mockFileService.deleteFiles).toHaveBeenCalledWith([]);
134
+ });
135
+ });
136
+
137
+ describe('createFile', () => {
138
+ it('should create file successfully', async () => {
139
+ const params = {
140
+ hash: 'xyz789',
141
+ path: '/test/newfile.txt',
142
+ dataType: 'base64' as const,
143
+ data: 'bmV3IGZpbGUgY29udGVudA==',
144
+ filename: 'newfile.txt',
145
+ fileType: 'txt',
146
+ };
147
+ const expectedResult = { id: 'new-file-id', url: '/files/new-file-id' };
148
+ mockFileService.uploadFile.mockResolvedValue(expectedResult);
149
+
150
+ const result = await controller.createFile(params);
151
+
152
+ expect(result).toEqual(expectedResult);
153
+ expect(mockFileService.uploadFile).toHaveBeenCalledWith(params);
154
+ });
155
+
156
+ it('should handle create file error', async () => {
157
+ const params = {
158
+ hash: 'xyz789',
159
+ path: '/test/newfile.txt',
160
+ dataType: 'base64' as const,
161
+ data: 'bmV3IGZpbGUgY29udGVudA==',
162
+ filename: 'newfile.txt',
163
+ fileType: 'txt',
164
+ };
165
+ const error = new Error('Create failed');
166
+ mockFileService.uploadFile.mockRejectedValue(error);
167
+
168
+ await expect(controller.createFile(params)).rejects.toThrow('Create failed');
169
+ });
170
+ });
171
+ });