@arsedizioni/ars-utils 22.0.30 → 22.0.32
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.
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Clipper common — Vitest test suite
|
|
2
|
+
|
|
3
|
+
Effective unit-test suite for the `clipper.common` library: the 6 feature services,
|
|
4
|
+
the shared `ClipperCoreService`, the `ClipperService` facade and `ClipperAuthInterceptor`.
|
|
5
|
+
|
|
6
|
+
## What is covered
|
|
7
|
+
|
|
8
|
+
| Spec | Focus |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| `core.service.spec.ts` | state mutators (`ensureLoginInfo`, `setLoggedIn`, `setTeams`, `updateContext`, `initializeChannels`, `reset`, `clear`), lazy `loginInfo` load, `initialize` (serviceUri/appUri/flags, client-id / embedded, F5 branch), broadcast handlers (`LOGIN_CHANGED`, `LOGOUT` logged-in/out), `ping` |
|
|
11
|
+
| `login.service.spec.ts` | credential + OAuth login, MFA pending, failure, temporary context, `autoLogin`/`autoLogout`, `confirmIdentity`, `logout` (clears session on success **and** error), `newOTP` |
|
|
12
|
+
| `documents.service.spec.ts` | every endpoint, `references`/`referencesFacets` mode routing + `null`, default taxonomy body, dashboard counters, bag parsing (`loadBag`/`addToBag`/`removeFromBag`/`clearBag`) |
|
|
13
|
+
| `account.service.spec.ts` | password/settings, `updateSettings`→`setChannels`, `updateChannelsState`→`setChannelsState`, the moved channel helpers, `updateTrialInfo` guards + both result branches, links |
|
|
14
|
+
| `archive.service.spec.ts` | folders/files endpoints, `exportArchiveFolders` URL building, multipart `importArchiveFolders`/`saveArchiveFile` form data, blob download |
|
|
15
|
+
| `calendar.service.spec.ts` | all deadline endpoints + team storage + ICS export |
|
|
16
|
+
| `collaboration.service.spec.ts` | teams (incl. `adminsOnly` team-storage rule), contacts, notes |
|
|
17
|
+
| `clipper.service.spec.ts` | facade exposes/forwards feature services, re-exports core signals by identity, delegates `initialize`/`ping` |
|
|
18
|
+
| `auth.interceptor.spec.ts` | header decoration, passthrough of non-Clipper URLs, error mapping (0/403/405/410/5xx), `NotifySystemErrors` flag, 5s debounce |
|
|
19
|
+
|
|
20
|
+
## File placement
|
|
21
|
+
|
|
22
|
+
Drop the files into the library mirroring its structure (import paths assume this):
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
common/
|
|
26
|
+
services/ ← *.service.spec.ts + clipper.service.spec.ts
|
|
27
|
+
interceptors/ auth.interceptor.spec.ts
|
|
28
|
+
testing/ ← clipper-test-helpers.ts (shared TestBed harness + fakes)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`vitest.config.ts` goes at the package root and `src/test-setup.ts` wherever your
|
|
32
|
+
setup lives — adjust `setupFiles` accordingly. If you already have a Vitest config,
|
|
33
|
+
just merge the `test` block.
|
|
34
|
+
|
|
35
|
+
## Running
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm i -D vitest @analogjs/vite-plugin-angular @analogjs/vitest-angular jsdom
|
|
39
|
+
npx vitest run # single run
|
|
40
|
+
npx vitest # watch
|
|
41
|
+
npx vitest run --coverage # coverage
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`@angular/*` and `@arsedizioni/ars-utils/*` are the library's own dependencies and
|
|
45
|
+
are used as-is (no mocking). Only `BroadcastService` and `SplashService` are replaced
|
|
46
|
+
by controllable test doubles via TestBed providers.
|
|
47
|
+
|
|
48
|
+
## How it works
|
|
49
|
+
|
|
50
|
+
`createHarness()` (in `testing/clipper-test-helpers.ts`) wires a `TestBed` with the
|
|
51
|
+
HTTP testing backend (`HttpTestingController`), all services and the fakes, resets
|
|
52
|
+
storage, and (unless `skipInitialize`) calls `core.initialize()`. It returns every
|
|
53
|
+
service plus the fakes, so a spec reads like:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const h = createHarness();
|
|
57
|
+
h.documents.query({ text: 'iva' }).subscribe();
|
|
58
|
+
h.http.expectOne(`${h.serviceUri}/documents`).flush(ok({ items: [] }));
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`FakeBroadcastService.emit(id, data)` pushes inbound bus messages (for the core
|
|
62
|
+
broadcast handler), while `sendMessage` is a spy recording outbound broadcasts —
|
|
63
|
+
the two are decoupled to avoid feedback loops.
|
|
64
|
+
|
|
65
|
+
## Assumptions / notes
|
|
66
|
+
|
|
67
|
+
- `@Service()` is treated as `@Injectable()`-compatible (it is provided through TestBed).
|
|
68
|
+
- The suite was authored against the library sources but **not executed here**, because
|
|
69
|
+
the private `@arsedizioni` packages and the Angular toolchain aren't installed in the
|
|
70
|
+
authoring environment. Run `vitest` in the repo; if `@Service`/zoneless setup needs a
|
|
71
|
+
tweak, it will be in `src/test-setup.ts` only.
|
|
72
|
+
- `initializeChannels`/`updateChannels` mutate the shared `ClipperChannels` constant
|
|
73
|
+
objects (existing library behaviour) — assertions check the produced channel, not
|
|
74
|
+
object identity, to stay robust.
|
|
@@ -56,8 +56,6 @@ class DateFnsAdapter extends DateAdapter {
|
|
|
56
56
|
constructor() {
|
|
57
57
|
super();
|
|
58
58
|
const matDateLocale = inject(MAT_DATE_LOCALE, { optional: true });
|
|
59
|
-
// MAT_DATE_LOCALE defaults to LOCALE_ID (a string): only a date-fns
|
|
60
|
-
// Locale OBJECT is usable here, a string would break format()/parse().
|
|
61
59
|
if (matDateLocale && typeof matDateLocale === 'object') {
|
|
62
60
|
this.setLocale(matDateLocale);
|
|
63
61
|
}
|
|
@@ -170,22 +168,20 @@ class DateFnsAdapter extends DateAdapter {
|
|
|
170
168
|
if (date < 1) {
|
|
171
169
|
throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
|
|
172
170
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
result
|
|
177
|
-
result.
|
|
178
|
-
const result2 = new TZDate(result, 'Europe/Rome');
|
|
179
|
-
if (result2.getMonth() !== month) {
|
|
171
|
+
if (month < 0 || month > 11) {
|
|
172
|
+
throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
|
|
173
|
+
}
|
|
174
|
+
const result = new TZDate(year, month, date, 0, 0, 0, 0, 'Europe/Rome');
|
|
175
|
+
if (result.getMonth() !== month) {
|
|
180
176
|
throw Error(`Invalid date "${date}" for month with index "${month}".`);
|
|
181
177
|
}
|
|
182
|
-
return
|
|
178
|
+
return result;
|
|
183
179
|
}
|
|
184
180
|
/**
|
|
185
181
|
* Returns today's date in the local timezone.
|
|
186
182
|
*/
|
|
187
183
|
today() {
|
|
188
|
-
return new Date();
|
|
184
|
+
return new TZDate(new Date(), 'Europe/Rome');
|
|
189
185
|
}
|
|
190
186
|
/**
|
|
191
187
|
* Parses a value into a `Date`.
|
|
@@ -324,8 +320,7 @@ function provideArsDateFns() {
|
|
|
324
320
|
return makeEnvironmentProviders([
|
|
325
321
|
{
|
|
326
322
|
provide: DateAdapter,
|
|
327
|
-
useClass: DateFnsAdapter
|
|
328
|
-
deps: [MAT_DATE_LOCALE],
|
|
323
|
+
useClass: DateFnsAdapter
|
|
329
324
|
},
|
|
330
325
|
{ provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS }
|
|
331
326
|
]);
|