Skip to content

Commit

Permalink
test: added test
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelFerrand committed May 31, 2024
1 parent adf3263 commit 2f0a78b
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion back/src/forms/__tests__/elastic.integration.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Company, Status } from "@prisma/client";
import { Company, Status, UserRole } from "@prisma/client";
import { resetDatabase } from "../../../integration-tests/helper";
import { prisma } from "@td/prisma";
import {
bsddTransporterData,
companyFactory,
formFactory,
formWithTempStorageFactory,
toIntermediaryCompany,
userFactory,
userWithCompanyFactory
} from "../../__tests__/factories";
import { getFirstTransporterSync, getFullForm } from "../database";
import { getSiretsByTab } from "../elasticHelpers";
import { getFormForElastic, toBsdElastic } from "../elastic";
import { BsdElastic } from "../../common/elastic";
import { RegistryFormInclude, toPrismaBsds } from "../../registry/elastic";
import { formToBsdd } from "../compat";
import { toAllWaste } from "../registry";

describe("getSiretsByTab", () => {
afterEach(resetDatabase);
Expand Down Expand Up @@ -534,3 +538,39 @@ describe("toBsdElastic > companies Names & OrgIds", () => {
);
});
});

describe("toPrismaBsds", () => {
afterEach(resetDatabase);

it("BSDD should contain intermediaries", async () => {
// Given
const user = await userFactory();
const intermediary1 = await userWithCompanyFactory(UserRole.MEMBER);
const intermediary2 = await userWithCompanyFactory(UserRole.MEMBER);
const intermediary3 = await userWithCompanyFactory(UserRole.MEMBER);
const bsdd = await formFactory({
ownerId: user.id,
opt: {
intermediaries: {
create: [
toIntermediaryCompany(intermediary1.company),
toIntermediaryCompany(intermediary2.company),
toIntermediaryCompany(intermediary3.company)
]
}
}
});

// When
const formForElastic = await getFormForElastic(bsdd);
const elasticBsd = toBsdElastic(formForElastic);
const result = await toPrismaBsds([elasticBsd]);

// Then
expect(result).not.toBeUndefined();
expect(result.bsdds).not.toBeUndefined();
expect(result.bsdds.length).toEqual(1);
expect(result.bsdds[0].intermediaries).not.toBeUndefined();
expect(result.bsdds[0].intermediaries.length).toEqual(3);
});
});

0 comments on commit 2f0a78b

Please sign in to comment.