Skip to content

Commit

Permalink
feat(stages): chargement du flux hellowork (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Naorid authored Oct 9, 2023
1 parent dfee6e9 commit d50c9d0
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 6 deletions.
4 changes: 4 additions & 0 deletions apps/cli/src/command/load.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
import { LoadFlowImmojeuneSubCommand } from "@logements/src/chargement/infrastructure/sub-command/load-flow-immojeune.sub-command";
import { LoadFlowStudapartSubCommand } from "@logements/src/chargement/infrastructure/sub-command/load-flow-studapart.sub-command";

import {
LoadFlowHelloworkSubCommand,
} from "@stages/src/chargement/infrastructure/sub-command/load-flow-hellowork.sub-command";
import { LoadFlowJobteaserSubCommand } from "@stages/src/chargement/infrastructure/sub-command/load-flow-jobteaser.sub-command";
import {
LoadFlowStagefrCompressedSubCommand,
Expand All @@ -25,6 +28,7 @@ import {
LoadFlowTousMobilisesSubCommand,
LoadFlowImmojeuneSubCommand,
LoadFlowStudapartSubCommand,
LoadFlowHelloworkSubCommand,
LoadFlowJobteaserSubCommand,
LoadFlowStagefrCompressedSubCommand,
LoadFlowStagefrUncompressedSubCommand,
Expand Down
14 changes: 14 additions & 0 deletions apps/cli/test/cli.module.integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import { PurgerLesOffresDeStage } from "@maintenance/src/application-service/purger-les-offres-de-stage.usecase";
import { MinioAdminStorageRepository } from "@maintenance/src/infrastructure/gateway/repository/minio-admin-storage.repository";

import { ChargerFluxHellowork } from "@stages/src/chargement/application-service/charger-flux-hellowork.usecase";
import { ChargerFluxJobteaser } from "@stages/src/chargement/application-service/charger-flux-jobteaser.usecase";
import {
ChargerFluxStagefrCompresse,
Expand Down Expand Up @@ -263,6 +264,7 @@ describe("CliModuleTest", () => {
});

context("Lorsque je lance la commande de chargement", () => {
let chargerHellowork: StubbedClass<ChargerFluxHellowork>;
let chargerJobteaser: StubbedClass<ChargerFluxJobteaser>;
let chargerStagefrCompresse: StubbedClass<ChargerFluxStagefrCompresse>;
let chargerStagefrDecompresse: StubbedClass<ChargerFluxStagefrDecompresse>;
Expand All @@ -272,6 +274,7 @@ describe("CliModuleTest", () => {
let chargerOnisep: StubbedClass<ChargerFluxOnisep>;

beforeEach(async () => {
chargerHellowork = stubClass(ChargerFluxHellowork);
chargerJobteaser = stubClass(ChargerFluxJobteaser);
chargerStagefrCompresse = stubClass(ChargerFluxStagefrCompresse);
chargerStagefrDecompresse = stubClass(ChargerFluxStagefrDecompresse);
Expand All @@ -285,6 +288,7 @@ describe("CliModuleTest", () => {
})
.overrideProvider(Client).useValue(stubClass(Client))
.overrideProvider(ChargerFluxOnisep).useValue(chargerOnisep)
.overrideProvider(ChargerFluxHellowork).useValue(chargerHellowork)
.overrideProvider(ChargerFluxJobteaser).useValue(chargerJobteaser)
.overrideProvider(ChargerFluxStagefrCompresse).useValue(chargerStagefrCompresse)
.overrideProvider(ChargerFluxStagefrDecompresse).useValue(chargerStagefrDecompresse)
Expand All @@ -303,6 +307,16 @@ describe("CliModuleTest", () => {
expect(chargerOnisep.executer).to.have.been.calledOnce;
});
});

context("du flux Hellowork", () => {
it("execute la commande", async () => {
// When
await CommandTestFactory.run(cliModule, ["load", "hellowork"]);

// Then
expect(chargerHellowork.executer).to.have.been.calledOnce;
});
});

context("du flux Jobteaser", () => {
it("execute la commande", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Usecase } from "@shared/src/application-service/usecase";

import { FluxChargement } from "@stages/src/chargement/domain/model/flux";
import {
ChargerOffresDeStageDomainService,
} from "@stages/src/chargement/domain/service/charger-offres-de-stage.domain-service";

export class ChargerFluxHellowork implements Usecase {
constructor(private readonly chargerOffresDeStages: ChargerOffresDeStageDomainService) {
}

public async executer(flux: FluxChargement): Promise<void> {
await this.chargerOffresDeStages.charger(flux);
}
}
10 changes: 9 additions & 1 deletion apps/stages/src/chargement/application-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Module } from "@nestjs/common";
import { Shared } from "@shared/src";
import { DateService } from "@shared/src/domain/service/date.service";

import { ChargerFluxHellowork } from "@stages/src/chargement/application-service/charger-flux-hellowork.usecase";
import { ChargerFluxJobteaser } from "@stages/src/chargement/application-service/charger-flux-jobteaser.usecase";
import {
ChargerFluxStagefrCompresse,
Expand Down Expand Up @@ -50,8 +51,15 @@ import { Gateways } from "@stages/src/chargement/infrastructure/gateway";
return new ChargerFluxStagefrDecompresse(chargerOffresDeStageDomainService);
},
},
{
provide: ChargerFluxHellowork,
inject: [ChargerOffresDeStageDomainService],
useFactory: (chargerOffresDeStageDomainService: ChargerOffresDeStageDomainService): ChargerFluxHellowork => {
return new ChargerFluxHellowork(chargerOffresDeStageDomainService);
},
},
],
exports: [ChargerFluxJobteaser, ChargerFluxStagefrCompresse, ChargerFluxStagefrDecompresse],
exports: [ChargerFluxJobteaser, ChargerFluxStagefrCompresse, ChargerFluxStagefrDecompresse, ChargerFluxHellowork],
})
export class Usecases {
}
15 changes: 14 additions & 1 deletion apps/stages/src/chargement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";

import { Usecases } from "@stages/src/chargement/application-service";
import { ChargerFluxHellowork } from "@stages/src/chargement/application-service/charger-flux-hellowork.usecase";
import { ChargerFluxJobteaser } from "@stages/src/chargement/application-service/charger-flux-jobteaser.usecase";
import {
ChargerFluxStagefrCompresse,
Expand All @@ -10,6 +11,9 @@ import {
ChargerFluxStagefrDecompresse,
} from "@stages/src/chargement/application-service/charger-flux-stagefr-decompresse.usecase";
import { Configuration, ConfigurationFactory } from "@stages/src/chargement/infrastructure/configuration/configuration";
import {
LoadFlowHelloworkSubCommand,
} from "@stages/src/chargement/infrastructure/sub-command/load-flow-hellowork.sub-command";
import { LoadFlowJobteaserSubCommand } from "@stages/src/chargement/infrastructure/sub-command/load-flow-jobteaser.sub-command";
import {
LoadFlowStagefrCompressedSubCommand,
Expand All @@ -26,7 +30,15 @@ import {
}),
Usecases,
],
providers: [{
providers: [
{
provide: LoadFlowHelloworkSubCommand,
inject: [ConfigService, ChargerFluxHellowork],
useFactory: (configurationService: ConfigService, chargerFluxHellowork: ChargerFluxHellowork): LoadFlowHelloworkSubCommand => {
return new LoadFlowHelloworkSubCommand(chargerFluxHellowork, configurationService.get<Configuration>("stagesChargement"));
},
},
{
provide: LoadFlowJobteaserSubCommand,
inject: [ConfigService, ChargerFluxJobteaser],
useFactory: (configurationService: ConfigService, chargerFluxJobteaser: ChargerFluxJobteaser): LoadFlowJobteaserSubCommand => {
Expand All @@ -46,6 +58,7 @@ import {
},
}],
exports: [
LoadFlowHelloworkSubCommand,
LoadFlowJobteaserSubCommand,
LoadFlowStagefrCompressedSubCommand,
LoadFlowStagefrUncompressedSubCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Configuration = {
DOMAINE: Domaine
FEATURE_FLIPPING_CHARGEMENT: boolean
FLOWS: Array<string>
HELLOWORK: TaskConfiguration
JOBTEASER: TaskConfiguration
LOGGER_LOG_LEVEL: LogLevel
MINIO: MinioConfiguration
Expand Down Expand Up @@ -58,9 +59,15 @@ export class ConfigurationFactory extends ConfigurationValidator {
FEATURE_FLIPPING_CHARGEMENT: toBoolean(getOrDefault("INTERNSHIPS_FEATURE_FLIPPING_CHARGEMENT", "false")),
FLOWS: [
getOrError("INTERNSHIPS_JOBTEASER_NAME"),
getOrError("INTERNSHIPS_HELLOWORK_NAME"),
getOrError("INTERNSHIPS_STAGEFR_COMPRESSED_NAME"),
getOrError("INTERNSHIPS_STAGEFR_UNCOMPRESSED_NAME"),
],
HELLOWORK: {
DIRECTORY_NAME: getOrDefault("INTERNSHIPS_HELLOWORK_DIRECTORY_NAME", "hellowork"),
NAME: getOrDefault("INTERNSHIPS_HELLOWORK_NAME", "hellowork"),
TRANSFORMED_FILE_EXTENSION: getOrError("INTERNSHIPS_HELLOWORK_TRANSFORMED_FILE_EXTENSION"),
},
JOBTEASER: {
DIRECTORY_NAME: getOrDefault("INTERNSHIPS_JOBTEASER_DIRECTORY_NAME", "jobteaser"),
NAME: getOrDefault("INTERNSHIPS_JOBTEASER_NAME", "jobteaser"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CommandRunner, SubCommand } from "nest-commander";

import { ChargerFluxHellowork } from "@stages/src/chargement/application-service/charger-flux-hellowork.usecase";
import { FluxChargement } from "@stages/src/chargement/domain/model/flux";
import { Configuration } from "@stages/src/chargement/infrastructure/configuration/configuration";
import { CommandLog } from "@stages/src/chargement/infrastructure/configuration/log.decorator";

@SubCommand({ name: LoadFlowHelloworkSubCommand.FLOW_NAME })
export class LoadFlowHelloworkSubCommand extends CommandRunner {
private static readonly FLOW_NAME = "hellowork";

constructor(
private readonly chargerHellowork: ChargerFluxHellowork,
private readonly configuration: Configuration
) {
super();
}

@CommandLog(LoadFlowHelloworkSubCommand.FLOW_NAME)
public async run(): Promise<void> {
await this.chargerHellowork.executer(
new FluxChargement(this.configuration.HELLOWORK.NAME, this.configuration.HELLOWORK.TRANSFORMED_FILE_EXTENSION)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export class Convertir {
ville: offreDeStage.city,
codePostal: offreDeStage.postalcode.toString(),
pays: this.pays.versFormatISOAlpha2(offreDeStage.country),
latitude: offreDeStage.geoloc && Number(offreDeStage.geoloc.split(",")[0]),
longitude: offreDeStage.geoloc && Number(offreDeStage.geoloc.split(",")[1]),
latitude: offreDeStage.geoloc ? Number(offreDeStage.geoloc.split(",")[0]) : undefined,
longitude: offreDeStage.geoloc ? Number(offreDeStage.geoloc.split(",")[1]) : undefined,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect, StubbedClass, stubClass } from "@test/library";

import { ChargerFluxHellowork } from "@stages/src/chargement/application-service/charger-flux-hellowork.usecase";
import { FluxChargement } from "@stages/src/chargement/domain/model/flux";
import {
ChargerOffresDeStageDomainService,
} from "@stages/src/chargement/domain/service/charger-offres-de-stage.domain-service";

let extension: string;
let nomDuFlux: string;
let flux: FluxChargement;

let domainService: StubbedClass<ChargerOffresDeStageDomainService>;
let usecase: ChargerFluxHellowork;

describe("ChargerFluxHelloworkTest", () => {
context("Lorsque je charge le flux Hellowork", () => {
beforeEach(() => {
nomDuFlux = "hellowork";
extension = ".json";

flux = new FluxChargement(nomDuFlux, extension);

domainService = stubClass(ChargerOffresDeStageDomainService);
usecase = new ChargerFluxHellowork(domainService);
});

it("Je charge ce dernier", async () => {
await usecase.executer(flux);

expect(domainService.charger).to.have.been.calledOnce;
expect(domainService.charger).to.have.been.calledWith(flux);
});
});
});
12 changes: 10 additions & 2 deletions cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
"command": "0 7 * * * npm run cli -- extract jobteaser",
"size": "XL"
},
{
"command": "30 7 * * * npm run cli -- transform jobteaser",
"size": "XL"
},
{
"command": "45 7 * * * npm run cli -- load jobteaser",
"size": "XL"
},
{
"command": "0 4 * * * npm run cli -- extract hellowork",
"size": "XL"
},
{
"command": "30 7 * * * npm run cli -- transform jobteaser",
"command": "30 4 * * * npm run cli -- transform hellowork",
"size": "XL"
},
{
"command": "45 7 * * * npm run cli -- load jobteaser",
"command": "45 4 * * * npm run cli -- load hellowork",
"size": "XL"
},
{
Expand Down

0 comments on commit d50c9d0

Please sign in to comment.