Skip to content

Commit 4678e48

Browse files
Tidy up Authorization error tests (#24404)
## Description Ensure these tests would fail if error was not thrown, make a bit more concise. Cleanup done while working on #24405
1 parent 79a9fa2 commit 4678e48

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

packages/drivers/odsp-driver/src/test/odspError.spec.ts

+31-34
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import {
1010
IAuthorizationError,
1111
IGenericNetworkError,
1212
} from "@fluidframework/driver-definitions/internal";
13-
import {
14-
type AuthorizationError,
15-
NonRetryableError,
16-
} from "@fluidframework/driver-utils/internal";
13+
import { NonRetryableError } from "@fluidframework/driver-utils/internal";
1714
import {
1815
createOdspNetworkError,
1916
throwOdspNetworkError,
@@ -272,19 +269,21 @@ describe("Odsp Error", () => {
272269
throwOdspNetworkError(errorMessage, 401, testResponseWithInsufficientClaims);
273270
}
274271

275-
it("Authorization error with insufficient claims first-class properties", async () => {
276-
try {
277-
throwAuthorizationErrorWithInsufficientClaims("TestMessage");
278-
} catch (error: unknown) {
279-
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
280-
assert(error.message.includes("TestMessage"), "message should contain original message");
281-
assert.equal((error as AuthorizationError).canRetry, false, "canRetry should be false");
282-
assert.equal(
283-
(error as AuthorizationError).claims,
284-
'{"access_token":{"nbf":{"essential":true, "value":"1597959090"}}}',
285-
"claims should be extracted from response",
286-
);
287-
}
272+
it("Authorization error with insufficient claims first-class properties", () => {
273+
assert.throws(
274+
() => throwAuthorizationErrorWithInsufficientClaims("TestMessage"),
275+
(error) => {
276+
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
277+
assert.match(error.message, /TestMessage/, "message should contain original message");
278+
assert.equal(error.canRetry, false, "canRetry should be false");
279+
assert.equal(
280+
error.claims,
281+
'{"access_token":{"nbf":{"essential":true, "value":"1597959090"}}}',
282+
"claims should be extracted from response",
283+
);
284+
return true;
285+
},
286+
);
288287
});
289288

290289
it("Authorization error with insufficient claims results in retry with claims passed in options", async () => {
@@ -322,23 +321,21 @@ describe("Odsp Error", () => {
322321
throwOdspNetworkError(errorMessage, 401, testResponseWithRealm);
323322
}
324323

325-
it("Authorization error with realm first-class properties", async () => {
326-
try {
327-
throwAuthorizationErrorWithRealm("TestMessage");
328-
} catch (error: unknown) {
329-
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
330-
assert(error.message.includes("TestMessage"), "message should contain original message");
331-
assert.strictEqual(
332-
(error as AuthorizationError).canRetry,
333-
false,
334-
"canRetry should be false",
335-
);
336-
assert.strictEqual(
337-
(error as AuthorizationError).tenantId,
338-
"6c482541-f706-4168-9e58-8e35a9992f58",
339-
"realm should be extracted from response",
340-
);
341-
}
324+
it("Authorization error with realm first-class properties", () => {
325+
assert.throws(
326+
() => throwAuthorizationErrorWithRealm("TestMessage"),
327+
(error) => {
328+
assert(isIAuthorizationError(error), "error should be a IAuthorizationError");
329+
assert.match(error.message, /TestMessage/, "message should contain original message");
330+
assert.equal(error.canRetry, false, "canRetry should be false");
331+
assert.equal(
332+
error.tenantId,
333+
"6c482541-f706-4168-9e58-8e35a9992f58",
334+
"realm should be extracted from response",
335+
);
336+
return true;
337+
},
338+
);
342339
});
343340

344341
it("Authorization error with realm results in retry and realm passed as tenant id", async () => {

0 commit comments

Comments
 (0)