Skip to content

Commit bb0edd5

Browse files
committed
chore: rename-policy-to-validation
1 parent 9c448bd commit bb0edd5

7 files changed

Lines changed: 21 additions & 22 deletions

File tree

e2e/davinci-app/components/password.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ export default function passwordComponent(
3636
formEl?.appendChild(input);
3737

3838
if (collector.type === 'ValidatedPasswordCollector') {
39-
const passwordPolicy = collector.output.passwordPolicy;
39+
const validation = collector.input.validation;
4040
const requirementsList = document.createElement('ul');
4141
requirementsList.className = 'password-requirements';
4242

43-
if (passwordPolicy.length) {
44-
const { min, max } = passwordPolicy.length;
43+
if (validation.length) {
44+
const { min, max } = validation.length;
4545
let lengthMessage: string | null = null;
4646
if (min != null && max != null) {
4747
lengthMessage = `${min}${max} characters`;
@@ -57,8 +57,8 @@ export default function passwordComponent(
5757
}
5858
}
5959

60-
if (passwordPolicy.minCharacters) {
61-
for (const [charset, count] of Object.entries(passwordPolicy.minCharacters)) {
60+
if (validation.minCharacters) {
61+
for (const [charset, count] of Object.entries(validation.minCharacters)) {
6262
const li = document.createElement('li');
6363
if (UPPERCASE_RE.test(charset)) {
6464
li.textContent = `At least ${count} uppercase letter(s)`;

packages/davinci-client/src/lib/collector.types.test-d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ describe('Collector Types', () => {
7474
expectTypeOf<ValidatedPasswordCollector['output']>()
7575
.toHaveProperty('verify')
7676
.toEqualTypeOf<boolean>();
77-
expectTypeOf<ValidatedPasswordCollector['output']>()
78-
.toHaveProperty('passwordPolicy')
77+
expectTypeOf<ValidatedPasswordCollector['input']>()
78+
.toHaveProperty('validation')
7979
.toEqualTypeOf<PasswordPolicy>();
8080
});
8181

82-
it('should validate PasswordCollector output does NOT have passwordPolicy', () => {
83-
expectTypeOf<PasswordCollector['output']>().not.toHaveProperty('passwordPolicy');
82+
it('should validate PasswordCollector input does NOT have validation', () => {
83+
expectTypeOf<PasswordCollector['input']>().not.toHaveProperty('validation');
8484
});
8585

8686
it('should validate SingleCollector structure', () => {
@@ -310,13 +310,13 @@ describe('Collector Types', () => {
310310
key: '',
311311
value: '',
312312
type: '',
313+
validation: {},
313314
},
314315
output: {
315316
key: '',
316317
label: '',
317318
type: '',
318319
verify: false,
319-
passwordPolicy: {},
320320
},
321321
};
322322

packages/davinci-client/src/lib/collector.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ export interface ValidatedPasswordCollector {
217217
key: string;
218218
value: string | number | boolean;
219219
type: string;
220+
validation: PasswordPolicy;
220221
};
221222
output: {
222223
key: string;
223224
label: string;
224225
type: string;
225226
verify: boolean;
226-
passwordPolicy: PasswordPolicy;
227227
};
228228
}
229229
export type TextCollector = SingleValueCollectorWithValue<'TextCollector'>;

packages/davinci-client/src/lib/collector.utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,13 +1346,13 @@ describe('returnValidatedPasswordCollector', () => {
13461346
key: 'user.password',
13471347
value: '',
13481348
type: 'PASSWORD_VERIFY',
1349+
validation: mockPasswordPolicy,
13491350
},
13501351
output: {
13511352
key: 'user.password',
13521353
label: 'Password',
13531354
type: 'PASSWORD_VERIFY',
13541355
verify: false,
1355-
passwordPolicy: mockPasswordPolicy,
13561356
},
13571357
});
13581358
});
@@ -1384,7 +1384,7 @@ describe('returnValidatedPasswordCollector', () => {
13841384

13851385
const result = returnValidatedPasswordCollector(field, 1);
13861386

1387-
expect(result.output.passwordPolicy).toEqual({});
1387+
expect(result.input.validation).toEqual({});
13881388
expect(result.output.verify).toBe(false);
13891389
});
13901390

packages/davinci-client/src/lib/collector.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function returnSingleValueCollector<
192192
// Reducer routes by `field.type === 'PASSWORD_VERIFY'`, so a policy may or may not be
193193
// present. Fallback to an empty object keeps the factory total; the policy validator
194194
// treats an empty policy as no rules.
195-
const passwordPolicy =
195+
const validation =
196196
'passwordPolicy' in field && field.passwordPolicy ? field.passwordPolicy : {};
197197
const verify = 'verify' in field ? field.verify === true : false;
198198
return {
@@ -205,13 +205,13 @@ export function returnSingleValueCollector<
205205
key: field.key,
206206
value: '',
207207
type: field.type,
208+
validation,
208209
},
209210
output: {
210211
key: field.key,
211212
label: field.label,
212213
type: field.type,
213214
verify,
214-
passwordPolicy,
215215
},
216216
} as InferSingleValueCollectorType<CollectorType>;
217217
} else if (collectorType === 'SingleSelectCollector') {

packages/davinci-client/src/lib/node.reducer.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,13 +1476,13 @@ describe('PASSWORD_VERIFY with password policy', () => {
14761476
key: 'user.password',
14771477
value: '',
14781478
type: 'PASSWORD_VERIFY',
1479+
validation: mockPasswordPolicy,
14791480
},
14801481
output: {
14811482
key: 'user.password',
14821483
label: 'Password',
14831484
type: 'PASSWORD_VERIFY',
14841485
verify: false,
1485-
passwordPolicy: mockPasswordPolicy,
14861486
},
14871487
} satisfies ValidatedPasswordCollector,
14881488
]);
@@ -1504,7 +1504,7 @@ describe('PASSWORD_VERIFY with password policy', () => {
15041504
};
15051505
const result = nodeCollectorReducer(undefined, action);
15061506
expect(result[0].type).toBe('ValidatedPasswordCollector');
1507-
expect((result[0] as ValidatedPasswordCollector).output.passwordPolicy).toEqual({});
1507+
expect((result[0] as ValidatedPasswordCollector).input.validation).toEqual({});
15081508
});
15091509

15101510
it('should produce ValidatedPasswordCollector when a PASSWORD field has a policy', () => {
@@ -1524,9 +1524,7 @@ describe('PASSWORD_VERIFY with password policy', () => {
15241524
};
15251525
const result = nodeCollectorReducer(undefined, action);
15261526
expect(result[0].type).toBe('ValidatedPasswordCollector');
1527-
expect((result[0] as ValidatedPasswordCollector).output.passwordPolicy).toEqual(
1528-
mockPasswordPolicy,
1529-
);
1527+
expect((result[0] as ValidatedPasswordCollector).input.validation).toEqual(mockPasswordPolicy);
15301528
});
15311529

15321530
it('should propagate verify: true from the field onto PasswordCollector', () => {
@@ -1604,7 +1602,8 @@ describe('PASSWORD_VERIFY with password policy', () => {
16041602
};
16051603
const result = nodeCollectorReducer(undefined, action);
16061604
expect(result[0].type).toBe('PasswordCollector');
1607-
expect(result[0].output).not.toHaveProperty('passwordPolicy');
1605+
expect((result[0] as PasswordCollector).output).not.toHaveProperty('passwordPolicy');
1606+
expect((result[0] as PasswordCollector).input).not.toHaveProperty('validation');
16081607
});
16091608
});
16101609

packages/davinci-client/src/lib/password-policy.rules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const passwordPolicyRules: readonly PasswordPolicyRule[] = [
8989
export function returnPasswordPolicyValidator(
9090
collector: ValidatedPasswordCollector,
9191
): (value: string) => string[] {
92-
const policy = collector.output.passwordPolicy;
92+
const policy = collector.input.validation;
9393
return (value: string) =>
9494
policy
9595
? pipe(

0 commit comments

Comments
 (0)