newportsite 1.1.3
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/newportsite-1.1.3.tgz +0 -0
- package/ng-package.json +7 -0
- package/obfuscate.js +70 -0
- package/package.json +15 -0
- package/src/lib/app.component.ts +47 -0
- package/src/lib/app.routing.ts +38 -0
- package/src/lib/auth/alert.component.html +5 -0
- package/src/lib/auth/alert.component.ts +24 -0
- package/src/lib/auth/auth.component.html +1 -0
- package/src/lib/auth/auth.component.ts +10 -0
- package/src/lib/auth/auth.routes.ts +16 -0
- package/src/lib/auth/index.ts +4 -0
- package/src/lib/auth/login.component.html +87 -0
- package/src/lib/auth/login.component.ts +158 -0
- package/src/lib/auth/models/index.ts +1 -0
- package/src/lib/auth/models/user.ts +25 -0
- package/src/lib/auth/register.component.html +157 -0
- package/src/lib/auth/register.component.ts +219 -0
- package/src/lib/auth/services/alert.service.ts +47 -0
- package/src/lib/auth/services/auth.service.ts +28 -0
- package/src/lib/auth/services/index.ts +3 -0
- package/src/lib/auth/services/user.service.spec.ts +112 -0
- package/src/lib/auth/services/user.service.ts +47 -0
- package/src/lib/common/card.component.html +72 -0
- package/src/lib/common/card.component.ts +102 -0
- package/src/lib/common/commands.component.html +8 -0
- package/src/lib/common/commands.component.ts +42 -0
- package/src/lib/common/context.component.html +9 -0
- package/src/lib/common/context.component.ts +38 -0
- package/src/lib/common/grid.component.html +20 -0
- package/src/lib/common/grid.component.ts +747 -0
- package/src/lib/common/index.ts +9 -0
- package/src/lib/common/loader.component.html +5 -0
- package/src/lib/common/loader.component.ts +27 -0
- package/src/lib/common/lookup.component.html +29 -0
- package/src/lib/common/lookup.component.ts +115 -0
- package/src/lib/common/messagebox.component.html +39 -0
- package/src/lib/common/messagebox.component.ts +74 -0
- package/src/lib/common/theme-toggle.component.ts +139 -0
- package/src/lib/config.ts +62 -0
- package/src/lib/containers/default-layout/default-layout.component.html +191 -0
- package/src/lib/containers/default-layout/default-layout.component.ts +158 -0
- package/src/lib/containers/default-layout/index.ts +1 -0
- package/src/lib/containers/index.ts +1 -0
- package/src/lib/directives/component.draggable.ts +80 -0
- package/src/lib/directives/index.ts +2 -0
- package/src/lib/directives/input.directive.spec.ts +158 -0
- package/src/lib/directives/input.directive.ts +210 -0
- package/src/lib/home/dashboard/dashboard.component.html +38 -0
- package/src/lib/home/dashboard/dashboard.component.ts +50 -0
- package/src/lib/home/dashboard/index.ts +1 -0
- package/src/lib/home/index.component.html +1 -0
- package/src/lib/home/index.component.ts +10 -0
- package/src/lib/home/index.routes.ts +29 -0
- package/src/lib/home/index.ts +1 -0
- package/src/lib/home/info/index.ts +1 -0
- package/src/lib/home/info/info.component.css +476 -0
- package/src/lib/home/info/info.component.html +174 -0
- package/src/lib/home/info/info.component.ts +287 -0
- package/src/lib/home/model/article.component.html +10 -0
- package/src/lib/home/model/article.component.ts +50 -0
- package/src/lib/home/model/barchart.component.html +8 -0
- package/src/lib/home/model/barchart.component.ts +59 -0
- package/src/lib/home/model/index.ts +7 -0
- package/src/lib/home/model/itemdetail.component.html +25 -0
- package/src/lib/home/model/itemdetail.component.ts +93 -0
- package/src/lib/home/model/itemtab.component.html +25 -0
- package/src/lib/home/model/itemtab.component.ts +105 -0
- package/src/lib/home/model/model.component.html +121 -0
- package/src/lib/home/model/model.component.ts +510 -0
- package/src/lib/home/model/modeltoolbar.component.html +111 -0
- package/src/lib/home/model/modeltoolbar.component.ts +157 -0
- package/src/lib/home/model/navigation.component.html +86 -0
- package/src/lib/home/model/navigation.component.ts +247 -0
- package/src/lib/home/model/services/index.ts +1 -0
- package/src/lib/home/model/services/model.service.spec.ts +423 -0
- package/src/lib/home/model/services/model.service.ts +319 -0
- package/src/lib/home/modelsearch/index.ts +1 -0
- package/src/lib/home/modelsearch/modelsearch.component.html +124 -0
- package/src/lib/home/modelsearch/modelsearch.component.ts +453 -0
- package/src/lib/interfaces/data.interface.ts +131 -0
- package/src/lib/interfaces/index.ts +2 -0
- package/src/lib/interfaces/item.interface.ts +438 -0
- package/src/lib/players/lookup/lookup.directive.ts +6 -0
- package/src/lib/players/lookup/lookup.item.component.ts +37 -0
- package/src/lib/players/lookup/lookup.item.ts +9 -0
- package/src/lib/players/lookup/lookup.player.component.ts +59 -0
- package/src/lib/players/lookup/lookup.selector.component.ts +41 -0
- package/src/lib/players/model/model.directive.ts +6 -0
- package/src/lib/players/model/model.item.component.spec.ts +311 -0
- package/src/lib/players/model/model.item.component.ts +3457 -0
- package/src/lib/players/model/model.item.ts +9 -0
- package/src/lib/players/model/model.player.component.ts +109 -0
- package/src/lib/players/model/model.selector.component.ts +59 -0
- package/src/lib/scheduler/scheduler.component.html +13 -0
- package/src/lib/scheduler/scheduler.component.scss +6 -0
- package/src/lib/scheduler/scheduler.component.ts +296 -0
- package/src/lib/scheduler/scheduler.routes.ts +15 -0
- package/src/lib/scheduler/schedulerdialog.component.html +72 -0
- package/src/lib/scheduler/schedulerdialog.component.ts +208 -0
- package/src/lib/scheduler/services/scheduler.service.ts +133 -0
- package/src/lib/services/auth-state.service.ts +129 -0
- package/src/lib/services/auth.interceptor.spec.ts +144 -0
- package/src/lib/services/auth.interceptor.ts +44 -0
- package/src/lib/services/cache.service.spec.ts +143 -0
- package/src/lib/services/cache.service.ts +71 -0
- package/src/lib/services/global-error-handler.spec.ts +39 -0
- package/src/lib/services/global-error-handler.ts +28 -0
- package/src/lib/services/global.service.spec.ts +801 -0
- package/src/lib/services/global.service.ts +724 -0
- package/src/lib/services/message.service.ts +556 -0
- package/src/lib/services/theme.service.ts +96 -0
- package/src/lib/template/authtemplate.component.html +6 -0
- package/src/lib/template/authtemplate.component.ts +13 -0
- package/src/lib/template/basetemplate.component.html +7 -0
- package/src/lib/template/basetemplate.component.ts +13 -0
- package/src/lib/template/index.ts +3 -0
- package/src/lib/template/modeltemplate.component.html +7 -0
- package/src/lib/template/modeltemplate.component.ts +21 -0
- package/src/lib/utils/piva.spec.ts +56 -0
- package/src/lib/utils/piva.ts +29 -0
- package/src/lib/validators/email.validator.spec.ts +57 -0
- package/src/lib/validators/email.validator.ts +17 -0
- package/src/lib/validators/equalPasswords.validator.spec.ts +54 -0
- package/src/lib/validators/equalPasswords.validator.ts +17 -0
- package/src/lib/validators/index.ts +2 -0
- package/src/lib/version.ts +1 -0
- package/src/public-api.ts +64 -0
- package/src/typings.d.ts +2 -0
- package/tsconfig.lib.json +18 -0
- package/tsconfig.lib.prod.json +9 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import {
|
|
3
|
+
HttpClientTestingModule,
|
|
4
|
+
HttpTestingController,
|
|
5
|
+
} from '@angular/common/http/testing';
|
|
6
|
+
import { Router } from '@angular/router';
|
|
7
|
+
import { Location } from '@angular/common';
|
|
8
|
+
import { ManagmentService } from './model.service';
|
|
9
|
+
import { GlobalService } from '../../../services/global.service';
|
|
10
|
+
import { ManagmentInterface } from '../../../interfaces/index';
|
|
11
|
+
import { NEWPORT_CONFIG } from '../../../config';
|
|
12
|
+
|
|
13
|
+
const TEST_API_URL = 'http://test/';
|
|
14
|
+
|
|
15
|
+
// ── Stubs ────────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
const routerStub = { navigateByUrl: jest.fn().mockResolvedValue(true) };
|
|
18
|
+
const locationStub = { normalize: (url: string) => url };
|
|
19
|
+
|
|
20
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
/** Minimal ManagmentInterface for each test. */
|
|
23
|
+
function makeManagment(overrides: Partial<ManagmentInterface> = {}): ManagmentInterface {
|
|
24
|
+
return {
|
|
25
|
+
functionId: 'read',
|
|
26
|
+
appId: 'APP',
|
|
27
|
+
entId: 'ENT',
|
|
28
|
+
year: 2024,
|
|
29
|
+
keys: 'prg=1',
|
|
30
|
+
fields: [],
|
|
31
|
+
states: [],
|
|
32
|
+
entIds: [],
|
|
33
|
+
keyId: '1',
|
|
34
|
+
filterId: '',
|
|
35
|
+
page: 1,
|
|
36
|
+
data: '',
|
|
37
|
+
...overrides,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const BASE_URL = TEST_API_URL + 'managment';
|
|
42
|
+
|
|
43
|
+
// ── Test suite ───────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
describe('ManagmentService', () => {
|
|
46
|
+
let svc: ManagmentService;
|
|
47
|
+
let http: HttpTestingController;
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
localStorage.clear();
|
|
51
|
+
TestBed.configureTestingModule({
|
|
52
|
+
imports: [HttpClientTestingModule],
|
|
53
|
+
providers: [
|
|
54
|
+
ManagmentService,
|
|
55
|
+
GlobalService,
|
|
56
|
+
{ provide: Router, useValue: routerStub },
|
|
57
|
+
{ provide: Location, useValue: locationStub },
|
|
58
|
+
{ provide: NEWPORT_CONFIG, useValue: { apiUrl: TEST_API_URL, logicFactory: () => {}, projectsInfoLoader: () => Promise.resolve({ getData: () => ({ entities: [] } as any), getSchema: () => ({ entities: [] } as any) }) } },
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
svc = TestBed.inject(ManagmentService);
|
|
63
|
+
http = TestBed.inject(HttpTestingController);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
http.verify();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// ── getItemsData ─────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
describe('getItemsData()', () => {
|
|
73
|
+
it('hits the correct GetItemsData URL', () => {
|
|
74
|
+
const m = makeManagment({ filterId: 'FILT' });
|
|
75
|
+
|
|
76
|
+
svc.getItemsData(m).subscribe();
|
|
77
|
+
|
|
78
|
+
const req = http.expectOne(r => r.url.includes('GetItemsData'));
|
|
79
|
+
expect(req.request.method).toBe('GET');
|
|
80
|
+
expect(req.request.url).toContain('/APP/2024/FILT/1/read/ENT');
|
|
81
|
+
req.flush({ items: [], total: 0, page: 1 });
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// ── getAllItemsData ───────────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
describe('getAllItemsData()', () => {
|
|
88
|
+
it('hits the correct GetAllItemsData URL', () => {
|
|
89
|
+
const m = makeManagment({ page: 2 });
|
|
90
|
+
|
|
91
|
+
svc.getAllItemsData(m).subscribe();
|
|
92
|
+
|
|
93
|
+
const req = http.expectOne(r => r.url.includes('GetAllItemsData'));
|
|
94
|
+
expect(req.request.method).toBe('GET');
|
|
95
|
+
expect(req.request.url).toContain('/APP/2024/2');
|
|
96
|
+
req.flush({ items: [], total: 0, page: 2 });
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// ── getItemsCount ────────────────────────────────────────────────────────
|
|
101
|
+
|
|
102
|
+
describe('getItemsCount()', () => {
|
|
103
|
+
it('hits the correct GetItemsCount URL', () => {
|
|
104
|
+
const m = makeManagment();
|
|
105
|
+
|
|
106
|
+
svc.getItemsCount(m).subscribe();
|
|
107
|
+
|
|
108
|
+
const req = http.expectOne(r => r.url.includes('GetItemsCount'));
|
|
109
|
+
expect(req.request.method).toBe('GET');
|
|
110
|
+
expect(req.request.url).toContain('/APP/2024');
|
|
111
|
+
req.flush(42);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ── deleteItem ───────────────────────────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
describe('deleteItem()', () => {
|
|
118
|
+
it('sends a DELETE to the correct URL', () => {
|
|
119
|
+
const m = makeManagment({ keyId: '7' });
|
|
120
|
+
|
|
121
|
+
svc.deleteItem(m).subscribe();
|
|
122
|
+
|
|
123
|
+
const req = http.expectOne(r => r.url.includes('DeleteItem'));
|
|
124
|
+
expect(req.request.method).toBe('DELETE');
|
|
125
|
+
expect(req.request.url).toContain('/APP/2024/7');
|
|
126
|
+
req.flush(true);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// ── postData ─────────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
describe('postData()', () => {
|
|
133
|
+
it('sends a POST with the JSON-serialised managment body', () => {
|
|
134
|
+
const m = makeManagment();
|
|
135
|
+
|
|
136
|
+
svc.postData(m).subscribe();
|
|
137
|
+
|
|
138
|
+
const req = http.expectOne(`${BASE_URL}`);
|
|
139
|
+
expect(req.request.method).toBe('POST');
|
|
140
|
+
expect(JSON.parse(req.request.body)).toMatchObject({ appId: 'APP', entId: 'ENT' });
|
|
141
|
+
req.flush({ svg: '', dataFile: '', booleanResult: false });
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ── putData ──────────────────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
describe('putData()', () => {
|
|
148
|
+
it('sends a PUT with the JSON-serialised managment body', () => {
|
|
149
|
+
const m = makeManagment();
|
|
150
|
+
|
|
151
|
+
svc.putData(m).subscribe();
|
|
152
|
+
|
|
153
|
+
const req = http.expectOne(`${BASE_URL}`);
|
|
154
|
+
expect(req.request.method).toBe('PUT');
|
|
155
|
+
expect(JSON.parse(req.request.body)).toMatchObject({ appId: 'APP', entId: 'ENT' });
|
|
156
|
+
req.flush({ svg: '', dataFile: '', booleanResult: false });
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// ── getFields ────────────────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
describe('getFields()', () => {
|
|
163
|
+
it('hits the GetResource URL with entity name + .json', () => {
|
|
164
|
+
const m = makeManagment();
|
|
165
|
+
|
|
166
|
+
svc.getFields(m).subscribe();
|
|
167
|
+
|
|
168
|
+
const req = http.expectOne(r => r.url.includes('GetResource'));
|
|
169
|
+
expect(req.request.method).toBe('GET');
|
|
170
|
+
expect(req.request.url).toContain('ENT.json');
|
|
171
|
+
req.flush([]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// ── getItemsByName ───────────────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
describe('getItemsByName()', () => {
|
|
178
|
+
it('hits the GetItemsInfo URL', () => {
|
|
179
|
+
const m = makeManagment({ entIds: ['ENT', 'ENT2'] });
|
|
180
|
+
|
|
181
|
+
svc.getItemsByName(m).subscribe();
|
|
182
|
+
|
|
183
|
+
const req = http.expectOne(r => r.url.includes('GetItemsInfo'));
|
|
184
|
+
expect(req.request.method).toBe('GET');
|
|
185
|
+
req.flush([]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// ── handleError (via observable) ─────────────────────────────────────────
|
|
190
|
+
|
|
191
|
+
describe('error handling', () => {
|
|
192
|
+
it('propagates server errors as a typed Error', (done) => {
|
|
193
|
+
const m = makeManagment();
|
|
194
|
+
|
|
195
|
+
svc.getItemsCount(m).subscribe({
|
|
196
|
+
error: (err: Error) => {
|
|
197
|
+
expect(err.message).toContain('Server Error');
|
|
198
|
+
done();
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// retry(3) makes 4 total attempts; flush each with the same error
|
|
203
|
+
for (let i = 0; i < 4; i++) {
|
|
204
|
+
const req = http.expectOne(r => r.url.includes('GetItemsCount'));
|
|
205
|
+
req.flush('Server Error', { status: 500, statusText: 'Internal Server Error' });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('propagates client-side network errors as a typed Error', (done) => {
|
|
210
|
+
const m = makeManagment();
|
|
211
|
+
|
|
212
|
+
svc.getItemsCount(m).subscribe({
|
|
213
|
+
error: (err: Error) => {
|
|
214
|
+
expect(err.message).toContain('Client Error');
|
|
215
|
+
done();
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// retry(3) makes 4 total attempts; error each one
|
|
220
|
+
for (let i = 0; i < 4; i++) {
|
|
221
|
+
const req = http.expectOne(r => r.url.includes('GetItemsCount'));
|
|
222
|
+
req.error(new ErrorEvent('error', { message: 'Network failure' }));
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ── downloadFile ─────────────────────────────────────────────────────────
|
|
228
|
+
|
|
229
|
+
describe('downloadFile()', () => {
|
|
230
|
+
it('sends a GET request to the correct GetData URL', () => {
|
|
231
|
+
const m = makeManagment();
|
|
232
|
+
svc.downloadFile(m).subscribe();
|
|
233
|
+
|
|
234
|
+
const req = http.expectOne(r => r.url.includes('GetData') && r.method === 'GET');
|
|
235
|
+
expect(req.request.url).toContain('/read/APP/2024/ENT/prg=1/1');
|
|
236
|
+
req.flush(new Blob(['PDF']));
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('accepts a custom fileType', () => {
|
|
240
|
+
const m = makeManagment();
|
|
241
|
+
svc.downloadFile(m, 'zip').subscribe();
|
|
242
|
+
|
|
243
|
+
const req = http.expectOne(r => r.url.includes('GetData'));
|
|
244
|
+
req.flush(new Blob(['ZIP']));
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ── downloadFileAll ───────────────────────────────────────────────────────
|
|
249
|
+
|
|
250
|
+
describe('downloadFileAll()', () => {
|
|
251
|
+
it('sends a GET request to the correct GetItemsData URL', () => {
|
|
252
|
+
const m = makeManagment({ filterId: 'FILT' });
|
|
253
|
+
svc.downloadFileAll(m).subscribe();
|
|
254
|
+
|
|
255
|
+
const req = http.expectOne(r => r.url.includes('GetItemsData') && r.method === 'GET');
|
|
256
|
+
expect(req.request.url).toContain('/APP/2024/FILT/1/read/ENT');
|
|
257
|
+
req.flush(new Blob(['ZIP']));
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// ── downloadPDF ───────────────────────────────────────────────────────────
|
|
262
|
+
|
|
263
|
+
describe('downloadPDF()', () => {
|
|
264
|
+
it('returns a Blob on success', (done) => {
|
|
265
|
+
const m = makeManagment();
|
|
266
|
+
svc.downloadPDF(m).subscribe(result => {
|
|
267
|
+
expect(result).toBeInstanceOf(Blob);
|
|
268
|
+
done();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const req = http.expectOne(r => r.url.includes('GetData'));
|
|
272
|
+
req.flush(new Blob(['PDF content']));
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('retries on network error and eventually succeeds', (done) => {
|
|
276
|
+
const m = makeManagment();
|
|
277
|
+
svc.downloadPDF(m).subscribe(result => {
|
|
278
|
+
expect(result).toBeInstanceOf(Blob);
|
|
279
|
+
done();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
for (let i = 0; i < 3; i++) {
|
|
283
|
+
const req = http.expectOne(r => r.url.includes('GetData'));
|
|
284
|
+
req.error(new ErrorEvent('network error', { message: 'failed' }));
|
|
285
|
+
}
|
|
286
|
+
const req = http.expectOne(r => r.url.includes('GetData'));
|
|
287
|
+
req.flush(new Blob(['PDF retry']));
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// ── getGroupedDataArtPromise ──────────────────────────────────────────────
|
|
292
|
+
|
|
293
|
+
describe('getGroupedDataArtPromise()', () => {
|
|
294
|
+
it('resolves data from the GetGroupedDataArt endpoint', async () => {
|
|
295
|
+
const m = makeManagment({ codmag: 'MAG1', codart: 'ART1' } as any);
|
|
296
|
+
const promise = svc.getGroupedDataArtPromise(m);
|
|
297
|
+
|
|
298
|
+
const req = http.expectOne(r => r.url.includes('GetGroupedDataArt'));
|
|
299
|
+
expect(req.request.url).toContain('/APP/2024/MAG1/ART1');
|
|
300
|
+
req.flush({ items: [{ code: 'X' }] });
|
|
301
|
+
|
|
302
|
+
const result = await promise;
|
|
303
|
+
expect((result as any).items).toHaveLength(1);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// ── getItemsState ─────────────────────────────────────────────────────────
|
|
308
|
+
|
|
309
|
+
describe('getItemsState()', () => {
|
|
310
|
+
it('hits the GetItemsState URL', () => {
|
|
311
|
+
const m = makeManagment({ keyId: '5' });
|
|
312
|
+
svc.getItemsState(m).subscribe();
|
|
313
|
+
|
|
314
|
+
const req = http.expectOne(r => r.url.includes('GetItemsState'));
|
|
315
|
+
expect(req.request.method).toBe('GET');
|
|
316
|
+
expect(req.request.url).toContain('/APP/2024/5');
|
|
317
|
+
req.flush([]);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// ── getItemsSStatePromise ─────────────────────────────────────────────────
|
|
322
|
+
|
|
323
|
+
describe('getItemsSStatePromise()', () => {
|
|
324
|
+
it('resolves with the items state array', async () => {
|
|
325
|
+
const m = makeManagment({ keyId: '3' });
|
|
326
|
+
const promise = svc.getItemsSStatePromise(m);
|
|
327
|
+
|
|
328
|
+
const req = http.expectOne(r => r.url.includes('GetItemsState'));
|
|
329
|
+
req.flush([{ id: 'state1' }]);
|
|
330
|
+
|
|
331
|
+
const result = await promise;
|
|
332
|
+
expect(result).toHaveLength(1);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// ── getItemsByNamePromise ─────────────────────────────────────────────────
|
|
337
|
+
|
|
338
|
+
describe('getItemsByNamePromise()', () => {
|
|
339
|
+
it('resolves with the items from GetItemsInfo', async () => {
|
|
340
|
+
const m = makeManagment({ entIds: ['ENT', 'ENT2'] });
|
|
341
|
+
const promise = svc.getItemsByNamePromise(m);
|
|
342
|
+
|
|
343
|
+
const req = http.expectOne(r => r.url.includes('GetItemsInfo'));
|
|
344
|
+
req.flush([{ id: 'item1' }, { id: 'item2' }]);
|
|
345
|
+
|
|
346
|
+
const result = await promise;
|
|
347
|
+
expect(result).toHaveLength(2);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// ── getFieldsPromise ──────────────────────────────────────────────────────
|
|
352
|
+
|
|
353
|
+
describe('getFieldsPromise()', () => {
|
|
354
|
+
it('resolves with the field definitions', async () => {
|
|
355
|
+
const m = makeManagment();
|
|
356
|
+
const promise = svc.getFieldsPromise(m);
|
|
357
|
+
|
|
358
|
+
const req = http.expectOne(r => r.url.includes('GetResource'));
|
|
359
|
+
expect(req.request.url).toContain('ENT.json');
|
|
360
|
+
req.flush([{ name: 'field1' }, { name: 'field2' }]);
|
|
361
|
+
|
|
362
|
+
const result = await promise;
|
|
363
|
+
expect(result).toHaveLength(2);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// ── getData (with pako decompression) ────────────────────────────────────
|
|
368
|
+
|
|
369
|
+
describe('getData()', () => {
|
|
370
|
+
function deflateBase64(str: string): string {
|
|
371
|
+
const pako = require('pako');
|
|
372
|
+
const compressed = pako.deflate(str) as Uint8Array;
|
|
373
|
+
return btoa(Array.from(compressed).map((b: number) => String.fromCharCode(b)).join(''));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
it('decompresses the pako-encoded dataFile in the response', (done) => {
|
|
377
|
+
const m = makeManagment();
|
|
378
|
+
const original = JSON.stringify({ entities: [{ name: 'test' }] });
|
|
379
|
+
|
|
380
|
+
svc.getData(m).subscribe(result => {
|
|
381
|
+
expect(result.dataFile).toBe(original);
|
|
382
|
+
done();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
const req = http.expectOne(r => r.url.includes('GetData') && r.method === 'GET');
|
|
386
|
+
expect(req.request.url).toContain('/read/APP/2024/ENT/prg=1/1');
|
|
387
|
+
req.flush({ dataFile: deflateBase64(original), svg: '', booleanResult: false });
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// ── getDataPromise ────────────────────────────────────────────────────────
|
|
392
|
+
|
|
393
|
+
describe('getDataPromise()', () => {
|
|
394
|
+
it('resolves with the raw transport data (no decompression)', async () => {
|
|
395
|
+
const m = makeManagment();
|
|
396
|
+
const promise = svc.getDataPromise(m);
|
|
397
|
+
|
|
398
|
+
const req = http.expectOne(r => r.url.includes('GetData'));
|
|
399
|
+
req.flush({ svg: 'svg-content', dataFile: 'raw-data', booleanResult: false });
|
|
400
|
+
|
|
401
|
+
const result = await promise;
|
|
402
|
+
expect(result.dataFile).toBe('raw-data');
|
|
403
|
+
expect(result.svg).toBe('svg-content');
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// ── putDataPromise ────────────────────────────────────────────────────────
|
|
408
|
+
|
|
409
|
+
describe('putDataPromise()', () => {
|
|
410
|
+
it('sends a PUT and resolves with the transport response', async () => {
|
|
411
|
+
const m = makeManagment();
|
|
412
|
+
const promise = svc.putDataPromise(m);
|
|
413
|
+
|
|
414
|
+
const req = http.expectOne(`${BASE_URL}`);
|
|
415
|
+
expect(req.request.method).toBe('PUT');
|
|
416
|
+
expect(JSON.parse(req.request.body)).toMatchObject({ appId: 'APP' });
|
|
417
|
+
req.flush({ svg: '', dataFile: '', booleanResult: true });
|
|
418
|
+
|
|
419
|
+
const result = await promise;
|
|
420
|
+
expect(result.booleanResult).toBe(true);
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|