-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow multi email in contact field
- Loading branch information
Showing
18 changed files
with
70 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention, camelcase */ | ||
|
||
import { Courriel } from '../courriel'; | ||
import { Url } from '../url'; | ||
import { Contact, ContactToValidate } from './contact'; | ||
import { CourrielError, TelephoneError } from './errors'; | ||
import { TelephoneError } from './errors'; | ||
|
||
describe('contact model', (): void => { | ||
it('should create a valid contact', (): void => { | ||
const contactData: ContactToValidate = { | ||
telephone: '+33145896378', | ||
courriel: '[email protected]', | ||
courriel: [Courriel('[email protected]')], | ||
site_web: [Url('http://www.cartographienationale.fr')] | ||
}; | ||
|
||
|
@@ -29,7 +30,7 @@ describe('contact model', (): void => { | |
|
||
it('should create a valid contact with only courriel property', (): void => { | ||
const contactData: ContactToValidate = { | ||
courriel: '[email protected]' | ||
courriel: [Courriel('[email protected]')] | ||
}; | ||
|
||
const contact: Contact = Contact(contactData); | ||
|
@@ -40,7 +41,7 @@ describe('contact model', (): void => { | |
it('should create a valid contact with a phone from French Guiana', (): void => { | ||
const contactData: ContactToValidate = { | ||
telephone: '+594694020905', | ||
courriel: '[email protected]', | ||
courriel: [Courriel('[email protected]')], | ||
site_web: [Url('https://www.facebook.com/YenkumuLutuPapaichton/')] | ||
}; | ||
|
||
|
@@ -49,16 +50,6 @@ describe('contact model', (): void => { | |
expect(contact).toStrictEqual({ ...contactData } as Contact); | ||
}); | ||
|
||
it('should throw CourrielError when courriel is invalid', (): void => { | ||
const contactData: ContactToValidate = { | ||
courriel: 'error' | ||
}; | ||
|
||
expect((): void => { | ||
Contact(contactData); | ||
}).toThrow(new CourrielError('error')); | ||
}); | ||
|
||
it('should throw TelephoneError when telephone is invalid', (): void => { | ||
const contactData: ContactToValidate = { | ||
telephone: 'error' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './courriel.error'; | ||
export * from './telephone.error'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Courriel } from './courriel'; | ||
import { CourrielError } from './errors'; | ||
|
||
describe('courriel model', (): void => { | ||
it('should create a valid courriel', (): void => { | ||
const courrielData: string = '[email protected]'; | ||
|
||
const courriel: Courriel = Courriel(courrielData); | ||
|
||
expect(courriel).toStrictEqual(courrielData as Courriel); | ||
}); | ||
|
||
it('should throw CourrielError when email do not have at symbole or domain extension', (): void => { | ||
const courrielData: string = 'test@gmail'; | ||
|
||
expect((): void => { | ||
Courriel(courrielData); | ||
}).toThrow(new CourrielError(courrielData)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Model } from '../model'; | ||
import { CourrielError } from './errors'; | ||
|
||
export type Courriel = Model<'Courriel', string>; | ||
|
||
const COURRIEL_REG_EXP: RegExp = | ||
/^(?:[a-zA-Z0-9_][a-zA-Z0-9.!#$%&'*+\\=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])+(?:;|$))+$/u; | ||
|
||
const throwCourrielError = (courriel: string): Courriel => { | ||
throw new CourrielError(courriel); | ||
}; | ||
|
||
export const isValidCourriel = (courriel: string): courriel is Courriel => COURRIEL_REG_EXP.test(courriel); | ||
|
||
/* eslint-disable-next-line @typescript-eslint/naming-convention */ | ||
export const Courriel = (courriel: string): Courriel => (isValidCourriel(courriel) ? courriel : throwCourrielError(courriel)); |
3 changes: 1 addition & 2 deletions
3
src/models/contact/errors/courriel.error.ts → src/models/courriel/errors/courriel.error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './courriel.error' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './errors'; | ||
export * from './courriel'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
ConditionAcces, | ||
ConditionsAcces, | ||
Contact, | ||
Courriel, | ||
Id, | ||
LabelNational, | ||
LabelsNationaux, | ||
|
@@ -170,7 +171,7 @@ describe('from schema data inclusion', (): void => { | |
typologies: Typologies([Typologie.TIERS_LIEUX]), | ||
contact: Contact({ | ||
telephone: '+33180059880', | ||
courriel: '[email protected]', | ||
courriel: [Courriel('[email protected]')], | ||
site_web: [Url('https://www.laquincaillerie.tl/'), Url('https://m.facebook.com/laquincaillerienumerique/')] | ||
}), | ||
horaires: 'Mo-Fr 09:00-12:00,14:00-18:30; Sa 08:30-12:00', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
ConditionAcces, | ||
ConditionsAcces, | ||
Contact, | ||
Courriel, | ||
Id, | ||
LabelNational, | ||
LabelsNationaux, | ||
|
@@ -100,7 +101,7 @@ describe('to schema data.inclusion', (): void => { | |
contact: Contact({ | ||
site_web: [Url('https://www.asso-gonzalez.net/'), Url('https://www.facebook.com/asso-gonzalez.net/')], | ||
telephone: '0102030405', | ||
courriel: '[email protected]' | ||
courriel: [Courriel('[email protected]')] | ||
}), | ||
horaires: 'Mo-Fr 10:00-20:00 "sur rendez-vous"; PH off', | ||
presentation: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
ConditionAcces, | ||
ConditionsAcces, | ||
Contact, | ||
Courriel, | ||
Id, | ||
LabelNational, | ||
LabelsNationaux, | ||
|
@@ -140,7 +141,7 @@ describe('from schema lieux de mediation numerique', (): void => { | |
typologies: Typologies([Typologie.TIERS_LIEUX]), | ||
contact: Contact({ | ||
telephone: '+33180059880', | ||
courriel: '[email protected]', | ||
courriel: [Courriel('[email protected]')], | ||
site_web: [Url('https://www.laquincaillerie.tl/'), Url('https://m.facebook.com/laquincaillerienumerique/')] | ||
}), | ||
horaires: 'Mo-Fr 09:00-12:00,14:00-18:30; Sa 08:30-12:00', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
ConditionAcces, | ||
ConditionsAcces, | ||
Contact, | ||
Courriel, | ||
Id, | ||
LabelNational, | ||
LabelsNationaux, | ||
|
@@ -97,7 +98,7 @@ describe('to schema lieux de mediation numerique', (): void => { | |
typologies: Typologies([Typologie.TIERS_LIEUX]), | ||
contact: Contact({ | ||
telephone: '+33180059880', | ||
courriel: '[email protected]', | ||
courriel: [Courriel('[email protected]')], | ||
site_web: [Url('https://www.laquincaillerie.tl/'), Url('https://m.facebook.com/laquincaillerienumerique/')] | ||
}), | ||
horaires: 'Mo-Fr 09:00-12:00,14:00-18:30; Sa 08:30-12:00', | ||
|