Skip to content

Commit ac21991

Browse files
committed
Added tests for config migration
1 parent 7784686 commit ac21991

3 files changed

Lines changed: 36 additions & 23 deletions

File tree

src/core/utils/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @see https://stackoverflow.com/a/51365037/2391359
2+
export type RecursivePartial<T> = {
3+
[P in keyof T]?: T[P] extends (infer U)[]
4+
? RecursivePartial<U>[]
5+
: T[P] extends object | undefined
6+
? RecursivePartial<T[P]>
7+
: T[P];
8+
};

src/migrations/v2/types.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {RecursivePartial} from '../../core/utils/types';
2+
13
export interface V2Translations {
24
consentModal: {
35
title: string;
@@ -8,7 +10,7 @@ export interface V2Translations {
810
};
911
};
1012
consentNotice: {
11-
title?: string;
13+
title: string;
1214
description: string;
1315
changeDescription: string;
1416
learnMore: string;
@@ -47,40 +49,42 @@ export interface V2Consents {
4749
export interface V2App {
4850
name: string;
4951
title: string;
50-
description: string;
51-
cookies: string[];
52+
description?: string;
53+
cookies: Array<
54+
string | RegExp | [name: string, path: string, domain: string]
55+
>;
5256
purposes: string[];
53-
callback: (consent: boolean, app: V2App) => void;
54-
required: boolean;
55-
optOut: boolean;
56-
default: boolean;
57-
onlyOnce: boolean;
57+
callback?: (consent: boolean, app: V2App) => void;
58+
required?: boolean;
59+
optOut?: boolean;
60+
default?: boolean;
61+
onlyOnce?: boolean;
5862
}
5963

6064
export interface V2Category {
6165
name: string;
6266
title: string;
63-
description: string;
67+
description?: string;
6468
apps: string[];
6569
}
6670

6771
export interface V2Config {
6872
elementID: string;
6973
appElement: string;
70-
stylePrefix: string;
71-
cookieName: string;
72-
cookieExpiresAfterDays: 365;
73-
cookieDomain: undefined;
74-
stringifyCookie: (consents: V2Consents) => string;
75-
parseCookie: (consents: string) => V2Consents;
74+
stylePrefix?: string;
75+
cookieName?: string;
76+
cookieExpiresAfterDays?: number;
77+
cookieDomain?: string;
78+
stringifyCookie?: (consents: V2Consents) => string;
79+
parseCookie?: (consents: string) => V2Consents;
7680
privacyPolicy: string;
77-
default: boolean;
78-
mustConsent: boolean;
79-
mustNotice: boolean;
80-
logo: boolean;
81+
default?: boolean;
82+
mustConsent?: boolean;
83+
mustNotice?: boolean;
84+
logo?: boolean;
8185
lang: string;
82-
translations: Record<string, V2Translations>;
86+
translations?: Record<string, RecursivePartial<V2Translations>>;
8387
apps: V2App[];
84-
categories: V2Category[];
85-
debug: boolean;
88+
categories?: V2Category[];
89+
debug?: boolean;
8690
}

src/migrations/v3/translations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import cleanDeep from 'clean-deep';
22
import type {Translations} from '../../ui/types';
33
import type {V2Translations} from '../v2/types';
4+
import {RecursivePartial} from '../../core/utils/types';
45

56
const join = (strings: string[], separator = ' ') =>
67
strings.filter((string) => !!string).join(separator);
78

89
export const migrateTranslations = (
9-
translations: Partial<V2Translations>
10+
translations: RecursivePartial<V2Translations>
1011
): Translations =>
1112
cleanDeep({
1213
banner: {

0 commit comments

Comments
 (0)