@intellegens/cornerstone-client 0.0.9999-alpha-29 → 0.0.9999-alpha-31
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/dist/adapters/CollectionViewAdapter/index.integration.test.d.ts +1 -0
- package/dist/adapters/CollectionViewAdapter/index.integration.test.js +163 -0
- package/dist/adapters/SearchAdapter/index.d.ts +5 -1
- package/dist/adapters/SearchAdapter/index.js +25 -13
- package/dist/data/api/enum/read/ReadSelectedPropertyType.d.ts +4 -0
- package/dist/data/api/enum/read/ReadSelectedPropertyType.js +4 -0
- package/dist/data/auth/dto/index.d.ts +1 -0
- package/dist/data/auth/dto/index.js +1 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiCrudControllerClient/index.integration.test.js +34 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/ApiReadControllerClient/index.integration.test.js +59 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.d.ts +1 -0
- package/dist/services/api/HttpService/FetchHttpService.integration.test.js +52 -0
- package/dist/services/api/UserManagementControllerClient/index.d.ts +0 -6
- package/dist/services/api/UserManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/api/UserManagementControllerClient/index.integration.test.js +60 -0
- package/dist/services/api/UserManagementControllerClient/index.js +0 -29
- package/dist/services/auth/client/AuthService/index.d.ts +10 -2
- package/dist/services/auth/client/AuthService/index.js +40 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.d.ts +1 -0
- package/dist/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.js +89 -0
- package/package.json +6 -8
- package/src/adapters/CollectionViewAdapter/index.integration.test.ts +197 -0
- package/src/adapters/SearchAdapter/index.ts +30 -13
- package/src/data/api/dto/response/ApiSuccessResponseDto.ts +1 -1
- package/src/data/api/enum/read/ReadSelectedPropertyType.ts +5 -0
- package/src/data/auth/dto/index.ts +1 -0
- package/src/services/api/ApiCrudControllerClient/index.integration.test.ts +46 -0
- package/src/services/api/ApiReadControllerClient/index.integration.test.ts +71 -0
- package/src/services/api/HttpService/FetchHttpService.integration.test.ts +65 -0
- package/src/services/api/UserManagementControllerClient/index.integration.test.ts +69 -0
- package/src/services/api/UserManagementControllerClient/index.ts +0 -32
- package/src/services/auth/client/AuthService/index.ts +48 -2
- package/src/services/auth/client/AuthorizationManagementControllerClient/index.integration.test.ts +110 -0
- package/vitest-setup.ts +43 -0
- package/vitest.config.ts +59 -0
- package/jest.config.js +0 -29
- package/tests/ApiClients.test.ts +0 -284
- package/tests/CollectionViewAdapter.test.ts +0 -392
- package/tests/HttpService.test.ts +0 -303
- package/tests/setup.ts +0 -76
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { AngularHttpService } from '../../angular/projects/intellegens/cornerstone-client-angular/src/lib/services/AngularHttpService';
|
|
2
|
-
import { FetchHttpService, IHttpService } from '../src';
|
|
3
|
-
import { jest } from '@jest/globals';
|
|
4
|
-
import { of, throwError } from 'rxjs';
|
|
5
|
-
|
|
6
|
-
// Mock fetch for testing
|
|
7
|
-
const mockFetch = jest.fn() as jest.MockedFunction<typeof fetch>;
|
|
8
|
-
global.fetch = mockFetch;
|
|
9
|
-
|
|
10
|
-
// Mock Angular HttpClient
|
|
11
|
-
const mockAngularHttpClient = {
|
|
12
|
-
get: jest.fn(),
|
|
13
|
-
post: jest.fn(),
|
|
14
|
-
put: jest.fn(),
|
|
15
|
-
delete: jest.fn(),
|
|
16
|
-
patch: jest.fn(),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe('HttpService Implementations', () => {
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.clearAllMocks();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('FetchHttpService', () => {
|
|
25
|
-
let fetchService: FetchHttpService;
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
fetchService = new FetchHttpService();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should make a GET request successfully', async () => {
|
|
32
|
-
const mockResponse = {
|
|
33
|
-
ok: true,
|
|
34
|
-
status: 200,
|
|
35
|
-
statusText: 'OK',
|
|
36
|
-
headers: new Map([['content-type', 'application/json']]),
|
|
37
|
-
json: jest.fn<() => Promise<any>>().mockResolvedValue({ data: 'test' }),
|
|
38
|
-
text: jest.fn<() => Promise<string>>().mockResolvedValue('{"data":"test"}'),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Mock Headers.forEach
|
|
42
|
-
mockResponse.headers.forEach = jest.fn((callback: (value: string, key: string) => void) => {
|
|
43
|
-
callback('application/json', 'content-type');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
mockFetch.mockResolvedValue(mockResponse as any);
|
|
47
|
-
|
|
48
|
-
const result = await fetchService.request('https://api.example.com/test');
|
|
49
|
-
|
|
50
|
-
expect(mockFetch).toHaveBeenCalledWith('https://api.example.com/test', {
|
|
51
|
-
method: 'GET',
|
|
52
|
-
headers: undefined,
|
|
53
|
-
body: undefined,
|
|
54
|
-
credentials: 'include',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(result.ok).toBe(true);
|
|
58
|
-
expect(result.status).toBe(200);
|
|
59
|
-
expect(result.statusText).toBe('OK');
|
|
60
|
-
expect(result.headers).toEqual({ 'content-type': 'application/json' });
|
|
61
|
-
|
|
62
|
-
const jsonData = await result.json();
|
|
63
|
-
expect(jsonData).toEqual({ data: 'test' });
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should make a POST request with body', async () => {
|
|
67
|
-
const mockResponse = {
|
|
68
|
-
ok: true,
|
|
69
|
-
status: 201,
|
|
70
|
-
statusText: 'Created',
|
|
71
|
-
headers: new Map(),
|
|
72
|
-
json: jest.fn<() => Promise<any>>().mockResolvedValue({ id: 1 }),
|
|
73
|
-
text: jest.fn<() => Promise<string>>().mockResolvedValue('{"id":1}'),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
mockResponse.headers.forEach = jest.fn();
|
|
77
|
-
mockFetch.mockResolvedValue(mockResponse as any);
|
|
78
|
-
|
|
79
|
-
const testData = { name: 'test' };
|
|
80
|
-
const result = await fetchService.request('https://api.example.com/create', {
|
|
81
|
-
method: 'POST',
|
|
82
|
-
headers: { 'Content-Type': 'application/json' },
|
|
83
|
-
body: JSON.stringify(testData),
|
|
84
|
-
credentials: 'include',
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
expect(mockFetch).toHaveBeenCalledWith('https://api.example.com/create', {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
headers: { 'Content-Type': 'application/json' },
|
|
90
|
-
body: JSON.stringify(testData),
|
|
91
|
-
credentials: 'include',
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
expect(result.ok).toBe(true);
|
|
95
|
-
expect(result.status).toBe(201);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should handle fetch errors', async () => {
|
|
99
|
-
mockFetch.mockRejectedValue(new Error('Network error'));
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
await fetchService.request('https://api.example.com/error');
|
|
103
|
-
fail('Should have thrown an error');
|
|
104
|
-
} catch (error: any) {
|
|
105
|
-
expect(error.message).toBe('Network error');
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should handle non-ok responses', async () => {
|
|
110
|
-
const mockResponse = {
|
|
111
|
-
ok: false,
|
|
112
|
-
status: 404,
|
|
113
|
-
statusText: 'Not Found',
|
|
114
|
-
headers: new Map(),
|
|
115
|
-
json: jest.fn<() => Promise<any>>().mockResolvedValue({ error: 'Not found' }),
|
|
116
|
-
text: jest.fn<() => Promise<string>>().mockResolvedValue('{"error":"Not found"}'),
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
mockResponse.headers.forEach = jest.fn();
|
|
120
|
-
mockFetch.mockResolvedValue(mockResponse as any);
|
|
121
|
-
|
|
122
|
-
const result = await fetchService.request('https://api.example.com/notfound');
|
|
123
|
-
|
|
124
|
-
expect(result.ok).toBe(false);
|
|
125
|
-
expect(result.status).toBe(404);
|
|
126
|
-
expect(result.statusText).toBe('Not Found');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('AngularHttpService', () => {
|
|
131
|
-
let angularService: AngularHttpService;
|
|
132
|
-
|
|
133
|
-
beforeEach(() => {
|
|
134
|
-
angularService = new AngularHttpService(mockAngularHttpClient as any);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('should throw error if no HttpClient provided', () => {
|
|
138
|
-
expect(() => new AngularHttpService(null as any)).toThrow('Angular HttpClient instance is required');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should make a GET request successfully', async () => {
|
|
142
|
-
const mockResponse = {
|
|
143
|
-
status: 200,
|
|
144
|
-
statusText: 'OK',
|
|
145
|
-
body: { data: 'test' },
|
|
146
|
-
headers: {
|
|
147
|
-
keys: jest.fn().mockReturnValue(['content-type']),
|
|
148
|
-
get: jest.fn().mockReturnValue('application/json'),
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
mockAngularHttpClient.get.mockReturnValue(of(mockResponse));
|
|
153
|
-
|
|
154
|
-
const result = await angularService.request('https://api.example.com/test');
|
|
155
|
-
|
|
156
|
-
expect(mockAngularHttpClient.get).toHaveBeenCalledWith('https://api.example.com/test', {
|
|
157
|
-
headers: {},
|
|
158
|
-
withCredentials: false,
|
|
159
|
-
observe: 'response',
|
|
160
|
-
responseType: 'json',
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
expect(result.ok).toBe(true);
|
|
164
|
-
expect(result.status).toBe(200);
|
|
165
|
-
expect(result.statusText).toBe('OK');
|
|
166
|
-
expect(result.headers).toEqual({ 'content-type': 'application/json' });
|
|
167
|
-
|
|
168
|
-
const jsonData = await result.json();
|
|
169
|
-
expect(jsonData).toEqual({ data: 'test' });
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('should make a POST request with body', async () => {
|
|
173
|
-
const mockResponse = {
|
|
174
|
-
status: 201,
|
|
175
|
-
statusText: 'Created',
|
|
176
|
-
body: { id: 1 },
|
|
177
|
-
headers: {
|
|
178
|
-
keys: jest.fn().mockReturnValue([]),
|
|
179
|
-
get: jest.fn(),
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
mockAngularHttpClient.post.mockReturnValue(of(mockResponse));
|
|
184
|
-
|
|
185
|
-
const testData = { name: 'test' };
|
|
186
|
-
const result = await angularService.request('https://api.example.com/create', {
|
|
187
|
-
method: 'POST',
|
|
188
|
-
headers: { 'Content-Type': 'application/json' },
|
|
189
|
-
body: JSON.stringify(testData),
|
|
190
|
-
credentials: 'include',
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
expect(mockAngularHttpClient.post).toHaveBeenCalledWith('https://api.example.com/create', testData, {
|
|
194
|
-
headers: { 'Content-Type': 'application/json' },
|
|
195
|
-
withCredentials: true,
|
|
196
|
-
observe: 'response',
|
|
197
|
-
responseType: 'json',
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
expect(result.ok).toBe(true);
|
|
201
|
-
expect(result.status).toBe(201);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('should handle PUT requests', async () => {
|
|
205
|
-
const mockResponse = {
|
|
206
|
-
status: 200,
|
|
207
|
-
statusText: 'OK',
|
|
208
|
-
body: { updated: true },
|
|
209
|
-
headers: {
|
|
210
|
-
keys: jest.fn().mockReturnValue([]),
|
|
211
|
-
get: jest.fn(),
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
mockAngularHttpClient.put.mockReturnValue(of(mockResponse));
|
|
216
|
-
|
|
217
|
-
const result = await angularService.request('https://api.example.com/update', {
|
|
218
|
-
method: 'PUT',
|
|
219
|
-
body: JSON.stringify({ id: 1, name: 'updated' }),
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
expect(mockAngularHttpClient.put).toHaveBeenCalled();
|
|
223
|
-
expect(result.ok).toBe(true);
|
|
224
|
-
expect(result.status).toBe(200);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should handle DELETE requests', async () => {
|
|
228
|
-
const mockResponse = {
|
|
229
|
-
status: 204,
|
|
230
|
-
statusText: 'No Content',
|
|
231
|
-
body: null,
|
|
232
|
-
headers: {
|
|
233
|
-
keys: jest.fn().mockReturnValue([]),
|
|
234
|
-
get: jest.fn(),
|
|
235
|
-
},
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
mockAngularHttpClient.delete.mockReturnValue(of(mockResponse));
|
|
239
|
-
|
|
240
|
-
const result = await angularService.request('https://api.example.com/delete/1', {
|
|
241
|
-
method: 'DELETE',
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
expect(mockAngularHttpClient.delete).toHaveBeenCalled();
|
|
245
|
-
expect(result.ok).toBe(true);
|
|
246
|
-
expect(result.status).toBe(204);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('should handle Angular HttpErrorResponse', async () => {
|
|
250
|
-
const mockError = {
|
|
251
|
-
status: 400,
|
|
252
|
-
statusText: 'Bad Request',
|
|
253
|
-
error: { message: 'Invalid data' },
|
|
254
|
-
headers: {
|
|
255
|
-
keys: jest.fn().mockReturnValue(['content-type']),
|
|
256
|
-
get: jest.fn().mockReturnValue('application/json'),
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
mockAngularHttpClient.get.mockReturnValue(throwError(() => mockError));
|
|
261
|
-
|
|
262
|
-
const result = await angularService.request('https://api.example.com/error');
|
|
263
|
-
|
|
264
|
-
expect(result.ok).toBe(false);
|
|
265
|
-
expect(result.status).toBe(400);
|
|
266
|
-
expect(result.statusText).toBe('Bad Request');
|
|
267
|
-
expect(result.headers).toEqual({ 'content-type': 'application/json' });
|
|
268
|
-
|
|
269
|
-
const errorData = await result.json();
|
|
270
|
-
expect(errorData).toEqual({ message: 'Invalid data' });
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('should throw error for unsupported HTTP methods', async () => {
|
|
274
|
-
try {
|
|
275
|
-
await angularService.request('https://api.example.com/test', { method: 'OPTIONS' as any });
|
|
276
|
-
fail('Should have thrown an error');
|
|
277
|
-
} catch (error: any) {
|
|
278
|
-
expect(error.message).toContain('Unsupported HTTP method: OPTIONS');
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('should handle non-Angular errors', async () => {
|
|
283
|
-
mockAngularHttpClient.get.mockReturnValue(throwError(() => new Error('Network error')));
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
await angularService.request('https://api.example.com/error');
|
|
287
|
-
fail('Should have thrown an error');
|
|
288
|
-
} catch (error: any) {
|
|
289
|
-
expect(error.message).toBe('Network error');
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
describe('Interface Compliance', () => {
|
|
295
|
-
it('should implement IHttpService interface correctly', () => {
|
|
296
|
-
const fetchService: IHttpService = new FetchHttpService();
|
|
297
|
-
const angularService: IHttpService = new AngularHttpService(mockAngularHttpClient as any);
|
|
298
|
-
|
|
299
|
-
expect(typeof fetchService.request).toBe('function');
|
|
300
|
-
expect(typeof angularService.request).toBe('function');
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
});
|
package/tests/setup.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// Jest setup file for global test configuration
|
|
2
|
-
|
|
3
|
-
import { jest } from '@jest/globals';
|
|
4
|
-
|
|
5
|
-
// Mock global fetch with proper Response structure
|
|
6
|
-
const mockFetch = jest.fn(async (url: string, config?: RequestInit) => {
|
|
7
|
-
// Create a proper Headers object mock
|
|
8
|
-
const mockHeaders = {
|
|
9
|
-
get: (name: string) => {
|
|
10
|
-
if (name === 'CORNERSTONE-API-BASEURL') return 'https://api.example.com';
|
|
11
|
-
if (name === 'content-type') return 'application/json';
|
|
12
|
-
return null;
|
|
13
|
-
},
|
|
14
|
-
forEach: (callback: (value: string, key: string) => void) => {
|
|
15
|
-
callback('application/json', 'content-type');
|
|
16
|
-
if (url === window.location.href || url === './') {
|
|
17
|
-
callback('https://api.example.com', 'CORNERSTONE-API-BASEURL');
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Default successful response
|
|
23
|
-
const mockResponse = {
|
|
24
|
-
ok: true,
|
|
25
|
-
status: 200,
|
|
26
|
-
statusText: 'OK',
|
|
27
|
-
headers: mockHeaders,
|
|
28
|
-
json: jest.fn<() => Promise<any>>().mockResolvedValue({}),
|
|
29
|
-
text: jest.fn<() => Promise<string>>().mockResolvedValue(''),
|
|
30
|
-
blob: jest.fn<() => Promise<Blob>>().mockResolvedValue(new Blob()),
|
|
31
|
-
arrayBuffer: jest.fn<() => Promise<ArrayBuffer>>().mockResolvedValue(new ArrayBuffer(0)),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Handle websettings.json requests
|
|
35
|
-
if (url.includes('websettings.json')) {
|
|
36
|
-
return {
|
|
37
|
-
...mockResponse,
|
|
38
|
-
status: 404,
|
|
39
|
-
ok: false,
|
|
40
|
-
statusText: 'Not Found',
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return mockResponse;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
global.fetch = mockFetch as any;
|
|
48
|
-
|
|
49
|
-
// Mock window.location for tests that might use it
|
|
50
|
-
Object.defineProperty(window, 'location', {
|
|
51
|
-
value: {
|
|
52
|
-
href: 'http://localhost:3000',
|
|
53
|
-
origin: 'http://localhost:3000',
|
|
54
|
-
protocol: 'http:',
|
|
55
|
-
host: 'localhost:3000',
|
|
56
|
-
hostname: 'localhost',
|
|
57
|
-
port: '3000',
|
|
58
|
-
pathname: '/',
|
|
59
|
-
search: '',
|
|
60
|
-
hash: '',
|
|
61
|
-
assign: jest.fn(),
|
|
62
|
-
replace: jest.fn(),
|
|
63
|
-
reload: jest.fn(),
|
|
64
|
-
},
|
|
65
|
-
writable: true,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Mock console methods to reduce noise in tests
|
|
69
|
-
global.console = {
|
|
70
|
-
...console,
|
|
71
|
-
log: jest.fn(),
|
|
72
|
-
debug: jest.fn(),
|
|
73
|
-
info: jest.fn(),
|
|
74
|
-
warn: jest.fn(),
|
|
75
|
-
error: jest.fn(),
|
|
76
|
-
};
|