CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/database/postgres/pii.test.ts
Views: 687
1
// basically check, that all valid fields for PII values work and give a suitable date in the future
2
3
import {
4
EXTRAS,
5
pii_retention_parse,
6
} from "@cocalc/util/db-schema/site-settings-extras";
7
8
import { pii_retention_to_future } from "@cocalc/database/postgres/pii";
9
10
function getValid(): string[] {
11
const vals = EXTRAS.pii_retention.valid;
12
13
// make TS happy
14
if (vals == null) return [];
15
16
return vals as string[];
17
}
18
19
test.each(getValid())("pii(%s)", async (pii: string) => {
20
const pii_val = pii_retention_parse(pii);
21
const v = await pii_retention_to_future(pii_val);
22
if (pii === "never") {
23
expect(v).toBeUndefined();
24
} else {
25
expect(v).toBeInstanceOf(Date);
26
const now = new Date();
27
const diff = v!.getTime() - now.getTime();
28
expect(diff).toBeGreaterThan(1000 * 60 * 60 * 24);
29
}
30
});
31
32