Skip to content

Commit 36a0037

Browse files
committed
test: fix unit tests
1 parent 8bee88d commit 36a0037

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

packages/credential-provider-ini/src/fromIni.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe(fromIni.name, () => {
1212
const mockMasterProfileName = "mockMasterProfileName";
1313
const mockProfileName = "mockProfileName";
1414
const mockInit = { profile: mockProfileName };
15+
const mockInitWithParentClientConfig = { profile: mockProfileName, parentClientConfig: {} };
1516
const mockProfiles = { [mockProfileName]: { key: "value" } };
1617

1718
beforeEach(() => {
@@ -32,7 +33,7 @@ describe(fromIni.name, () => {
3233
} catch (error) {
3334
expect(error).toStrictEqual(expectedError);
3435
}
35-
expect(parseKnownFiles).toHaveBeenCalledWith(mockInit);
36+
expect(parseKnownFiles).toHaveBeenCalledWith(mockInitWithParentClientConfig);
3637
expect(getProfileName).not.toHaveBeenCalled();
3738
expect(resolveProfileData).not.toHaveBeenCalled();
3839
});
@@ -46,9 +47,13 @@ describe(fromIni.name, () => {
4647
} catch (error) {
4748
expect(error).toStrictEqual(expectedError);
4849
}
49-
expect(parseKnownFiles).toHaveBeenCalledWith(mockInit);
50+
expect(parseKnownFiles).toHaveBeenCalledWith(mockInitWithParentClientConfig);
5051
expect(getProfileName).toHaveBeenCalledWith(mockInit);
51-
expect(resolveProfileData).toHaveBeenCalledWith(mockMasterProfileName, mockProfiles, mockInit);
52+
expect(resolveProfileData).toHaveBeenCalledWith(
53+
mockMasterProfileName,
54+
mockProfiles,
55+
mockInitWithParentClientConfig
56+
);
5257
});
5358

5459
it("returns resolved process creds", async () => {
@@ -59,8 +64,12 @@ describe(fromIni.name, () => {
5964
vi.mocked(resolveProfileData).mockResolvedValue(expectedCreds);
6065
const receivedCreds = await fromIni(mockInit)();
6166
expect(receivedCreds).toStrictEqual(expectedCreds);
62-
expect(parseKnownFiles).toHaveBeenCalledWith(mockInit);
67+
expect(parseKnownFiles).toHaveBeenCalledWith(mockInitWithParentClientConfig);
6368
expect(getProfileName).toHaveBeenCalledWith(mockInit);
64-
expect(resolveProfileData).toHaveBeenCalledWith(mockMasterProfileName, mockProfiles, mockInit);
69+
expect(resolveProfileData).toHaveBeenCalledWith(
70+
mockMasterProfileName,
71+
mockProfiles,
72+
mockInitWithParentClientConfig
73+
);
6574
});
6675
});

packages/token-providers/src/fromSso.spec.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe(fromSso.name, () => {
3434

3535
const mockProfileName = "mockProfileName";
3636
const mockInit = { profile: mockProfileName };
37+
const mockInitWithParentClientConfig = { profile: mockProfileName, parentClientConfig: {} };
3738
const mockProfiles = { [mockProfileName]: mockSsoProfile };
3839

3940
const mockSsoToken = {
@@ -68,7 +69,7 @@ describe(fromSso.name, () => {
6869
});
6970

7071
afterEach(() => {
71-
expect(parseKnownFiles).toHaveBeenCalledWith(mockInit);
72+
expect(parseKnownFiles).toHaveBeenCalledWith(mockInitWithParentClientConfig);
7273
expect(getProfileName).toHaveBeenCalledWith(mockInit);
7374
vi.clearAllMocks();
7475
});
@@ -167,7 +168,11 @@ describe(fromSso.name, () => {
167168
const { fromSso } = await import("./fromSso");
168169
await expect(fromSso(mockInit)()).resolves.toStrictEqual(mockNewToken);
169170
expect(getNewSsoOidcToken).toHaveBeenCalledTimes(1);
170-
expect(getNewSsoOidcToken).toHaveBeenCalledWith(mockSsoToken, mockSsoSession.sso_region, mockInit);
171+
expect(getNewSsoOidcToken).toHaveBeenCalledWith(
172+
mockSsoToken,
173+
mockSsoSession.sso_region,
174+
mockInitWithParentClientConfig
175+
);
171176

172177
// Simulate token expiration.
173178
const ssoTokenExpiryError = new TokenProviderError(`SSO Token is expired. ${REFRESH_MESSAGE}`, false);
@@ -183,7 +188,11 @@ describe(fromSso.name, () => {
183188
const { fromSso } = await import("./fromSso");
184189
await expect(fromSso(mockInit)()).resolves.toStrictEqual(mockNewToken);
185190
expect(getNewSsoOidcToken).toHaveBeenCalledTimes(1);
186-
expect(getNewSsoOidcToken).toHaveBeenCalledWith(mockSsoToken, mockSsoSession.sso_region, mockInit);
191+
expect(getNewSsoOidcToken).toHaveBeenCalledWith(
192+
mockSsoToken,
193+
mockSsoSession.sso_region,
194+
mockInitWithParentClientConfig
195+
);
187196

188197
// Return a valid token for second call.
189198
const mockValidSsoToken = {
@@ -234,7 +243,7 @@ describe(fromSso.name, () => {
234243
expect(getNewSsoOidcToken).toHaveBeenCalledWith(
235244
mockValidSsoTokenInExpiryWindow,
236245
mockSsoSession.sso_region,
237-
mockInit
246+
mockInitWithParentClientConfig
238247
);
239248
};
240249

@@ -244,7 +253,11 @@ describe(fromSso.name, () => {
244253
throw ssoTokenExpiryError;
245254
});
246255
await expect(fromSsoImpl(mockInit)()).rejects.toStrictEqual(ssoTokenExpiryError);
247-
expect(getNewSsoOidcToken).toHaveBeenCalledWith(mockSsoToken, mockSsoSession.sso_region, mockInit);
256+
expect(getNewSsoOidcToken).toHaveBeenCalledWith(
257+
mockSsoToken,
258+
mockSsoSession.sso_region,
259+
mockInitWithParentClientConfig
260+
);
248261
};
249262

250263
afterEach(() => {
@@ -290,7 +303,11 @@ describe(fromSso.name, () => {
290303
const { fromSso } = await import("./fromSso");
291304
await expect(fromSso(mockInit)()).resolves.toStrictEqual(mockNewToken);
292305
expect(getNewSsoOidcToken).toHaveBeenCalledTimes(1);
293-
expect(getNewSsoOidcToken).toHaveBeenCalledWith(mockSsoToken, mockSsoSession.sso_region, mockInit);
306+
expect(getNewSsoOidcToken).toHaveBeenCalledWith(
307+
mockSsoToken,
308+
mockSsoSession.sso_region,
309+
mockInitWithParentClientConfig
310+
);
294311

295312
expect(writeSSOTokenToFile).toHaveBeenCalledWith(mockSsoSessionName, {
296313
...mockSsoToken,

0 commit comments

Comments
 (0)