-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(contributions): add slug for all idcc (even when starting with 0) (…
- Loading branch information
1 parent
8a85d98
commit 1bb8628
Showing
3 changed files
with
114 additions
and
46 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
125 changes: 91 additions & 34 deletions
125
shared/elasticsearch-document-adapter/src/__tests__/cdtnDocuments.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,99 @@ | ||
import { getDuplicateSlugs } from "../cdtnDocuments"; | ||
import { | ||
getDuplicateSlugs, | ||
updateContributionsAndGetIDCCs, | ||
} from "../cdtnDocuments"; | ||
import { context } from "../context"; | ||
|
||
jest.mock("@socialgouv/cdtn-logger"); | ||
|
||
describe("getDuplicateSlug", () => { | ||
test("should return an empty array if there is no duplicate slug", async () => { | ||
context.provide(); | ||
const documents = [ | ||
[ | ||
{ slug: "slug-1", source: "cdt" }, | ||
{ slug: "slug-2", source: "cdt" }, | ||
], | ||
[ | ||
{ slug: "slug-1", source: "contribution" }, | ||
{ slug: "slug-2", source: "contribution" }, | ||
], | ||
]; | ||
const duplicateSlugs = await getDuplicateSlugs(documents); | ||
expect(Object.entries(duplicateSlugs).length).toBe(0); | ||
describe("cdtnDocuments", () => { | ||
describe("getDuplicateSlug", () => { | ||
test("should return an empty array if there is no duplicate slug", async () => { | ||
context.provide(); | ||
const documents = [ | ||
[ | ||
{ slug: "slug-1", source: "cdt" }, | ||
{ slug: "slug-2", source: "cdt" }, | ||
], | ||
[ | ||
{ slug: "slug-1", source: "contribution" }, | ||
{ slug: "slug-2", source: "contribution" }, | ||
], | ||
]; | ||
const duplicateSlugs = await getDuplicateSlugs(documents); | ||
expect(Object.entries(duplicateSlugs).length).toBe(0); | ||
}); | ||
|
||
test("should return an array of duplicated slug", async () => { | ||
context.provide(); | ||
const documents = [ | ||
[ | ||
{ slug: "slug-1", source: "cdt" }, | ||
{ slug: "slug-2", source: "cdt" }, | ||
], | ||
[ | ||
{ slug: "slug-1", source: "faq" }, | ||
{ slug: "slug-1", source: "faq" }, | ||
], | ||
[ | ||
{ slug: "slug-4", source: "fiche" }, | ||
{ slug: "slug-3", source: "fiche" }, | ||
], | ||
]; | ||
const duplicateSlugs = await getDuplicateSlugs(documents); | ||
expect(Object.entries(duplicateSlugs).length).toBe(1); | ||
}); | ||
}); | ||
|
||
test("should return an array of duplicated slug", async () => { | ||
context.provide(); | ||
const documents = [ | ||
[ | ||
{ slug: "slug-1", source: "cdt" }, | ||
{ slug: "slug-2", source: "cdt" }, | ||
], | ||
[ | ||
{ slug: "slug-1", source: "faq" }, | ||
{ slug: "slug-1", source: "faq" }, | ||
], | ||
[ | ||
{ slug: "slug-4", source: "fiche" }, | ||
{ slug: "slug-3", source: "fiche" }, | ||
], | ||
]; | ||
const duplicateSlugs = await getDuplicateSlugs(documents); | ||
expect(Object.entries(duplicateSlugs).length).toBe(1); | ||
describe("updateContributionsAndGetIDCCs", () => { | ||
test("should return a list of iddc", async () => { | ||
const ccnData = [ | ||
{ | ||
num: 829, | ||
slug: "829-convention-collective-departementale-des-industries-metallurgiques-et-des-in", | ||
}, | ||
{ | ||
num: 292, | ||
slug: "292-plasturgie", | ||
}, | ||
{ | ||
num: 1557, | ||
slug: "1557-commerce-des-articles-de-sport-et-equipements-de-loisirs", | ||
}, | ||
{ | ||
num: 1909, | ||
slug: "1909-organismes-de-tourisme", | ||
}, | ||
]; | ||
|
||
const contributions: { | ||
answers: { | ||
conventionAnswer: { idcc: string; slug?: string }; | ||
}; | ||
}[] = [ | ||
{ answers: { conventionAnswer: { idcc: "0292" } } }, | ||
{ answers: { conventionAnswer: { idcc: "0829" } } }, | ||
{ answers: { conventionAnswer: { idcc: "1557" } } }, | ||
{ answers: { conventionAnswer: { idcc: "1909" } } }, | ||
]; | ||
const idccs = await updateContributionsAndGetIDCCs( | ||
contributions, | ||
// @ts-ignore | ||
ccnData | ||
); | ||
expect(Array.from(idccs)).toEqual([292, 829, 1557, 1909]); | ||
expect(contributions[0].answers.conventionAnswer.slug).toBe( | ||
"292-plasturgie" | ||
); | ||
expect(contributions[1].answers.conventionAnswer.slug).toBe( | ||
"829-convention-collective-departementale-des-industries-metallurgiques-et-des-in" | ||
); | ||
expect(contributions[2].answers.conventionAnswer.slug).toBe( | ||
"1557-commerce-des-articles-de-sport-et-equipements-de-loisirs" | ||
); | ||
expect(contributions[3].answers.conventionAnswer.slug).toBe( | ||
"1909-organismes-de-tourisme" | ||
); | ||
}); | ||
}); | ||
}); |
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