Skip to content

Commit

Permalink
feat: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Aug 20, 2024
1 parent 9a45ed1 commit 734bd96
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/domain/usecases/MapDiseaseOutbreakToAlertsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import {
RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID,
} from "../../data/repositories/consts/DiseaseOutbreakConstants";

type DiseaseOutbreakEventData = Pick<
DiseaseOutbreakEventBaseAttrs,
"dataSourceCode" | "hazardType" | "incidentStatus" | "suspectedDiseaseCode"
>;

const incidentDataSourceCode = "IBS";

export class MapDiseaseOutbreakToAlertsUseCase {
constructor(private alertRepository: AlertRepository) {}

public execute(
diseaseOutbreakEventId: Id,
diseaseOutbreakEventData: DiseaseOutbreakEventBaseAttrs
diseaseOutbreakEventData: DiseaseOutbreakEventData
): FutureData<void> {
const { dataSourceCode, hazardType, suspectedDiseaseCode } = diseaseOutbreakEventData;
const hazardTypeCode = hazardTypeCodeMap[hazardType];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getTestCompositionRoot } from "../../../CompositionRoot";

describe("MapDiseaseOutbreakToAlertsUseCase", () => {
it("does not map disease outbreak to alerts if there is no event id", async () => {
const compositionRoot = getTestCompositionRoot();

compositionRoot.diseaseOutbreakEvent.mapDiseaseOutbreakEventToAlerts
.execute("", {
dataSourceCode: "EBS",
hazardType: "Biological:Human",
suspectedDiseaseCode: "",
incidentStatus: "Watch",
})
.run(
() => fail("Should not reach here"),
error => expect(error.message).toBe("Disease Outbreak Event Id is required")
);
});

it("maps disease outbreak to alerts", async () => {
const compositionRoot = getTestCompositionRoot();

compositionRoot.diseaseOutbreakEvent.mapDiseaseOutbreakEventToAlerts
.execute("123", {
dataSourceCode: "EBS",
hazardType: "Biological:Human",
suspectedDiseaseCode: "",
incidentStatus: "Watch",
})
.run(
data => expect(data).toBeUndefined(),
() => fail("Should not reach here")
);
});
});

0 comments on commit 734bd96

Please sign in to comment.