-
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.
- Loading branch information
1 parent
5a8e55b
commit 8c39255
Showing
1 changed file
with
77 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,40 @@ import { sendMail } from "../../../mailer/mailing"; | |
import { sirenify } from "../sirene"; | ||
import { companyFactory, userFactory } from "../../../__tests__/factories"; | ||
import { bulkCreate, Opts } from "../index"; | ||
import { searchCompany } from "../../../companies/search"; | ||
|
||
// No mails | ||
jest.mock("../../../mailer/mailing"); | ||
(sendMail as jest.Mock).mockImplementation(() => Promise.resolve()); | ||
|
||
jest.mock("../sirene"); | ||
(sirenify as jest.Mock).mockImplementation(company => | ||
Promise.resolve({ | ||
...company, | ||
name: "NAME FROM SIRENE", | ||
address: "40 boulevard Voltaire 13001 Marseille", | ||
codeNaf: "62.01Z", | ||
latitude: 1, | ||
longitude: 1 | ||
}) | ||
); | ||
(sirenify as jest.Mock).mockImplementation(company => { | ||
if (company.siret === "85001946400021") { | ||
return { | ||
...company, | ||
name: "NAME FROM SIRENE", | ||
address: "40 boulevard Voltaire 13001 Marseille", | ||
codeNaf: "62.01Z", | ||
latitude: 1, | ||
longitude: 1 | ||
}; | ||
} | ||
|
||
if (company.siret === "81343950200028") { | ||
return { | ||
...company, | ||
name: "NAME FROM SIRENE", | ||
address: "4 boulevard Pasteur 44100 Nantes", | ||
codeNaf: "62.01Z", | ||
latitude: 1, | ||
longitude: 1 | ||
}; | ||
} | ||
}); | ||
|
||
jest.mock("../../../companies/search", () => ({ | ||
searchCompany: jest.fn().mockResolvedValue({ etatAdministratif: "A" }) | ||
})); | ||
|
||
export interface CompanyInfo { | ||
etablissement: { | ||
|
@@ -34,21 +52,35 @@ export interface CompanyInfo { | |
} | ||
|
||
describe("bulk create users and companies from csv files", () => { | ||
const { searchCompany } = require("../../../companies/search"); | ||
jest.mock("../../../companies/search"); | ||
(searchCompany as jest.Mock) | ||
.mockResolvedValue({ | ||
siret: "85001946400021", | ||
name: "Code en stock", | ||
statutDiffusionEtablissement: "O", | ||
etatAdministratif: "A" | ||
}) | ||
.mockResolvedValue({ | ||
siret: "81343950200028", | ||
name: "Frontier SAS", | ||
statutDiffusionEtablissement: "O", | ||
etatAdministratif: "A" | ||
}); | ||
(searchCompany as jest.Mock).mockImplementation((cue: string) => { | ||
console.log("!!! APPELLE !!!"); | ||
|
||
if (cue === "85001946400021") { | ||
return { | ||
siret: "85001946400021", | ||
name: "Code en stock", | ||
statutDiffusionEtablissement: "O", | ||
etatAdministratif: "A", | ||
addressVoie: "40 boulevard Voltaire", | ||
addressPostalCode: "13001", | ||
addressCity: "Marseille", | ||
codePaysEtrangerEtablissement: "" | ||
}; | ||
} | ||
if (cue === "81343950200028") { | ||
return { | ||
siret: "81343950200028", | ||
name: "Frontier SAS", | ||
statutDiffusionEtablissement: "O", | ||
etatAdministratif: "A", | ||
addressVoie: "4 boulevard Pasteur", | ||
addressPostalCode: "44100", | ||
addressCity: "Nantes", | ||
codePaysEtrangerEtablissement: "" | ||
}; | ||
} | ||
}); | ||
|
||
// CSV files are read from __tests__/csv folder | ||
// | ||
// In the test data we have | ||
|
@@ -294,26 +326,32 @@ describe("bulk create users and companies from csv files", () => { | |
}, 10000); | ||
|
||
test("should fill company's splitted address", async () => { | ||
await bulkCreateIdempotent(); | ||
|
||
await expectNumberOfRecords(2, 3, 4); | ||
// Given | ||
|
||
// check fields are OK for first user | ||
const john = await prisma.user.findUniqueOrThrow({ | ||
where: { email: "[email protected]" } | ||
}); | ||
expect(john.name).toEqual("[email protected]"); | ||
expect(john.isActive).toEqual(true); | ||
expect(john.activatedAt).toBeTruthy(); | ||
expect(john.firstAssociationDate).toBeTruthy(); | ||
// When | ||
await bulkCreateIdempotent(); | ||
|
||
// check fields are OK for first company | ||
// Then | ||
// Check fields are OK for first company | ||
const codeEnStock = await prisma.company.findUniqueOrThrow({ | ||
where: { siret: "85001946400021" } | ||
}); | ||
expect(codeEnStock.street).toEqual("40 BOULEVARD VOLTAIRE BAT G"); | ||
expect(codeEnStock.address).toEqual( | ||
"40 boulevard Voltaire 13001 Marseille" | ||
); | ||
expect(codeEnStock.street).toEqual("40 boulevard Voltaire"); | ||
expect(codeEnStock.postalCode).toEqual("13001"); | ||
expect(codeEnStock.city).toEqual("MARSEILLE"); | ||
expect(codeEnStock.city).toEqual("Marseille"); | ||
expect(codeEnStock.country).toEqual("FR"); | ||
|
||
// Check fields are OK for second company | ||
const frontierSAS = await prisma.company.findUniqueOrThrow({ | ||
where: { siret: "81343950200028" } | ||
}); | ||
expect(frontierSAS.address).toEqual("4 boulevard Pasteur 44100 Nantes"); | ||
expect(frontierSAS.street).toEqual("4 boulevard Pasteur"); | ||
expect(frontierSAS.postalCode).toEqual("44100"); | ||
expect(frontierSAS.city).toEqual("Nantes"); | ||
expect(frontierSAS.country).toEqual("FR"); | ||
}, 10000); | ||
}); |