Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: enam-khan <[email protected]>
  • Loading branch information
enamkhan committed Feb 4, 2025
1 parent fd79504 commit 7a3eb2a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("Test suite for CICSSessionTree", () => {

describe("validation", () => {
beforeEach(() => {
cst = new CICSSessionTree(cicsProfileMock, undefined, getIconFilePathFromName("profile"));
cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.getSession();
});

Expand Down Expand Up @@ -98,7 +98,7 @@ describe("Test suite for CICSSessionTree", () => {
Cookie: "blah=hello"
};

cst = new CICSSessionTree(cicsProfileMock, undefined, getIconFilePathFromName("profile"));
cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.getSession();

ses.storeCookie(cookie);
Expand All @@ -112,7 +112,7 @@ describe("Test suite for CICSSessionTree", () => {
Cookie: "LtpaToken2=testValue"
};

cst = new CICSSessionTree(cicsProfileMock, undefined, getIconFilePathFromName("profile"));
cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.getSession();

ses.storeCookie(cookies);
Expand All @@ -126,32 +126,7 @@ describe("Test suite for CICSSessionTree", () => {
Cookie: "blah=hello;LtpaToken2=testValue"
};

cst = new CICSSessionTree(cicsProfileMock, undefined, getIconFilePathFromName("profile"));
ses = cst.getSession();

ses.storeCookie(cookies);

expect(ses.ISession.tokenType).toEqual("LtpaToken2");
expect(ses.ISession.tokenValue).toEqual("testValue");
});


it("Should store valid cookie if the session is provided", () => {
const cookies = {
Cookie: "blah=hello;LtpaToken2=testValue"
};

const mockSession = new imperative.Session({
type: SessConstants.AUTH_TYPE_TOKEN,
storeCookie: true,
tokenType: SessConstants.TOKEN_TYPE_LTPA,
hostname: cicsProfileMock.profile.host,
port: Number(cicsProfileMock.profile.port),
user: cicsProfileMock.profile.user || "",
password: cicsProfileMock.profile.password || "",
rejectUnauthorized: cicsProfileMock.profile.rejectUnauthorized});

cst = new CICSSessionTree(cicsProfileMock, mockSession, getIconFilePathFromName("profile"));
cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.getSession();

ses.storeCookie(cookies);
Expand Down
6 changes: 1 addition & 5 deletions packages/vsce/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ export async function activate(context: ExtensionContext) {
try {
plexExpansionHandler(node.element, treeDataProv);
} catch (error) {
const newSessionTree = new CICSSessionTree(
node.element.getParent().profile,
node.element.getParent().getSession(),
getIconFilePathFromName("profile-disconnected"));
treeDataProv.loadedProfiles.splice(treeDataProv.getLoadedProfiles().indexOf(node.element.getParent()), 1, newSessionTree);
node.element.getParent().iconPath = getIconFilePathFromName("profile-disconnected");
treeDataProv._onDidChangeTreeData.fire(undefined);
}
},
Expand Down
27 changes: 11 additions & 16 deletions packages/vsce/src/trees/CICSSessionTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,23 @@ export class CICSSessionTree extends TreeItem {

constructor(
profile: any,
session?: Session,
public readonly iconPath = getIconFilePathFromName("profile-unverified"),
) {
super(profile.name, TreeItemCollapsibleState.Collapsed);
this.children = [];
this.contextValue = `cicssession.${profile.name}`;

if (session) {
this.session = session;
} else {
this.session = new imperative.Session({
type: SessConstants.AUTH_TYPE_TOKEN,
storeCookie: true,
tokenType: SessConstants.TOKEN_TYPE_LTPA,
hostname: profile.profile!.host,
port: Number(profile.profile!.port),
user: profile.profile!.user || "",
password: profile.profile!.password || "",
rejectUnauthorized: profile.profile!.rejectUnauthorized,
protocol: profile.profile!.protocol,
});
}
this.session = new imperative.Session({
type: SessConstants.AUTH_TYPE_TOKEN,
storeCookie: true,
tokenType: SessConstants.TOKEN_TYPE_LTPA,
hostname: profile.profile!.host,
port: Number(profile.profile!.port),
user: profile.profile!.user || "",
password: profile.profile!.password || "",
rejectUnauthorized: profile.profile!.rejectUnauthorized,
protocol: profile.profile!.protocol,
});

this.profile = profile;
this.isUnauthorized = undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/vsce/src/trees/CICSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
}

// Initialise session tree
newSessionTree = new CICSSessionTree(profile, undefined, getIconFilePathFromName("profile"));
newSessionTree = new CICSSessionTree(profile, getIconFilePathFromName("profile"));
const plexInfo: InfoLoaded[] = await ProfileManagement.getPlexInfo(profile, newSessionTree.getSession());

// For each InfoLoaded object - happens if there are multiple plexes
Expand Down Expand Up @@ -315,7 +315,7 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
this._onDidChangeTreeData.fire(undefined);
} catch (error) {
// Change session tree icon to disconnected upon error
newSessionTree = new CICSSessionTree(profile, undefined, getIconFilePathFromName("profile-disconnected"));
newSessionTree = new CICSSessionTree(profile, getIconFilePathFromName("profile-disconnected"));
// If method was called when expanding profile
if (sessionTree) {
this.loadedProfiles.splice(position, 1, newSessionTree);
Expand Down

0 comments on commit 7a3eb2a

Please sign in to comment.