How do I add the api response in the below tests. So I am trying to validate 4 columns. I got the test to pass and it validates that we should get a 422 Reponses as those columns are missing that is correct.
I now want to add the actual the error message received from the api. I need to use a expect and realized the assert wont work as I need to use chai assertions.
I has the same code response 422 but we have different messages for these 4 responses.
- required column not provided: Client ID *
- required column not provided: Record Locator *
- required column not provided: First Name *
- required column not provided: Last Name *’
this is code I tried. The console.log gives me the error messages but I want better way to represent that. Please help.
<code> describe.only("Verify that invalid columns is required must fail validation*", function () {
[
"Client ID *",
"Record Locator *",
"First Name *",
"Last Name *",
"Email *",
].forEach((column) => {
it(`Should return 422 for column=${column}`, async function () {
getCreateUploadsRequestForTMCBulkUpload((clientId, clientOrg.id));
const fileRead = fs.readFileSync(fileDestination, "utf-8");
const invalidContent = fileRead.toString().replace(column, "");
fs.writeFileSync(fileDestination, invalidContent, "utf-8");
response = await createBulkUploadsTMC({
fileName: fileDestination,
token: userAccessToken,
delimiter: "COMMA",
quote: "DOUBLE_QUOTE",
dataResidency: "US",
});
expect(response.status).to.eql(422);
assert.fail(['required column not provided: Record Locator *']) // this is wrong
console.log(response.body)
});
});
});
});
</code>
<code> describe.only("Verify that invalid columns is required must fail validation*", function () {
[
"Client ID *",
"Record Locator *",
"First Name *",
"Last Name *",
"Email *",
].forEach((column) => {
it(`Should return 422 for column=${column}`, async function () {
getCreateUploadsRequestForTMCBulkUpload((clientId, clientOrg.id));
const fileRead = fs.readFileSync(fileDestination, "utf-8");
const invalidContent = fileRead.toString().replace(column, "");
fs.writeFileSync(fileDestination, invalidContent, "utf-8");
response = await createBulkUploadsTMC({
fileName: fileDestination,
token: userAccessToken,
delimiter: "COMMA",
quote: "DOUBLE_QUOTE",
dataResidency: "US",
});
expect(response.status).to.eql(422);
assert.fail(['required column not provided: Record Locator *']) // this is wrong
console.log(response.body)
});
});
});
});
</code>
describe.only("Verify that invalid columns is required must fail validation*", function () {
[
"Client ID *",
"Record Locator *",
"First Name *",
"Last Name *",
"Email *",
].forEach((column) => {
it(`Should return 422 for column=${column}`, async function () {
getCreateUploadsRequestForTMCBulkUpload((clientId, clientOrg.id));
const fileRead = fs.readFileSync(fileDestination, "utf-8");
const invalidContent = fileRead.toString().replace(column, "");
fs.writeFileSync(fileDestination, invalidContent, "utf-8");
response = await createBulkUploadsTMC({
fileName: fileDestination,
token: userAccessToken,
delimiter: "COMMA",
quote: "DOUBLE_QUOTE",
dataResidency: "US",
});
expect(response.status).to.eql(422);
assert.fail(['required column not provided: Record Locator *']) // this is wrong
console.log(response.body)
});
});
});
});
1