Skip to content

Commit

Permalink
[TRA-13846] Tests E2E - Création d'un BSVHU (#3149)
Browse files Browse the repository at this point in the history
* [REVERT] fix: fixing script deploy-db.sh to work with integration env

* feat: improved company seed with agrements & new info

* fix: fixing test company with a VAT number to not collide on create (uniqueness)

* feat: starting the creation of the VHU. Last tab not entirely done

* feat: creating the VHU completely

* fix: increased timeout for CI

* feat: verifying overview modal data

* feat: extracting bsvhu id and splitting tests

* feat: delete vhu
  • Loading branch information
GaelFerrand authored Mar 22, 2024
1 parent cbafa05 commit 26e1b1e
Show file tree
Hide file tree
Showing 11 changed files with 798 additions and 50 deletions.
1 change: 0 additions & 1 deletion back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"preintegration-tests": "prisma db push && npm run reindex-all-bsds-bulk",
"bulk-create-account": "tsx src/users/bulk-creation/index.ts",
"reindex-partial-in-place": "tsx --tsconfig tsconfig.lib.json ./src/scripts/bin/reindexPartialInPlace.ts",
"reindex-all-bsds-bulk": "tsx --tsconfig tsconfig.lib.json ./src/scripts/bin/reindexAllInBulk.ts",
"reindex-favorites": "tsx --tsconfig tsconfig.lib.json ./src/scripts/bin/reindexFavorites.ts",
"reindex-bsd": "tsx --tsconfig tsconfig.lib.json ./src/scripts/bin/reindexBsd.ts $bsdId",
"purge-pdf-token": "tsx --tsconfig tsconfig.lib.json ./src/scripts/bin/purgePdfAccessToken.ts",
Expand Down
9 changes: 9 additions & 0 deletions back/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"types": {
"command": "tsc -p back/tsconfig.lib.json --noEmit"
},
"reindex-all-bsds-bulk": {
"executor": "nx:run-commands",
"options": {
"command": "tsx --tsconfig back/tsconfig.lib.json back/src/scripts/bin/reindexAllInBulk.ts"
},
"configurations": {
"integration": {}
}
},
"codegen": {
"inputs": ["{projectRoot}/**/*.graphql"],
"cache": true,
Expand Down
171 changes: 153 additions & 18 deletions e2e/src/data/company.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import { prisma } from "@td/prisma";
import { generateUniqueTestSiret } from "back";
import { CompanyType } from "@prisma/client";
import { generateUniqueTestSiret, randomNbrChain } from "back";
import { CompanyType, Prisma } from "@prisma/client";

export const seedCompany = async company => {
interface VhuAgrement {
agrementNumber: string;
department: string;
}

interface TransporterReceipt {
receiptNumber: string;
validityLimit: string;
department: string;
}

interface Opt {
transporterReceipt?: TransporterReceipt;
vhuAgrementDemolisseur?: VhuAgrement;
vhuAgrementBroyeur?: VhuAgrement;
}

const generateRandomVatNumber = countryPrefix => {
return `${countryPrefix}${randomNbrChain(8)}`;
};

export const seedCompany = async (
companyInput: Partial<Prisma.CompanyCreateInput>,
opt: Opt = {}
) => {
let siret: string | null = null;
if (!company.vatNumber) siret = await generateUniqueTestSiret();
if (!companyInput.vatNumber) siret = await generateUniqueTestSiret();

// Need to create an anonymous company so that fakeSirets increment
await prisma.anonymousCompany.create({
data: {
siret: siret,
orgId: siret ?? company.vatNumber,
orgId: siret ?? companyInput.vatNumber!,
name: "Établissement de test",
address: "Adresse test",
codeCommune: "00000",
Expand All @@ -19,13 +43,63 @@ export const seedCompany = async company => {
}
});

return prisma.company.create({
const company = await prisma.company.create({
data: {
securityCode: 1234,
verificationCode: "1234",
siret: siret,
orgId: siret ?? company.vatNumber,
...company
orgId: siret ?? companyInput.vatNumber!,
name: companyInput.name ?? "",
...companyInput
}
});

const { transporterReceipt, vhuAgrementBroyeur, vhuAgrementDemolisseur } =
opt;

if (transporterReceipt) {
const receipt = await prisma.transporterReceipt.create({
data: transporterReceipt
});

if (!!company) {
await prisma.company.update({
where: { id: company.id },
data: { transporterReceipt: { connect: { id: receipt.id } } }
});
}
}

if (vhuAgrementDemolisseur) {
const demolisseurAgrement = await prisma.vhuAgrement.create({
data: vhuAgrementDemolisseur
});

await prisma.company.update({
data: {
vhuAgrementDemolisseur: { connect: { id: demolisseurAgrement.id } }
},
where: { id: company.id }
});
}

if (vhuAgrementBroyeur) {
const broyeurAgrement = await prisma.vhuAgrement.create({
data: vhuAgrementBroyeur
});

await prisma.company.update({
data: { vhuAgrementBroyeur: { connect: { id: broyeurAgrement.id } } },
where: { id: company.id }
});
}

return prisma.company.findFirst({
where: { id: company.id },
include: {
transporterReceipt: true,
vhuAgrementBroyeur: true,
vhuAgrementDemolisseur: true
}
});
};
Expand All @@ -36,15 +110,27 @@ export const seedDefaultCompanies = async () => {
companyTypes: [CompanyType.PRODUCER]
});

const companyB = await seedCompany({
name: "B - Transporteur FR",
companyTypes: [CompanyType.TRANSPORTER]
});
const companyB = await seedCompany(
{
name: "B - Transporteur FR",
companyTypes: [CompanyType.TRANSPORTER],
contact: "Monsieur Transporteur",
contactPhone: "0472568954",
contactEmail: "[email protected]"
},
{
transporterReceipt: {
receiptNumber: "TRANS-063022024",
validityLimit: "2055-07-31T00:00:00.000Z",
department: "75"
}
}
);

const companyC = await seedCompany({
name: "C - Transporteur étranger",
companyTypes: [CompanyType.TRANSPORTER],
vatNumber: "DE00000001"
vatNumber: generateRandomVatNumber("DE")
});

const companyD = await seedCompany({
Expand Down Expand Up @@ -72,10 +158,25 @@ export const seedDefaultCompanies = async () => {
companyTypes: [CompanyType.WASTE_CENTER]
});

const companyI = await seedCompany({
name: "I - Broyeur / casse automobile",
companyTypes: [CompanyType.WASTE_VEHICLES]
});
const companyI = await seedCompany(
{
name: "I - Broyeur / casse automobile",
companyTypes: [CompanyType.WASTE_VEHICLES],
contact: "Monsieur Démolisseur et Broyeur",
contactPhone: "0458758956",
contactEmail: "[email protected]"
},
{
vhuAgrementDemolisseur: {
agrementNumber: "AGR-DEM-002",
department: "75"
},
vhuAgrementBroyeur: {
agrementNumber: "AGR-BROYEUR-002",
department: "75"
}
}
);

const companyJ = await seedCompany({
name: "J - Installation TTR",
Expand All @@ -97,6 +198,38 @@ export const seedDefaultCompanies = async () => {
companyTypes: [CompanyType.WASTEPROCESSOR]
});

const companyN = await seedCompany(
{
name: "N - Démolisseur",
companyTypes: [CompanyType.WASTE_VEHICLES],
contact: "Monsieur Démolisseur",
contactPhone: "0473625689",
contactEmail: "[email protected]"
},
{
vhuAgrementDemolisseur: {
agrementNumber: "AGR-DEM-001",
department: "75"
}
}
);

const companyO = await seedCompany(
{
name: "O - Broyeur",
companyTypes: [CompanyType.WASTE_VEHICLES],
contact: "Monsieur Broyeur",
contactPhone: "0475875695",
contactEmail: "[email protected]"
},
{
vhuAgrementBroyeur: {
agrementNumber: "AGR-BROYEUR-003",
department: "75"
}
}
);

return {
companyA,
companyB,
Expand All @@ -110,7 +243,9 @@ export const seedDefaultCompanies = async () => {
companyJ,
companyK,
companyL,
companyM
companyM,
companyN,
companyO
};
};

Expand Down
112 changes: 112 additions & 0 deletions e2e/src/plans/bsvhu/createBsvhu.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { test } from "@playwright/test";
import { successfulLogin } from "../../utils/user";
import { seedUser } from "../../data/user";
import {
seedDefaultCompanies,
seedCompanyAssociations
} from "../../data/company";
import { selectCompany } from "../../utils/navigation";
import {
createBsvhu,
duplicateBsvhu,
fixAndPublishBsvhu,
publishBsvhu,
verifyCardData,
verifyOverviewData,
deleteBsvhu
} from "../../utils/bsvhu";

test.describe.serial("Cahier de recette de création des BSVHU", async () => {
// User credentials
const USER_NAME = "User e2e Create BSVHU";
const USER_EMAIL = "[email protected]";
const USER_PASSWORD = "Us3r_E2E_Cre4te_BSVHU$$";

// User
let user;

// Companies
let companies;

test("Seed user", async () => {
user = await seedUser({
name: USER_NAME,
email: USER_EMAIL,
password: USER_PASSWORD
});
});

test("Seed des entreprises", async () => {
companies = await seedDefaultCompanies();

await seedCompanyAssociations(user.id, Object.values(companies), "ADMIN");
});

test("Utilisateur connecté", async ({ page }) => {
await test.step("Log in", async () => {
await successfulLogin(page, {
email: USER_EMAIL,
password: USER_PASSWORD
});
});

let vhuId, duplicatedVhuId;

await test.step("Création d'un BSVHU", async () => {
await selectCompany(page, companies.companyN.siret);

const { id } = await createBsvhu(page, {
emitter: companies.companyN,
transporter: companies.companyB,
destination: companies.companyI,
broyeur: companies.companyO
});

vhuId = id;
});

await test.step("Vérification des informations du bordereau sur la bsd card", async () => {
await verifyCardData(page, {
id: vhuId,
emitter: companies.companyN,
transporter: companies.companyB,
destination: companies.companyI
});
});

await test.step("Vérification des informations du bordereau dans l'Aperçu", async () => {
await verifyOverviewData(page, {
id: vhuId,
emitter: companies.companyN,
transporter: companies.companyB,
destination: companies.companyI
});
});

await test.step("Publication du bordereau", async () => {
await fixAndPublishBsvhu(page, {
id: vhuId
});
});

await test.step("Duplication du bordereau", async () => {
const { id } = await duplicateBsvhu(page, {
id: vhuId
});

duplicatedVhuId = id;
});

await test.step("Publication du bordereau dupliqué", async () => {
await publishBsvhu(page, {
id: duplicatedVhuId
});
});

await test.step("Suppression du bordereau dupliqué", async () => {
await deleteBsvhu(page, {
id: duplicatedVhuId
});
});
});
});
Loading

0 comments on commit 26e1b1e

Please sign in to comment.