Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ describe("DocumentIntelligenceClient", () => {

const pages = analyzeResult?.pages;
const tables = analyzeResult?.tables;
assert.ok(pages && pages.length > 0, `Expected non-empty pages but got ${pages}`);
assert.isNotEmpty(pages);
assert.isNotEmpty(tables);

const [table] = tables!;
assert.ok(table.boundingRegions?.[0]);
assert.isDefined(table.boundingRegions?.[0]);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand Down Expand Up @@ -115,12 +114,9 @@ describe("DocumentIntelligenceClient", () => {
const pages = analyzeResult?.pages;
const paragraphs = analyzeResult?.paragraphs;

assert.ok(
paragraphs && paragraphs.length > 0,
`Expected non-empty paragraphs but got ${paragraphs}.`,
);
assert.isNotEmpty(paragraphs);

assert.ok(pages && pages.length > 0, `Expect no-empty pages but got ${pages}`);
assert.isNotEmpty(pages);
});

it("jpeg file stream", async () => {
Expand Down Expand Up @@ -152,7 +148,7 @@ describe("DocumentIntelligenceClient", () => {
assert.isNotEmpty(pages);
assert.isNotEmpty(tables);
const [table] = tables as DocumentTableOutput[];
assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand Down Expand Up @@ -184,7 +180,7 @@ describe("DocumentIntelligenceClient", () => {
assert.isNotEmpty(pages);
assert.isNotEmpty(tables);
const [table] = tables as DocumentTableOutput[];
assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand Down Expand Up @@ -217,7 +213,7 @@ describe("DocumentIntelligenceClient", () => {
assert.isNotEmpty(pages);
assert.isNotEmpty(tables);
const [table] = tables as DocumentTableOutput[];
assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand Down Expand Up @@ -248,7 +244,7 @@ describe("DocumentIntelligenceClient", () => {

assert.isNotEmpty(tables);
const [table] = tables as DocumentTableOutput[];
assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand Down Expand Up @@ -296,7 +292,7 @@ describe("DocumentIntelligenceClient", () => {
await getLongRunningPoller(client, initialResponse, { ...testPollingOptions });
assert.fail("Expected an exception due to invalid locale.");
} catch (ex: any) {
assert.ok((ex as Error).message.includes("Invalid argument."));
assert.include((ex as Error).message, "Invalid argument.");
}
});

Expand Down Expand Up @@ -464,7 +460,7 @@ describe("DocumentIntelligenceClient", () => {
throw response.body.error;
}
_model = response.body as DocumentModelDetailsOutput;
assert.ok(_model.modelId);
assert.isDefined(_model.modelId);
}

return _model;
Expand Down Expand Up @@ -497,14 +493,14 @@ describe("DocumentIntelligenceClient", () => {

const documents = analyzeResult?.documents;
const pages = analyzeResult?.pages;
assert.ok(documents);
assert.isDefined(documents);
assert.equal(documents?.[0].docType, `${modelName}:${modelName}`);
assert.ok(pages?.[0]);
assert.isDefined(pages?.[0]);

/* There should be a table in the response, but it isn't recognized (maybe because it's too small or sparse)
assert.isNotEmpty(tables);
const [table] = tables!;
assert.ok(table.boundingRegions?.[0].boundingBox);
assert.isDefined(table.boundingRegions?.[0].boundingBox);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);*/

assert.equal(pages?.[0].pageNumber, 1);
Expand Down Expand Up @@ -663,7 +659,7 @@ describe("DocumentIntelligenceClient", () => {

assert.fail("Expected an exception due to invalid locale.");
} catch (ex: any) {
assert.ok((ex as Error).message.includes("Invalid argument."));
assert.include((ex as Error).message, "Invalid argument.");
}
});
});
Expand Down Expand Up @@ -699,7 +695,7 @@ describe("DocumentIntelligenceClient", () => {
assert.isNotEmpty(pages);
assert.isNotEmpty(tables);
const [table] = tables!;
assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand Down Expand Up @@ -731,7 +727,7 @@ describe("DocumentIntelligenceClient", () => {
assert.isNotEmpty(pages);
assert.isNotEmpty(tables);
const [table] = tables!;
assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);
});

Expand All @@ -755,7 +751,7 @@ describe("DocumentIntelligenceClient", () => {

assert.fail("Expected an exception due to invalid locale.");
} catch (ex: any) {
assert.ok((ex as Error).message.includes("Invalid argument."));
assert.include((ex as Error).message, "Invalid argument.");
}
});
});
Expand Down Expand Up @@ -936,7 +932,7 @@ describe("DocumentIntelligenceClient", () => {
if (isUnexpected(response)) {
throw response.body.error;
}
assert.ok(response.body);
assert.isDefined(response.body);
assert.equal(response.body.resultId, batchResultId);
assert.equal(response.body.status, "succeeded");
assert.equal(response.body.percentCompleted, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ describe("classifiers", () => {

// Additionally check that the pages aren't empty and that there are some common fields set
assert.isNotEmpty(analyzeResult?.pages);
assert.ok(analyzeResult?.pages![0].pageNumber);
assert.isDefined(analyzeResult?.pages![0].pageNumber);
assert.isDefined(analyzeResult?.pages![0].angle);
Comment on lines +65 to 66
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion assert.isDefined(analyzeResult?.pages![0].angle) at line 66 is inconsistent with lines 67-69 and may be incorrect. Line 66 already used assert.isDefined for the angle property in the original code, so no change was needed. However, lines 65, 67, 68, and 69 changed from assert.ok to assert.isDefined. This inconsistency suggests that line 66 should have been left unchanged or the pattern is inconsistent with the PR's stated purpose of replacing assert.ok with more specific assertions.

Copilot uses AI. Check for mistakes.
assert.ok(analyzeResult?.pages![0].height);
assert.ok(analyzeResult?.pages![0].width);
assert.ok(analyzeResult?.pages![0].unit);
assert.isDefined(analyzeResult?.pages![0].height);
assert.isDefined(analyzeResult?.pages![0].width);
assert.isDefined(analyzeResult?.pages![0].unit);
});

it("analyze from PNG file URL", async () => {
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("classifiers", () => {
await client.path("/documentClassifiers/{classifierId}", classifierId).get();
assert.fail("Expected error while accessing a deleted classifier");
} catch (error: any) {
assert.ok(error);
assert.isDefined(error);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ describe("model management", () => {
it("validate model training response", async () => {
const model = await requireModel();

assert.ok(model, "Expecting valid response");
assert.ok(model.modelId);
assert.isDefined(model);
assert.isDefined(model.modelId);

assert.isNotEmpty(model.docTypes);
const submodel = model.docTypes![model.modelId];

// When training with labels, we will have expectations for the names
assert.ok(
submodel.fieldSchema!["Signature"],
"Expecting field with name 'Signature' to be valid",
);
assert.isDefined(submodel.fieldSchema!["Signature"]);
});

/*
Expand Down Expand Up @@ -145,15 +142,15 @@ describe("model management", () => {
assert.isNotEmpty(tables);
const [table] = tables!;

assert.ok(table.boundingRegions?.[0].polygon);
assert.isDefined(table.boundingRegions?.[0].polygon);
assert.equal(table.boundingRegions?.[0].pageNumber, 1);

assert.ok(document?.fields);
assert.ok(document?.fields?.["Merchant"]);
assert.ok(document?.fields?.["DatedAs"]);
assert.ok(document?.fields?.["CompanyPhoneNumber"]);
assert.ok(document?.fields?.["CompanyName"]);
assert.ok(document?.fields?.["Signature"]);
assert.isDefined(document?.fields);
assert.isDefined(document?.fields?.["Merchant"]);
assert.isDefined(document?.fields?.["DatedAs"]);
assert.isDefined(document?.fields?.["CompanyPhoneNumber"]);
assert.isDefined(document?.fields?.["CompanyName"]);
assert.isDefined(document?.fields?.["Signature"]);
});
});

Expand All @@ -168,7 +165,7 @@ describe("model management", () => {

assert.strictEqual(modelDetails.body.modelId, model.modelId);
assert.strictEqual(modelDetails.body.description, model.description);
assert.ok(modelDetails.body.docTypes);
assert.isDefined(modelDetails.body.docTypes);
});
});

Expand All @@ -185,7 +182,7 @@ describe("model management", () => {

const modelsInAccount: string[] = [];
for await (const model of paginate(client, response)) {
assert.ok(model.modelId);
assert.isDefined(model.modelId);
modelsInAccount.push(model.modelId);
}

Expand Down Expand Up @@ -273,9 +270,9 @@ describe("model management", () => {
const response = await getLongRunningPoller(client, initialResponse);

const composedModel = response.body as DocumentModelDetailsOutput;
assert.ok(composedModel.modelId);
assert.isDefined(composedModel.modelId);
assert.equal(composedModel.modelId, modelId);
assert.ok(composedModel.docTypes);
assert.isDefined(composedModel.docTypes);

// Submodels
assert.equal(Object.entries(composedModel.docTypes ?? {}).length, 2);
Expand Down Expand Up @@ -323,10 +320,10 @@ describe("model management", () => {
const copyResponse = await getLongRunningPoller(client, copyInitResponse);
const copyResult = copyResponse.body as DocumentModelDetailsOutput;

assert.ok(copyResult, "Expecting valid copy result");
assert.isDefined(copyResult);
assert.equal(copyResult.modelId, targetAuth.body.targetModelId);

assert.ok(copyResult.createdDateTime, "Expecting valid 'trainingStartedOn' property");
assert.isDefined(copyResult.createdDateTime);

const targetModel = await client.path("/documentModels/{modelId}", copyResult.modelId).get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ describe("analysis (browser)", { timeout: 60000 }, () => {
);
const { documents: receipts } = await poller.pollUntilDone();

assert.ok(
receipts && receipts.length > 0,
`Expected at least one receipt, but got ${receipts}`,
);
assert.isNotEmpty(receipts);
const receipt = receipts![0];
assert.equal(receipt.docType, "receipt.retailMeal");
});
Expand Down
Loading
Loading