Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackathon: msal-common - Replaced sinon with jest #7322

Closed
wants to merge 5 commits into from
Closed
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
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "replaced sinon with jest",
"packageName": "@azure/msal-common",
"email": "rginsburg@microsoft.com",
"dependentChangeType": "none"
}
2 changes: 0 additions & 2 deletions lib/msal-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"@types/jest": "^29.5.0",
"@types/lodash": "^4.14.182",
"@types/node": "^20.3.1",
"@types/sinon": "^7.5.0",
"eslint-config-msal": "file:../../shared-configs/eslint-config-msal",
"jest": "^29.5.0",
"lodash": "^4.17.21",
Expand All @@ -117,7 +116,6 @@
"rollup": "^3.29.5",
"rollup-msal": "file:../../shared-configs/rollup-msal",
"shx": "^0.3.2",
"sinon": "^7.5.0",
"ts-jest": "^29.1.0",
"ts-jest-resolver": "^2.0.1",
"ts-node": "^10.9.1",
Expand Down
20 changes: 10 additions & 10 deletions lib/msal-common/test/account/AuthToken.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,37 +168,37 @@ describe("AuthToken.ts Class Unit Tests", () => {
it("Throws error if rawIdToken is null or empty", () => {
expect(() =>
AuthToken.extractTokenClaims("", cryptoInterface.base64Decode)
).toThrowError(ClientAuthErrorMessage.nullOrEmptyToken.desc);
).toThrow(ClientAuthErrorMessage.nullOrEmptyToken.desc);
expect(() =>
AuthToken.extractTokenClaims("", cryptoInterface.base64Decode)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);

expect(() =>
// @ts-ignore
AuthToken.extractTokenClaims(null, cryptoInterface)
).toThrowError(ClientAuthErrorMessage.nullOrEmptyToken.desc);
).toThrow(ClientAuthErrorMessage.nullOrEmptyToken.desc);
expect(() =>
// @ts-ignore
AuthToken.extractTokenClaims(null, cryptoInterface)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);
});

it("Throws error if idToken is null or empty", () => {
expect(() =>
AuthToken.extractTokenClaims("", cryptoInterface.base64Decode)
).toThrowError(ClientAuthErrorMessage.nullOrEmptyToken.desc);
).toThrow(ClientAuthErrorMessage.nullOrEmptyToken.desc);
expect(() =>
AuthToken.extractTokenClaims("", cryptoInterface.base64Decode)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);

expect(() =>
// @ts-ignore
AuthToken.extractTokenClaims(null, cryptoInterface)
).toThrowError(ClientAuthErrorMessage.nullOrEmptyToken.desc);
).toThrow(ClientAuthErrorMessage.nullOrEmptyToken.desc);
expect(() =>
// @ts-ignore
AuthToken.extractTokenClaims(null, cryptoInterface)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);
});

it("Throws error if payload cannot be parsed", () => {
Expand All @@ -207,13 +207,13 @@ describe("AuthToken.ts Class Unit Tests", () => {
"not-a-real-token",
cryptoInterface.base64Decode
)
).toThrowError(ClientAuthErrorMessage.tokenParsingError.desc);
).toThrow(ClientAuthErrorMessage.tokenParsingError.desc);
expect(() =>
AuthToken.extractTokenClaims(
"not-a-real-token",
cryptoInterface.base64Decode
)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);
});

