Skip to content

Commit

Permalink
update profilesCache tests
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Dec 13, 2023
1 parent 87461f6 commit 52018cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ function createProfInfoMock(profiles: Partial<zowe.imperative.IProfileLoaded>[])
knownArgs: Object.entries(profile.profile as object).map(([k, v]) => ({ argName: k, argValue: v as unknown })),
};
},
updateProperty: jest.fn(),
updateKnownProperty: jest.fn(),
isSecured: jest.fn(),
} as any;
}

Expand Down Expand Up @@ -339,6 +342,27 @@ describe("ProfilesCache", () => {
expect(profileNames).toEqual(["lpar1", "lpar2"]);
});

describe("updateBaseProfileFile Login/Logout", () => {
const updProfile = { tokenType: "apimlAuthenticationToken", tokenValue: "tokenValue" };

it("should update the base profile on login", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger);
const mockProfInfo = createProfInfoMock([lpar1Profile, lpar2Profile]);
jest.spyOn(profCache, "getProfileInfo").mockResolvedValue(mockProfInfo);
await profCache.updateBaseProfileFileLogin(lpar1Profile as any, updProfile);

expect(mockProfInfo.updateProperty).toBeCalledTimes(2);
});
it("should update the base profile on login", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger);
const mockProfInfo = createProfInfoMock([lpar1Profile, lpar2Profile]);
jest.spyOn(profCache, "getProfileInfo").mockResolvedValue(mockProfInfo);
await profCache.updateBaseProfileFileLogout(lpar1Profile as any);

expect(mockProfInfo.updateKnownProperty).toBeCalledTimes(2);
});
});

describe("fetchAllProfilesByType", () => {
it("should return array of profile objects for given type", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe("ZoweVsCodeExtension", () => {
it("should login using the service profile given a simple profile name", async () => {
testCache.fetchBaseProfile.mockResolvedValue(baseProfile);
const testSpy = jest.spyOn(ZoweVsCodeExtension as any, "getServiceProfileForAuthPurposes");
const newServiceProfile = { ...serviceProfile, profile: { ...testProfile, ...updProfile, host: "service" } };
const newServiceProfile = { ...serviceProfile, profile: { ...testProfile, tokenValue: "tokenValue", host: "service" } };
testSpy.mockResolvedValue(newServiceProfile);
jest.spyOn(ZoweVsCodeExtension as any, "promptUserPass").mockResolvedValue(["user", "pass"]);
const loginSpy = jest.spyOn(Login, "apimlLogin").mockResolvedValue("tokenValue");
Expand Down

0 comments on commit 52018cf

Please sign in to comment.