Skip to content

Commit

Permalink
feat: remove cnfs duplication rule
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gavanier committed Jul 3, 2023
1 parent 1916241 commit 8d86328
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ const selectDuplication =
(lieuDuplication: SchemaLieuMediationNumerique, lieu: SchemaLieuMediationNumerique): Duplication =>
lieuDuplication.date_maj < tooOld.toISOString() ? { id: lieuDuplication.id } : { id: lieuDuplication.id, mergeId: lieu.id };

const cnfsDuplicationRule =
(tooOld: Date) =>
(lieu1: SchemaLieuMediationNumerique, lieu2: SchemaLieuMediationNumerique): Duplication => {
if (lieu1.source === 'conseiller-numerique') return selectDuplication(tooOld)(lieu2, lieu1);
if (lieu2.source === 'conseiller-numerique') return selectDuplication(tooOld)(lieu1, lieu2);
return {};
};

const dateDuplicationRule =
(tooOld: Date) =>
(lieu1: SchemaLieuMediationNumerique, lieu2: SchemaLieuMediationNumerique): Duplication =>
lieu1.date_maj < lieu2.date_maj ? selectDuplication(tooOld)(lieu1, lieu2) : selectDuplication(tooOld)(lieu2, lieu1);

const DUPLICATION_RULES: DuplicationRule[] = [cnfsDuplicationRule, dateDuplicationRule];
const DUPLICATION_RULES: DuplicationRule[] = [dateDuplicationRule];

export const applyDuplicationRules =
(tooOld: Date) =>
Expand Down
130 changes: 0 additions & 130 deletions src/dedupliquer/cli/action/remove-duplicates/remove-duplicates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,92 +93,6 @@ describe('remove duplicates', (): void => {
]);
});

it('should keep CnFS lieu 1 when there is two duplicate even if it is the oldest lieu', (): void => {
const lieux: SchemaLieuMediationNumerique[] = [
{
id: '1',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'DURTAL',
latitude: 47.671271,
longitude: -0.256457,
date_maj: '2019-08-01',
source: 'conseiller-numerique'
} as SchemaLieuMediationNumerique,
{
id: '2',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'Durtal',
latitude: 47.6699154795,
longitude: -0.2551539846,
date_maj: '2023-05-03',
source: 'hinaura'
} as SchemaLieuMediationNumerique
];

const lieuxWithoutDuplicates: SchemaLieuMediationNumerique[] = removeDuplicates(new Date('2023-05-30'))(lieux);

expect(lieuxWithoutDuplicates).toStrictEqual([
{
id: '1',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'DURTAL',
latitude: 47.671271,
longitude: -0.256457,
date_maj: '2019-08-01',
source: 'conseiller-numerique'
} as SchemaLieuMediationNumerique
]);
});

it('should keep CnFS lieu 2 when there is two duplicate even if it is the oldest lieu', (): void => {
const lieux: SchemaLieuMediationNumerique[] = [
{
id: '1',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'Durtal',
latitude: 47.6699154795,
longitude: -0.2551539846,
date_maj: '2023-05-03',
source: 'hinaura'
} as SchemaLieuMediationNumerique,
{
id: '2',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'DURTAL',
latitude: 47.671271,
longitude: -0.256457,
date_maj: '2019-08-01',
source: 'conseiller-numerique'
} as SchemaLieuMediationNumerique
];

const lieuxWithoutDuplicates: SchemaLieuMediationNumerique[] = removeDuplicates(new Date('2023-05-30'))(lieux);

expect(lieuxWithoutDuplicates).toStrictEqual([
{
id: '2',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'DURTAL',
latitude: 47.671271,
longitude: -0.256457,
date_maj: '2019-08-01',
source: 'conseiller-numerique'
} as SchemaLieuMediationNumerique
]);
});

it('should merge extra field from lieu 2 duplicate', (): void => {
const lieux: SchemaLieuMediationNumerique[] = [
{
Expand Down Expand Up @@ -313,50 +227,6 @@ describe('remove duplicates', (): void => {
]);
});

it('should merge extra field from lieu 1 duplicate which source that is not conseiller numerique', (): void => {
const lieux: SchemaLieuMediationNumerique[] = [
{
id: '1',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'Durtal',
latitude: 47.6699154795,
longitude: -0.2551539846,
date_maj: '2023-05-03',
courriel: 'commune-de-durtal@france-services.fr'
} as SchemaLieuMediationNumerique,
{
id: '2',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'DURTAL',
latitude: 47.671271,
longitude: -0.256457,
date_maj: '2023-01-16',
source: 'conseiller-numerique'
} as SchemaLieuMediationNumerique
];

const lieuxWithoutDuplicates: SchemaLieuMediationNumerique[] = removeDuplicates(new Date('2023-05-30'))(lieux);

expect(lieuxWithoutDuplicates).toStrictEqual([
{
id: '2',
nom: 'France Services Durtal',
adresse: '11 rue Joseph Cugnot',
code_postal: '49430',
commune: 'DURTAL',
latitude: 47.671271,
longitude: -0.256457,
date_maj: '2023-01-16',
source: 'conseiller-numerique',
courriel: 'commune-de-durtal@france-services.fr'
} as SchemaLieuMediationNumerique
]);
});

it('should not merge extra field from lieu 2 duplicate when duplicate is too old', (): void => {
const lieux: SchemaLieuMediationNumerique[] = [
{
Expand Down

0 comments on commit 8d86328

Please sign in to comment.