it("Successfully extracts the idTokenClaims from the decodedJwt", () => {
Expand Down
16 changes: 8 additions & 8 deletions lib/msal-common/test/account/ClientInfo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ describe("ClientInfo.ts Class Unit Tests", () => {

it("Throws error if clientInfo is null or empty", () => {
// @ts-ignore
expect(() => buildClientInfo(null, cryptoInterface)).toThrowError(
expect(() => buildClientInfo(null, cryptoInterface)).toThrow(
ClientAuthErrorMessage.clientInfoEmptyError.desc
);
// @ts-ignore
expect(() => buildClientInfo(null, cryptoInterface)).toThrowError(
expect(() => buildClientInfo(null, cryptoInterface)).toThrow(
ClientAuthError
);

expect(() =>
buildClientInfo("", cryptoInterface.base64Decode)
).toThrowError(ClientAuthErrorMessage.clientInfoEmptyError.desc);
).toThrow(ClientAuthErrorMessage.clientInfoEmptyError.desc);
expect(() =>
buildClientInfo("", cryptoInterface.base64Decode)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);
});

it("Throws error if function could not successfully decode ", () => {
Expand All @@ -110,13 +110,13 @@ describe("ClientInfo.ts Class Unit Tests", () => {
"ThisCan'tbeParsed",
cryptoInterface.base64Decode
)
).toThrowError(ClientAuthErrorMessage.clientInfoDecodingError.desc);
).toThrow(ClientAuthErrorMessage.clientInfoDecodingError.desc);
expect(() =>
buildClientInfo(
"ThisCan'tbeParsed",
cryptoInterface.base64Decode
)
).toThrowError(ClientAuthError);
).toThrow(ClientAuthError);
});

it("Succesfully returns decoded client info", () => {
Expand All @@ -132,10 +132,10 @@ describe("ClientInfo.ts Class Unit Tests", () => {

describe("buildClientInfoFromHomeAccountId", () => {
it("throws error if homeAccountId is not in the correct format", () => {
expect(() => buildClientInfoFromHomeAccountId("")).toThrowError(
expect(() => buildClientInfoFromHomeAccountId("")).toThrow(
ClientAuthError
);
expect(() => buildClientInfoFromHomeAccountId("")).toThrowError(
expect(() => buildClientInfoFromHomeAccountId("")).toThrow(
createClientAuthError(
ClientAuthErrorCodes.clientInfoDecodingError
)
Expand Down
28 changes: 14 additions & 14 deletions lib/msal-common/test/authority/Authority.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("Authority.ts Class Unit Tests", () => {
logger,
TEST_CONFIG.CORRELATION_ID
)
).toThrowError(
).toThrow(
ClientConfigurationErrorMessage.authorityUriInsecure.desc
);
expect(
Expand All @@ -166,7 +166,7 @@ describe("Authority.ts Class Unit Tests", () => {
logger,
TEST_CONFIG.CORRELATION_ID
)
).toThrowError(ClientConfigurationErrorMessage.urlParseError.desc);
).toThrow(ClientConfigurationErrorMessage.urlParseError.desc);
expect(
() =>
new Authority(
Expand All @@ -177,7 +177,7 @@ describe("Authority.ts Class Unit Tests", () => {
logger,
TEST_CONFIG.CORRELATION_ID
)
).toThrowError(ClientConfigurationErrorMessage.urlEmptyError.desc);
).toThrow(ClientConfigurationErrorMessage.urlEmptyError.desc);
});
});

Expand Down Expand Up @@ -222,17 +222,17 @@ describe("Authority.ts Class Unit Tests", () => {
() =>
(authority.canonicalAuthority =
"http://login.microsoftonline.com/common")
).toThrowError(
).toThrow(
ClientConfigurationErrorMessage.authorityUriInsecure.desc
);
expect(
() =>
(authority.canonicalAuthority =
"https://login.microsoftonline.com/")
).not.toThrowError();
).not.toThrow();
expect(
() => (authority.canonicalAuthority = "This is not a URI")
).toThrowError(ClientConfigurationErrorMessage.urlParseError.desc);
).toThrow(ClientConfigurationErrorMessage.urlParseError.desc);

authority.canonicalAuthority = `${TEST_URIS.ALTERNATE_INSTANCE}/${RANDOM_TEST_GUID}`;
expect(authority.canonicalAuthority.endsWith("/")).toBe(true);
Expand Down Expand Up @@ -336,32 +336,32 @@ describe("Authority.ts Class Unit Tests", () => {
logger,
TEST_CONFIG.CORRELATION_ID
);
expect(() => authority.authorizationEndpoint).toThrowError(
expect(() => authority.authorizationEndpoint).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
);
expect(() => authority.tokenEndpoint).toThrowError(
expect(() => authority.tokenEndpoint).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
);
expect(() => authority.endSessionEndpoint).toThrowError(
expect(() => authority.endSessionEndpoint).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
);
expect(() => authority.deviceCodeEndpoint).toThrowError(
expect(() => authority.deviceCodeEndpoint).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
);
expect(() => authority.selfSignedJwtAudience).toThrowError(
expect(() => authority.selfSignedJwtAudience).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
);
expect(() => authority.jwksUri).toThrowError(
expect(() => authority.jwksUri).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
Expand Down Expand Up @@ -1112,7 +1112,7 @@ describe("Authority.ts Class Unit Tests", () => {
);
await authority.resolveEndpointsAsync();

expect(() => authority.endSessionEndpoint).toThrowError(
expect(() => authority.endSessionEndpoint).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endSessionEndpointNotSupported
)
Expand Down Expand Up @@ -2597,7 +2597,7 @@ describe("Authority.ts Class Unit Tests", () => {
});

it("getPreferredCache throws error if discovery is not complete", () => {
expect(() => authority.getPreferredCache()).toThrowError(
expect(() => authority.getPreferredCache()).toThrow(
createClientAuthError(
ClientAuthErrorCodes.endpointResolutionError
)
Expand Down
Loading
Loading