Skip to content

Commit

Permalink
Merge pull request #59 from AtB-AS/jorelosorio/add_contact_phone_number
Browse files Browse the repository at this point in the history
feat: Add contact phone number
  • Loading branch information
jorelosorio authored Oct 23, 2024
2 parents 06b65fa + 989e6e9 commit 560513e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions schema-definitions/other.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"enableTokenToggleRestrictions": {
"type": "boolean"
},
"contactPhoneNumber": {
"type": "string",
"pattern": "^\\+\\d{1,3}\\d{1,14}$"
},
"enableNynorsk": {
"type": "boolean"
},
Expand Down
1 change: 1 addition & 0 deletions src/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const LoginMethod = z.enum(['otp', 'email', 'vipps']);
export const Other = z.object({
vatPercent: z.number(),
enableTokenToggleRestrictions: z.boolean().optional(),
contactPhoneNumber: z.string().regex(/^\+\d{1,3}\d{1,14}$/).optional(),
enableNynorsk: z.boolean().optional(),
tokenToggleMaxLimit: z.number().optional(),
travelcardNumberLength: z.number().default(16),
Expand Down
32 changes: 32 additions & 0 deletions src/tests/Others.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {assertType, expect, test} from 'vitest';

import {Other} from '../other';

test('Phone number', () => {
expect(
() =>
Other.parse({
contactPhoneNumber: 'foo',
vatPercent: 0,
}),
'Phone number must be valid',
).toThrowError();

expect(
() =>
Other.parse({
vatPercent: 1,
contactPhoneNumber: '+12345678901234567890',
}),
'Phone must be at most 17 digits',
).toThrowError();

expect(
() =>
Other.parse({
vatPercent: 1,
contactPhoneNumber: '+4712345678',
}),
'Phone must be at least +(3 digits)',
).not.toThrowError();
});

0 comments on commit 560513e

Please sign in to comment.