With in my mocha tests, I have data-generation.js file that holds my functions and this code snippet creates my invalid csv.file. This file has 4 missing fields Clientid, recordlocator, last name, first name and email. I have removed this from my function so when the csv generates it will not add these rows which is what I expect for my tests to pass.
Then in my test-spec.js folder I have to test 4 invalid columns that generates the file, and validate if clientID is not there then show me 422 error, but I need to generate this for the other 3 missing columns, how can I manipulate my Data-generation.js folder to generate these scenarios?
Below Test.spec.js
describe.only("Create Upload without ClientID, recordlocator,lastName,First name and Email Columns ", function (){
it("Should throw unprocessable Entity Repoonse 422", async function (){
getCreateUploadsRequestForInvalidColumnsTMCBulkUpload(clientId, clientOrg.id);
response = await createBulkUploadsTMC({
fileName: fileDestination,
token: userAccessToken,
delimiter: "COMMA",
quote: "DOUBLE_QUOTE",
dataResidency: "US",
});
expect(response.status).to.eql(422);
});
})
})
});
Below Data-generation.js folder where my csv gets generated with these columns and rows.
clientId,
organizationId
) {
const data = [];
const originAirport = "YUL";
const destinationAirport = "YYR";
const originRail = "TPA";
const destinationRail = "WAS";
const flightNumber = faker.airline.flightNumber();
const phoneNumber = faker.phone.number("+1878540####");
const employeeId = faker.string.numeric(5);
// generate date
const currentDate = moment();
const departureDateTime = currentDate.format("YYYY-MM-DDTHH:mm");
const arrivalDateTime = currentDate.add(2, "days").format("YYYY-MM-DDTHH:mm");
const hotelName = faker.person.lastName();
for (let i = 1; i < 6; i++) {
let rowDetails;
switch (i) {
case 1:
rowDetails = [
`Organization,Phone Number,Employee ID,Person Type,Flight Origin,Flight Origin Date,Flight Destination,Flight Destination Date,Airline Code,Flight Number,Hotel Nearest Airport,Hotel Check-in Date,Hotel Check-out Date,Hotel Name,Hotel Address,Hotel Latitude,Hotel Longitude,Vehicle Origin,Vehicle Origin Date,Vehicle Destination,Vehicle Destination Date,Vehicle Company Name,Rail Origin,Rail Origin Date,Rail Destination,Rail Destination Date,Rail Carrier Code,Train Number,Action`,
];
break;
case 2:
rowDetails = [
organizationId,
phoneNumber,
employeeId,
"VIP",
originAirport,
departureDateTime,
destinationAirport,
arrivalDateTime,
"YUL",
flightNumber,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Create",
];
break;
case 3:
rowDetails = [
organizationId,
phoneNumber,
employeeId,
"VIP",
"",
"",
"",
"",
"",
"",
originAirport,
departureDateTime,
arrivalDateTime,
hotelName,
"",
"48.78",
"-78.88",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Create",
];
break;
case 4:
rowDetails = [
organizationId,
phoneNumber,
employeeId,
"VIP",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
originAirport,
departureDateTime,
destinationAirport,
arrivalDateTime,
"HERTZ",
"",
"",
"",
"",
"",
"",
"Create",
];
break;
case 5:
rowDetails = [
organizationId,
phoneNumber,
employeeId,
"VIP",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
originRail,
departureDateTime,
destinationRail,
arrivalDateTime,
"2V",
"92",
"Create",
];
break;
}
const row = [...rowDetails];
data.push(row);
}
// Convert data to CSV format
const csvContent = data.map((row) => row.join(",")).join("n");
// Specify the file path and name
const fileNameCSV = "tmc_upload.csv";
const fileDestination = path.join(
__dirname + `/../../../../../testData/testFiles/${fileNameCSV}`
);
// Write the CSV content to the file
fs.writeFileSync(fileDestination, csvContent, "utf-8");
console.log(`CSV file "${fileNameCSV}" created successfully.`);
return fileDestination
}```