Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a201222
Improve test coverage to ~100% for @azure/core-lro
Apr 16, 2026
8109455
Remove 'coverage' from test describe block names
Apr 17, 2026
0b796b1
Remove 'edge cases' from describe block names
Apr 17, 2026
5350c62
Strengthen isDefined-only assertions with value checks
Apr 17, 2026
57b9c74
Move imports to top level (vitest hoists vi.mock automatically)
Apr 17, 2026
e8ac8ea
Fix TypeScript compilation errors caught by CI
Apr 17, 2026
61c046d
Move public-API poller tests from internal to public
Apr 17, 2026
3876c44
Extract makeRawResponse and makeState to shared test utils
Apr 17, 2026
42ed16b
Move createTestPoller tests from internal to public (core-lro)
Apr 17, 2026
392aa23
Clean up imports: combine duplicates, prefer src/index.js (core-lro)
Apr 17, 2026
f88d5b7
Rename internal test files for clarity (core-lro)
Apr 17, 2026
74d290e
Remove old test files after rename
Apr 17, 2026
1207617
Remove unnecessary comments from test files (core-lro)
Apr 17, 2026
351d245
Merge poller.spec.ts into lro.spec.ts (core-lro)
Apr 17, 2026
141baa3
Delete poller.spec.ts (merged into lro.spec.ts)
Apr 17, 2026
8c5d303
Address PR review feedback: fix test names and retry-after value
Apr 17, 2026
d122244
test(core-client-rest): remove redundant strictEqual assertions in cl…
Apr 17, 2026
dea4797
Fix test substance issues in core-client
Apr 17, 2026
95b24b6
fix(core-lro): strengthen test assertions for polling interval, custo…
Apr 17, 2026
c36a532
Merge remote-tracking branch 'origin/main' into deyaaeldeen/core-lro-…
Apr 18, 2026
a4e5372
fix: merge main and remove dead getCachedDefaultHttpsClient test
Apr 18, 2026
d41f580
fix: address audit issues in core-lro tests
Apr 18, 2026
5f50252
fix: use isAtLeast in tokenCycler test
Apr 18, 2026
6170eb9
fix: use assert.strictEqual instead of assert.isTrue(x === y) in lro …
Apr 18, 2026
f604f87
fix: strengthen isDefined to assert actual value in lro state tests
Apr 18, 2026
7d87337
refactor: replace non-null assertions with optional chaining in lro t…
Apr 19, 2026
305485e
refactor: modernize spy patterns in core-lro tests
Apr 19, 2026
42879ea
refactor: second pass modernization in core-lro tests
Apr 19, 2026
086c2ec
fix: resolve TS2339 on operationState?.status in lro tests
Apr 19, 2026
96318e3
refactor: third pass modernization in core-lro tests
Apr 19, 2026
fe10246
fix: remove foreign package files from core-lro branch
Apr 19, 2026
d9dceb3
Eliminate unnecessary type casts in core-lro tests
Apr 20, 2026
61ae359
fix: align test title with actual assertion in http-operation.spec.ts
Apr 21, 2026
ed389cd
Address PR feedback: fix test titles, strengthen assertions, add miss…
Apr 21, 2026
fb7e547
Remove stale temp file
Apr 21, 2026
a42c3c6
Add idempotency comment on duplicate poll assertion
Apr 21, 2026
62bd399
Add idempotency comment on canceled poll assertion
Apr 21, 2026
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
132 changes: 132 additions & 0 deletions sdk/core/core-lro/test/internal/buildCreatePoller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { describe, it, assert, vi } from "vitest";
import { buildCreatePoller } from "../../src/poller/poller.js";
import { getOperationStatus, getOperationLocation } from "../../src/http/operation.js";
import type { OperationResponse, OperationState } from "../../src/index.js";
import { makeRawResponse, makeState } from "../utils/utils.js";

describe("getProvisioningState via Body mode", () => {
it("reads provisioningState from top-level body property", () => {
const response: OperationResponse = {
rawResponse: makeRawResponse({
body: { provisioningState: "Succeeded" },
}),
flatResponse: {},
};
const state = makeState("Body");
const status = getOperationStatus(response, state);
assert.equal(status, "succeeded");
});
});

describe("getOperationLocation for ResourceLocation mode", () => {
it("returns location header for ResourceLocation mode", () => {
const response: OperationResponse = {
rawResponse: makeRawResponse({
headers: { location: "https://example.com/location" },
}),
flatResponse: {},
};
const state = makeState("ResourceLocation");
const loc = getOperationLocation(response, state);
assert.equal(loc, "https://example.com/location");
});
});

describe("getOperationStatus for ResourceLocation mode", () => {
it("uses status code for ResourceLocation mode", () => {
const response: OperationResponse = {
rawResponse: makeRawResponse({ statusCode: 202 }),
flatResponse: {},
};
const state = makeState("ResourceLocation");
assert.equal(getOperationStatus(response, state), "running");
});

it("returns succeeded for status 200 in ResourceLocation mode", () => {
const response: OperationResponse = {
rawResponse: makeRawResponse({ statusCode: 200 }),
flatResponse: {},
};
const state = makeState("ResourceLocation");
assert.equal(getOperationStatus(response, state), "succeeded");
});

it("returns failed for status >= 300 in ResourceLocation mode", () => {
const response: OperationResponse = {
rawResponse: makeRawResponse({ statusCode: 500 }),
flatResponse: {},
};
const state = makeState("ResourceLocation");
assert.equal(getOperationStatus(response, state), "failed");
});
});

describe("buildCreatePoller", () => {
it("completes polling when getPollingInterval is provided", async () => {
let pollCount = 0;
const getPollingInterval = vi.fn().mockReturnValue(42);
const createPoller = buildCreatePoller<any, any, OperationState<any>>({
getStatusFromInitialResponse: () => "running",
getStatusFromPollResponse: () => {
pollCount++;
return pollCount >= 2 ? "succeeded" : "running";
},
isOperationError: () => false,
getResourceLocation: () => undefined,
getPollingInterval,
resolveOnUnsuccessful: false,
});

const poller = createPoller(
{
init: async () => ({
response: { data: "init" },
operationLocation: "/poll",
}),
poll: async () => ({ data: "polled" }),
},
{ intervalInMs: 0 },
);

await poller.submitted();
const state = await poller.poll();
assert.equal(state.status, "running");
const finalState = await poller.poll();
assert.equal(finalState.status, "succeeded");
assert.isAbove(
getPollingInterval.mock.calls.length,
0,
"getPollingInterval should have been called",
);
});

it("returns a state object when polling", async () => {
const createPoller = buildCreatePoller<any, any, OperationState<any>>({
getStatusFromInitialResponse: () => "running",
getStatusFromPollResponse: () => "running",
isOperationError: () => false,
getResourceLocation: () => undefined,
resolveOnUnsuccessful: false,
});

const poller = createPoller(
{
init: async () => {
return {
response: { data: "init" },
operationLocation: "/poll",
};
},
poll: async () => ({ data: "polled" }),
},
{ intervalInMs: 0 },
);

await poller.submitted();
const state = await poller.poll();
assert.property(state, "status");
});
});
Loading