Skip to content

Commit

Permalink
fix(jobteaser): rejette les stages dont la dateDebut est antérieure à…
Browse files Browse the repository at this point in the history
… 1 mois
  • Loading branch information
sokl-octo committed Aug 12, 2024
1 parent 6b7d0ef commit adb3a4f
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 13 deletions.
6 changes: 3 additions & 3 deletions apps/stages/src/transformation/application-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ import { Gateways } from "@stages/src/transformation/infrastructure/gateway";
},
{
provide: TransformerFluxJobteaser,
inject: ["OffreDeStageRepository", ConvertirJobteaser],
useFactory: (offreDeStageRepository: OffreDeStageRepository, convertirOffreDeStage: ConvertirJobteaser): TransformerFluxJobteaser => {
return new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
inject: ["OffreDeStageRepository", ConvertirJobteaser, DateService],
useFactory: (offreDeStageRepository: OffreDeStageRepository, convertirOffreDeStage: ConvertirJobteaser, dateService: DateService): TransformerFluxJobteaser => {
return new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DateTime } from "luxon";

import { Usecase } from "@shared/src/application-service/usecase";
import { DateService } from "@shared/src/domain/service/date.service";

import { UnJeune1Solution } from "@stages/src/transformation/domain/model/1jeune1solution";
import { FluxTransformation } from "@stages/src/transformation/domain/model/flux";
Expand All @@ -10,14 +13,18 @@ export class TransformerFluxJobteaser implements Usecase {
constructor(
private readonly offreDeStageRepository: OffreDeStageRepository,
private readonly convertirOffreDeStage: Convertir,
private readonly dateService: DateService,
) {
}

public async executer(flux: FluxTransformation): Promise<void> {
const contenuDuFlux = await this.offreDeStageRepository.recuperer<Jobteaser.Contenu>(flux);

const contenuTransforme: Array<UnJeune1Solution.OffreDeStage>
= contenuDuFlux.jobs.job.map((job: Jobteaser.OffreDeStage) => this.convertirOffreDeStage.depuisJobteaser(job));
const contenuFiltre: Array<Jobteaser.OffreDeStage> = contenuDuFlux.jobs.job.filter((job: Jobteaser.OffreDeStage) => {
const unMoisPlusTot: DateTime = DateTime.fromJSDate(this.dateService.maintenant()).minus({ "month": 1 });
return !job.start_date || DateTime.fromISO(job.start_date) >= unMoisPlusTot;
});
const contenuTransforme: Array<UnJeune1Solution.OffreDeStage> = contenuFiltre.map((job: Jobteaser.OffreDeStage) => this.convertirOffreDeStage.depuisJobteaser(job));

await this.offreDeStageRepository.sauvegarder(contenuTransforme, flux);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DateTime } from "luxon";

import { expect, sinon, StubbedClass, StubbedType, stubClass, stubInterface } from "@test/library";

import { AssainisseurDeTexte } from "@shared/src/domain/service/assainisseur-de-texte";
Expand Down Expand Up @@ -64,7 +66,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -126,7 +128,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -204,7 +206,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -282,7 +284,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -368,7 +370,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -444,7 +446,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -488,6 +490,127 @@ describe("TransformerFluxJobteaserTest", () => {
});
});

context("Lorsqu'il y a une date de début renseignée", () => {
let dateDebutJobTeaserFiltree: Date;
let dateDebutJobTeaserAcceptee: Date;

beforeEach(() => {
dateDebutJobTeaserFiltree = DateTime.fromJSDate(dateEcriture).minus({ "month": 1, "days": 1 }).toJSDate();
dateDebutJobTeaserAcceptee = DateTime.fromJSDate(dateEcriture).minus({ "month": 1 }).toJSDate();

dossierDHistorisation = "history";
nomDuFlux = "source";

flux = new FluxTransformation(nomDuFlux, dossierDHistorisation, ".xml", ".json");

dateService = stubClass(DateService);
offreDeStageRepository = stubInterface<OffreDeStageRepository>(sinon);
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
assainisseurDeTexte.nettoyer.callsFake((input: string) => (input + "-nettoyé"));
});

it("filtre l’offre expirée", async () => {
// Given
const fluxJobteaser = {
jobs: {
job: [OffreDeStageJobteaserFixtureBuilder.build({
title: "Titre de l’offre filtrée",
mission: "<p>Contenu</p>",
company: {
description: "<h1>Description de l'entreprise filtrée</h1>",
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: dateDebutJobTeaserFiltree.toISOString(),
contract: {
duration: {
amount: "180",
type: undefined,
},
name: "Internship",
},
})],
},
};

offreDeStageRepository.recuperer.resolves(fluxJobteaser);

// When
await transformFluxJobteaser.executer(flux);

// Then
resultatTransformation = [];
expect(offreDeStageRepository.recuperer).to.have.been.called;
expect(offreDeStageRepository.sauvegarder.getCall(0).args).to.have.deep.members([resultatTransformation, flux]);
});

it("sauvegarde l’offre à jour", async () => {
// Given
const fluxJobteaser = {
jobs: {
job: [OffreDeStageJobteaserFixtureBuilder.build({
title: "Titre de l’offre acceptée",
mission: "<p>Contenu</p>",
company: {
description: "<h1>Description de l'entreprise acceptée</h1>",
name: "Nom de l'entreprise",
logo: "http://url.du.logo",
domain: "Domaine d'activité de l'entreprise",
website: "http://site.de.l.entreprise",
},
start_date: dateDebutJobTeaserAcceptee.toISOString(),
contract: {
duration: {
amount: "180",
type: undefined,
},
name: "Internship",
},
})],
},
};
delete fluxJobteaser.jobs.job[0].contract?.duration;

offreDeStageRepository.recuperer.resolves(fluxJobteaser);

// When
await transformFluxJobteaser.executer(flux);

// Then
resultatTransformation = [OffreDeStageFixtureBuilder.build({
titre: "Titre de l’offre acceptée",
dateDeDebutMax: dateDebutJobTeaserAcceptee.toISOString(),
dateDeDebutMin: dateDebutJobTeaserAcceptee.toISOString(),
description: "<p>Contenu</p>-nettoyé",
dureeEnJour: undefined,
dureeEnJourMax: undefined,
employeur: {
description: "<h1>Description de l'entreprise acceptée</h1>-nettoyé",
nom: "Nom de l'entreprise-nettoyé",
logoUrl: "http://url.du.logo",
siteUrl: "http://site.de.l.entreprise",
},
remunerationMax: undefined,
remunerationMin: undefined,
remunerationPeriode: undefined,
teletravailPossible: undefined,
})];
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";
Expand Down Expand Up @@ -525,7 +648,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down Expand Up @@ -606,7 +729,7 @@ describe("TransformerFluxJobteaserTest", () => {
convertisseurDePays = stubInterface<Pays>(sinon);
assainisseurDeTexte = stubInterface<AssainisseurDeTexte>(sinon);
convertirOffreDeStage = new Convertir(dateService, assainisseurDeTexte, convertisseurDePays);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage);
transformFluxJobteaser = new TransformerFluxJobteaser(offreDeStageRepository, convertirOffreDeStage, dateService);

dateService.maintenant.returns(dateEcriture);
convertisseurDePays.versFormatISOAlpha2.withArgs("France").returns("FR");
Expand Down

0 comments on commit adb3a4f

Please sign in to comment.