-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRA-13846] Tests E2E - Création d'un BSVHU (#3149)
* [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
1 parent
cbafa05
commit 26e1b1e
Showing
11 changed files
with
798 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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 | ||
} | ||
}); | ||
}; | ||
|
@@ -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({ | ||
|
@@ -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", | ||
|
@@ -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, | ||
|
@@ -110,7 +243,9 @@ export const seedDefaultCompanies = async () => { | |
companyJ, | ||
companyK, | ||
companyL, | ||
companyM | ||
companyM, | ||
companyN, | ||
companyO | ||
}; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.