From 30e4c88574ac0cbf9a20dc281d1391656646c3c8 Mon Sep 17 00:00:00 2001 From: julie BRUNETTO Date: Fri, 29 Sep 2023 17:46:47 +0200 Subject: [PATCH] feat(stages): ajout des tests --- .../domain/model/hellowork/index.ts | 1 - .../hellowork/convertir.domain-service.ts | 8 +- ...transformer-flux-hellowork.usecase.test.ts | 621 +++--------------- ...ffre-de-stage-hellowork.fixture-builder.ts | 24 + 4 files changed, 135 insertions(+), 519 deletions(-) create mode 100644 apps/stages/test/transformation/fixture/offre-de-stage-hellowork.fixture-builder.ts diff --git a/apps/stages/src/transformation/domain/model/hellowork/index.ts b/apps/stages/src/transformation/domain/model/hellowork/index.ts index 6370ace3..d4f47525 100644 --- a/apps/stages/src/transformation/domain/model/hellowork/index.ts +++ b/apps/stages/src/transformation/domain/model/hellowork/index.ts @@ -29,7 +29,6 @@ export namespace Hellowork { function?: string seodomain?: _Domaine category?: string - education?: string salary?: string } } diff --git a/apps/stages/src/transformation/domain/service/hellowork/convertir.domain-service.ts b/apps/stages/src/transformation/domain/service/hellowork/convertir.domain-service.ts index f8c58591..7f5357de 100644 --- a/apps/stages/src/transformation/domain/service/hellowork/convertir.domain-service.ts +++ b/apps/stages/src/transformation/domain/service/hellowork/convertir.domain-service.ts @@ -80,8 +80,8 @@ export class Convertir { return { // TODO (BRUJ 29-09-2023): changer dateDeDebutMax/Min - dateDeDebutMax: "", - dateDeDebutMin: "", + dateDeDebutMax: undefined, + dateDeDebutMin: undefined, description: offreDeStage.description, domaines: [{ nom: this.traduireDomaine(offreDeStage.seodomain) }], employeur: { @@ -110,8 +110,8 @@ export class Convertir { ville: offreDeStage.city, codePostal: offreDeStage.postalcode, pays: this.pays.versFormatISOAlpha2(offreDeStage.country), - latitude: Number(offreDeStage.geoloc.split(",")[0]), - longitude: Number(offreDeStage.geoloc.split(",")[1]), + latitude: offreDeStage.geoloc && Number(offreDeStage.geoloc.split(",")[0]), + longitude: offreDeStage.geoloc && Number(offreDeStage.geoloc?.split(",")[1]), }; } } diff --git a/apps/stages/test/transformation/application-service/transformer-flux-hellowork.usecase.test.ts b/apps/stages/test/transformation/application-service/transformer-flux-hellowork.usecase.test.ts index 1076d026..383e7815 100644 --- a/apps/stages/test/transformation/application-service/transformer-flux-hellowork.usecase.test.ts +++ b/apps/stages/test/transformation/application-service/transformer-flux-hellowork.usecase.test.ts @@ -1,21 +1,21 @@ import { expect, sinon, StubbedClass, StubbedType, stubClass, stubInterface } from "@test/library"; -import { AssainisseurDeTexte } from "@shared/src/domain/service/assainisseur-de-texte"; import { DateService } from "@shared/src/domain/service/date.service"; import { Pays } from "@shared/src/domain/service/pays"; import { - TransformerFluxJobteaser, -} from "@stages/src/transformation/application-service/transformer-flux-jobteaser.usecase"; + TransformerFluxHellowork, +} from "@stages/src/transformation/application-service/transformer-flux-hellowork.usecase"; import { UnJeune1Solution } from "@stages/src/transformation/domain/model/1jeune1solution"; import { FluxTransformation } from "@stages/src/transformation/domain/model/flux"; -import { Jobteaser } from "@stages/src/transformation/domain/model/jobteaser"; -import { Convertir } from "@stages/src/transformation/domain/service/jobteaser/convertir.domain-service"; +import { Hellowork } from "@stages/src/transformation/domain/model/hellowork"; +import { Convertir } from "@stages/src/transformation/domain/service/hellowork/convertir.domain-service"; import { OffreDeStageRepository } from "@stages/src/transformation/domain/service/offre-de-stage.repository"; import { OffreDeStageFixtureBuilder } from "@stages/test/transformation/fixture/offre-de-stage.fixture-builder"; import { - OffreDeStageJobteaserFixtureBuilder, -} from "@stages/test/transformation/fixture/offre-de-stage-jobteaser.fixture-builder"; + OffreDeStageHelloworkFixtureBuilder, +} from "@stages/test/transformation/fixture/offre-de-stage-hellowork.fixture-builder"; +import Source = UnJeune1Solution.Source; const dateEcriture = new Date("2022-01-01T00:00:00.000Z"); let resultatTransformation: Array; @@ -26,9 +26,8 @@ let flux: FluxTransformation; let dateService: StubbedClass; let offreDeStageRepository: StubbedType; let convertisseurDePays: StubbedType; -let assainisseurDeTexte: StubbedType; let convertirOffreDeStage: Convertir; -let transformFluxJobteaser: TransformerFluxJobteaser; +let transformFluxHellowork: TransformerFluxHellowork; describe("TransformerFluxHelloworkTest", () => { context("Lorsque je transforme le flux en provenance de hellowork", () => { context("Lorsque tout est renseigné", () => { @@ -36,19 +35,34 @@ describe("TransformerFluxHelloworkTest", () => { dossierDHistorisation = "history"; nomDuFlux = "source"; resultatTransformation = [OffreDeStageFixtureBuilder.build({ - description: "

Contenu

-nettoyé", - dureeEnJourMax: undefined, - dureeEnJour: 5400, + description: "Description de l'offre", employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", + nom: "Nom de l'entreprise", logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", }, - remunerationBase: undefined, - teletravailPossible: undefined, + domaines: [{ nom: UnJeune1Solution.Domaine.LOGISTIQUE }], + identifiantSource: "Identifiant source", + localisation: { + ville: "Marseille", + codePostal: "13000", + pays: "FR", + latitude: 15.5, + longitude: 16.78, + }, + source: Source.HELLOWORK, + sourceCreatedAt: "2022-01-01T00:00:00.000Z", + sourceUpdatedAt: "2022-01-01T00:00:00.000Z", + titre: "Titre de l'offre", + urlDeCandidature: "https://url-de-candidature.com", + dateDeDebutMax: undefined, + dateDeDebutMin: undefined, })]; + delete resultatTransformation[0].remunerationBase; + delete resultatTransformation[0].dureeEnJour; + delete resultatTransformation[0].dureeEnJourMax; + delete resultatTransformation[0].teletravailPossible; + flux = new FluxTransformation( nomDuFlux, dossierDHistorisation, @@ -59,56 +73,63 @@ describe("TransformerFluxHelloworkTest", () => { dateService = stubClass(DateService); offreDeStageRepository = stubInterface(sinon); convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); + convertirOffreDeStage = new Convertir(dateService, convertisseurDePays); + transformFluxHellowork = new TransformerFluxHellowork(offreDeStageRepository, convertirOffreDeStage); dateService.maintenant.returns(dateEcriture); convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); offreDeStageRepository.recuperer.resolves({ - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, + source: { + job: [OffreDeStageHelloworkFixtureBuilder.build({ + title: "Titre de l'offre", + description: "Description de l'offre", + compagny: "Nom de l'entreprise", + logo: "http://url.du.logo", + seodomain: Hellowork.Domaine.LOGISTIQUE, + date: "2022-01-01T00:00:00.000Z", + city: "Marseille", + postalcode: "13000", + country: "France", + link: "https://url-de-candidature.com", + id: "Identifiant source", + geoloc: "15.5,16.78", })], }, }); }); it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); + await transformFluxHellowork.executer(flux); expect(offreDeStageRepository.recuperer).to.have.been.calledOnce; expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); }); }); - context("Lorsqu'il n'y a qu'un seul domaine", () => { + context("Lorsque la geolocalisation n'est pas renseigné", () => { beforeEach(() => { dossierDHistorisation = "history"; nomDuFlux = "source"; resultatTransformation = [OffreDeStageFixtureBuilder.build({ - description: "

Contenu

-nettoyé", - employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", + dateDeDebutMin: undefined, + dateDeDebutMax: undefined, + source: Source.HELLOWORK, + localisation: { + ville: "Marseille", + codePostal: "13000", + pays: "FR", + latitude: undefined, + longitude: undefined, }, - domaines: [{ nom: UnJeune1Solution.Domaine.CHIMIE_BIOLOGIE_AGRONOMIE }], - teletravailPossible: undefined, - dureeEnJour: 180, - dureeEnJourMax: undefined, - remunerationBase: undefined, })]; + delete resultatTransformation[0].remunerationBase; + delete resultatTransformation[0].dureeEnJour; + delete resultatTransformation[0].dureeEnJourMax; + delete resultatTransformation[0].teletravailPossible; + delete resultatTransformation[0].employeur.description; + delete resultatTransformation[0].employeur.siteUrl; + flux = new FluxTransformation( nomDuFlux, dossierDHistorisation, @@ -119,230 +140,55 @@ describe("TransformerFluxHelloworkTest", () => { dateService = stubClass(DateService); offreDeStageRepository = stubInterface(sinon); convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); + convertirOffreDeStage = new Convertir(dateService, convertisseurDePays); + transformFluxHellowork = new TransformerFluxHellowork(offreDeStageRepository, convertirOffreDeStage); dateService.maintenant.returns(dateEcriture); convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); - - offreDeStageRepository.recuperer.resolves({ - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: Jobteaser.Domaine.AGRONOMIE_BIOLOGIE, - }, - contract: { - duration: { - amount: "180", - type: undefined, - }, - name: "Internship", - }, - })], - }, + const offreHellowork = OffreDeStageHelloworkFixtureBuilder.build({ + city: "Marseille", + postalcode: "13000", + country: "France", }); - }); - - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); - - expect(offreDeStageRepository.recuperer).to.have.been.calledOnce; - expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); - }); - }); - - context("Lorsqu'il y a plusieurs domaines", () => { - beforeEach(() => { - dossierDHistorisation = "history"; - nomDuFlux = "source"; - resultatTransformation = [OffreDeStageFixtureBuilder.build({ - description: "

Contenu

-nettoyé", - employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", - }, - domaines: [ - { nom: UnJeune1Solution.Domaine.CHIMIE_BIOLOGIE_AGRONOMIE }, - { nom: UnJeune1Solution.Domaine.JOURNALISME_RP_MEDIAS }, - ], - teletravailPossible: undefined, - dureeEnJour: 180, - localisation: { - ville: "Montpellier", - codePostal: "34", - departement: "Hérault", - region: "Occitanie", - pays: "FR", - }, - dureeEnJourMax: undefined, - remunerationBase: undefined, - })]; - - flux = new FluxTransformation(nomDuFlux, dossierDHistorisation, ".xml", ".json"); - - dateService = stubClass(DateService); - offreDeStageRepository = stubInterface(sinon); - convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); - - dateService.maintenant.returns(dateEcriture); - convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); - + delete offreHellowork.geoloc; + offreDeStageRepository.recuperer.resolves({ - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: [Jobteaser.Domaine.AGRONOMIE_BIOLOGIE, Jobteaser.Domaine.MEDIA], - }, - contract: { - duration: { - amount: "180", - type: undefined, - }, - name: "Internship", - }, - })], + source: { + job: [offreHellowork], }, }); }); - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); + it("je le sauvegarde sans la longitude et la latitude", async () => { + await transformFluxHellowork.executer(flux); - expect(offreDeStageRepository.recuperer).to.have.been.called; + expect(offreDeStageRepository.recuperer).to.have.been.calledOnce; expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); }); }); - context("Lorsqu'il n'y a pas d'employeur", () => { + context("Lorsque le domaine n'est pas renseigné", () => { beforeEach(() => { dossierDHistorisation = "history"; nomDuFlux = "source"; resultatTransformation = [OffreDeStageFixtureBuilder.build({ - description: "

Contenu

-nettoyé", - employeur: { - description: undefined, - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", - }, - domaines: [ - { nom: UnJeune1Solution.Domaine.CHIMIE_BIOLOGIE_AGRONOMIE }, - { nom: UnJeune1Solution.Domaine.JOURNALISME_RP_MEDIAS }, - ], - teletravailPossible: undefined, - dureeEnJour: 180, - localisation: { - ville: "Montpellier", - codePostal: "34", - departement: "Hérault", - region: "Occitanie", - pays: "FR", - }, - dureeEnJourMax: undefined, remunerationBase: undefined, + dateDeDebutMin: undefined, + dateDeDebutMax: undefined, + source: Source.HELLOWORK, + domaines: [{ nom: UnJeune1Solution.Domaine.NON_APPLICABLE }], + }, { + latitude: undefined, + longitude: undefined, })]; - flux = new FluxTransformation(nomDuFlux, dossierDHistorisation, ".xml", ".json"); - - dateService = stubClass(DateService); - offreDeStageRepository = stubInterface(sinon); - convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); - - dateService.maintenant.returns(dateEcriture); - convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); - - const fluxJobteaser = { - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: [Jobteaser.Domaine.AGRONOMIE_BIOLOGIE, Jobteaser.Domaine.MEDIA], - }, - contract: { - duration: { - amount: "180", - type: undefined, - }, - name: "Internship", - }, - })], - }, - }; - delete fluxJobteaser.jobs.job[0].company.description; - - offreDeStageRepository.recuperer.resolves(fluxJobteaser); - }); - - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); - - expect(offreDeStageRepository.recuperer).to.have.been.called; - expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); - }); - }); - - context("Lorsqu'il n'y a pas de durée renseignée", () => { - beforeEach(() => { - dossierDHistorisation = "history"; - nomDuFlux = "source"; - resultatTransformation = [OffreDeStageFixtureBuilder.build({ - description: "

Contenu

-nettoyé", - employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", - }, - domaines: [ - { nom: UnJeune1Solution.Domaine.CHIMIE_BIOLOGIE_AGRONOMIE }, - { nom: UnJeune1Solution.Domaine.JOURNALISME_RP_MEDIAS }, - ], - teletravailPossible: undefined, - localisation: { - ville: "Montpellier", - codePostal: "34", - departement: "Hérault", - region: "Occitanie", - pays: "FR", - }, - dureeEnJourMax: undefined, - dureeEnJour: undefined, - remunerationBase: undefined, - })]; + delete resultatTransformation[0].remunerationBase; + delete resultatTransformation[0].dureeEnJour; + delete resultatTransformation[0].dureeEnJourMax; + delete resultatTransformation[0].teletravailPossible; + delete resultatTransformation[0].employeur.description; + delete resultatTransformation[0].employeur.siteUrl; + delete resultatTransformation[0].localisation.region; + delete resultatTransformation[0].localisation.departement; flux = new FluxTransformation( nomDuFlux, @@ -354,280 +200,27 @@ describe("TransformerFluxHelloworkTest", () => { dateService = stubClass(DateService); offreDeStageRepository = stubInterface(sinon); convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); - - dateService.maintenant.returns(dateEcriture); - convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); - - const fluxJobteaser = { - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: [Jobteaser.Domaine.AGRONOMIE_BIOLOGIE, Jobteaser.Domaine.MEDIA], - }, - contract: { - duration: { - amount: "180", - type: undefined, - }, - name: "Internship", - }, - })], - }, - }; - delete fluxJobteaser.jobs.job[0].contract?.duration; - - offreDeStageRepository.recuperer.resolves(fluxJobteaser); - }); - - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); - - expect(offreDeStageRepository.recuperer).to.have.been.called; - expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); - }); - }); - - context("Lorsqu'il n'y a pas de date de début renseignée", () => { - beforeEach(() => { - dossierDHistorisation = "history"; - nomDuFlux = "source"; - resultatTransformation = [OffreDeStageFixtureBuilder.build({ - dateDeDebutMax: dateEcriture.toISOString(), - dateDeDebutMin: dateEcriture.toISOString(), - description: "

Contenu

-nettoyé", - domaines: [ - { nom: UnJeune1Solution.Domaine.CHIMIE_BIOLOGIE_AGRONOMIE }, - { nom: UnJeune1Solution.Domaine.JOURNALISME_RP_MEDIAS }, - ], - dureeEnJour: undefined, - dureeEnJourMax: undefined, - employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", - }, - remunerationBase: undefined, - teletravailPossible: undefined, - })]; - - flux = new FluxTransformation(nomDuFlux, dossierDHistorisation, ".xml", ".json"); - - dateService = stubClass(DateService); - offreDeStageRepository = stubInterface(sinon); - convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); - - dateService.maintenant.returns(dateEcriture); - convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); - - const fluxJobteaser = { - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: [Jobteaser.Domaine.AGRONOMIE_BIOLOGIE, Jobteaser.Domaine.MEDIA], - }, - start_date: undefined, - contract: { - duration: { - amount: "180", - type: undefined, - }, - name: "Internship", - }, - })], - }, - }; - delete fluxJobteaser.jobs.job[0].contract?.duration; - - offreDeStageRepository.recuperer.resolves(fluxJobteaser); - }); - - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); - - expect(offreDeStageRepository.recuperer).to.have.been.called; - expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); - }); - }); - - context("Lorsqu'il n'y a pas de correspondance pour un domaine Jobteaser", () => { - beforeEach(() => { - dossierDHistorisation = "history"; - nomDuFlux = "source"; - resultatTransformation = [OffreDeStageFixtureBuilder.build({ - dateDeDebutMin: dateEcriture.toISOString(), - dateDeDebutMax: dateEcriture.toISOString(), - description: "

Contenu

-nettoyé", - domaines: [{ nom: UnJeune1Solution.Domaine.NON_APPLICABLE }], - dureeEnJourMax: undefined, - dureeEnJour: undefined, - employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", - }, - localisation: { - ville: "Montpellier", - codePostal: "34", - departement: "Hérault", - region: "Occitanie", - pays: "FR", - }, - teletravailPossible: undefined, - remunerationBase: undefined, - })]; - - flux = new FluxTransformation(nomDuFlux, dossierDHistorisation, ".xml", ".json"); - - dateService = stubClass(DateService); - offreDeStageRepository = stubInterface(sinon); - convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); + convertirOffreDeStage = new Convertir(dateService, convertisseurDePays); + transformFluxHellowork = new TransformerFluxHellowork(offreDeStageRepository, convertirOffreDeStage); dateService.maintenant.returns(dateEcriture); convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); + const offreHellowork = OffreDeStageHelloworkFixtureBuilder.build(); + delete offreHellowork.geoloc; + delete offreHellowork.seodomain; - const fluxJobteaser = { - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: ["Wrong value"], - }, - start_date: undefined, - contract: { - duration: { - amount: "180", - type: undefined, - }, - name: "Internship", - }, - })], - }, - }; - delete fluxJobteaser.jobs.job[0].contract?.duration; - - offreDeStageRepository.recuperer.resolves(fluxJobteaser); - }); - - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); - - expect(offreDeStageRepository.recuperer).to.have.been.called; - expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); - }); - }); - - context("Lorsqu'il y a un type renseigné pour la durée d'un stage", () => { - beforeEach(() => { - dossierDHistorisation = "history"; - nomDuFlux = "source"; - resultatTransformation = [OffreDeStageFixtureBuilder.build({ - description: "

Contenu

-nettoyé", - employeur: { - description: "

Description de l'entreprise

-nettoyé", - nom: "Nom de l'entreprise-nettoyé", - logoUrl: "http://url.du.logo", - siteUrl: "http://site.de.l.entreprise", - }, - domaines: [{ nom: UnJeune1Solution.Domaine.NON_APPLICABLE }], - teletravailPossible: undefined, - localisation: { - ville: "Montpellier", - codePostal: "34", - departement: "Hérault", - region: "Occitanie", - pays: "FR", - }, - dateDeDebutMin: dateEcriture.toISOString(), - dateDeDebutMax: dateEcriture.toISOString(), - dureeEnJour: 150, - dureeEnJourMax: undefined, - remunerationBase: undefined, - })]; - - flux = new FluxTransformation(nomDuFlux, dossierDHistorisation, ".xml", ".json"); - - dateService = stubClass(DateService); - offreDeStageRepository = stubInterface(sinon); - convertisseurDePays = stubInterface(sinon); - assainisseurDeTexte = stubInterface(sinon); - convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays); - transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage); - - dateService.maintenant.returns(dateEcriture); - convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR"); - assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé")); - - const fluxJobteaser = { - jobs: { - job: [OffreDeStageJobteaserFixtureBuilder.build({ - mission: "

Contenu

", - company: { - description: "

Description de l'entreprise

", - name: "Nom de l'entreprise", - logo: "http://url.du.logo", - domain: "Domaine d'activité de l'entreprise", - website: "http://site.de.l.entreprise", - }, - domains: { - domain: ["Wrong value"], - }, - start_date: undefined, - contract: { - duration: { - amount: "5", - type: "months", - }, - name: "Internship", - }, - })], + offreDeStageRepository.recuperer.resolves({ + source: { + job: [offreHellowork], }, - }; - - offreDeStageRepository.recuperer.resolves(fluxJobteaser); + }); }); - it("je le sauvegarde dans le format attendu", async () => { - await transformFluxJobteaser.executer(flux); + it("je le sauvegarde avec le domaine par défaut", async () => { + await transformFluxHellowork.executer(flux); - expect(offreDeStageRepository.recuperer).to.have.been.called; - expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]); + expect(offreDeStageRepository.recuperer).to.have.been.calledOnce; + expect(offreDeStageRepository.sauvegarder.getCall(0).args[0]).to.have.deep.members(resultatTransformation); }); }); }); diff --git a/apps/stages/test/transformation/fixture/offre-de-stage-hellowork.fixture-builder.ts b/apps/stages/test/transformation/fixture/offre-de-stage-hellowork.fixture-builder.ts new file mode 100644 index 00000000..b8d537ab --- /dev/null +++ b/apps/stages/test/transformation/fixture/offre-de-stage-hellowork.fixture-builder.ts @@ -0,0 +1,24 @@ +import { Hellowork } from "@stages/src/transformation/domain/model/hellowork"; + +export class OffreDeStageHelloworkFixtureBuilder { + public static build( + offreDeStage?: Partial, + ): Hellowork.OffreDeStage { + return { + title: "Titre de l'offre", + description: "Description de l'offre", + compagny: "Nom de l'entreprise", + logo: "http://url.du.logo", + seodomain: Hellowork.Domaine.NULL, + date: "2022-01-01T00:00:00.000Z", + city: "Montpellier", + postalcode: "34", + country: "France", + link: "http://url.de.candidature.com", + id: "Identifiant source", + geoloc: "15.5,16.78", + salary: "1000-2000 EUR par mois", + ...offreDeStage, + }; + } +}