-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when there is more then one org for the auth key
open Quick-pick dialog and let the user pick the org
- Loading branch information
Showing
11 changed files
with
126 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as jestMock from "jest-mock"; | ||
import * as vscode from "vscode"; | ||
|
||
let quickPickSpy: jestMock.SpyInstance<any>; | ||
export const spyOnQuickPick = () => { | ||
quickPickSpy = jestMock.spyOn(vscode.window, "showQuickPick"); | ||
return quickPickSpy; | ||
}; | ||
|
||
export const resetSpyOnQuickPick = () => { | ||
quickPickSpy?.mockReset?.(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,9 @@ import { | |
import * as jestMock from "jest-mock"; | ||
import * as vscode from "vscode"; | ||
import expect from "expect"; | ||
import { afterEach, beforeEach } from "mocha"; | ||
import { afterEach } from "mocha"; | ||
import { resetSpyOnQuickPick, spyOnQuickPick } from "../mocks/quick-pick"; | ||
|
||
const orgId = "org-id"; | ||
const envName = "my env"; | ||
const auth = { keyId: "key-id", secret: "key-secret" }; | ||
const environmentMock = getEnvironmentMock( | ||
|
@@ -30,40 +30,44 @@ const environmentMock = getEnvironmentMock( | |
name: envName, | ||
} | ||
); | ||
const selectedOrg = { name: "my org", id: "org-id" }; | ||
const initMocksAndLogin = async (moreOrgs: typeof selectedOrg[] = []) => { | ||
mockGetOrganization([selectedOrg, ...moreOrgs], auth); | ||
mockGetEnvironment(selectedOrg.id, [environmentMock], auth); | ||
mockGitRepoAndBranch("main", "[email protected]:user/repo.git"); | ||
mockGetDeploymentStepsApiResponse(); | ||
await login(auth); | ||
|
||
suite("authentication", function () { | ||
this.timeout(1000 * 10); | ||
beforeEach(async () => { | ||
mockGetOrganization(orgId, auth); | ||
mockGetEnvironment(orgId, [environmentMock], auth); | ||
mockGitRepoAndBranch("main", "[email protected]:user/repo.git"); | ||
mockGetDeploymentStepsApiResponse(); | ||
await waitFor(() => expect(getFirstEnvStatus()).toContain("ACTIVE")); | ||
}; | ||
|
||
await login(auth); | ||
await waitFor(() => expect(getFirstEnvStatus()).toContain("ACTIVE")); | ||
}); | ||
suite("authentication", function () { | ||
this.timeout(1000 * 600); | ||
|
||
afterEach(async () => { | ||
await logout(); | ||
await resetExtension(); | ||
resetSpyOnQuickPick(); | ||
}); | ||
|
||
test("should call redeploy with the credentials provided on login", async () => { | ||
await initMocksAndLogin(); | ||
const onRedeployCalled = jestMock.fn(); | ||
mockRedeployApiResponse(environmentMock.id, auth, onRedeployCalled); | ||
|
||
vscode.commands.executeCommand("env0.redeploy", getFirstEnvironment()); | ||
await waitFor(() => expect(onRedeployCalled).toHaveBeenCalled()); | ||
await waitFor(() => expect(onRedeployCalled).toHaveBeenCalled(), 10); | ||
}); | ||
|
||
test("should call redeploy with updated credentials when logout and login again ", async () => { | ||
await initMocksAndLogin(); | ||
await logout(); | ||
const newAuthData = { | ||
keyId: "different-key-id", | ||
secret: "different-key-secret", | ||
}; | ||
mockGetOrganization(orgId, newAuthData); | ||
mockGetEnvironment(orgId, [environmentMock], newAuthData); | ||
mockGetOrganization([selectedOrg], newAuthData); | ||
mockGetEnvironment(selectedOrg.id, [environmentMock], newAuthData); | ||
|
||
await login(newAuthData); | ||
await waitFor(() => expect(getFirstEnvStatus()).toContain("ACTIVE")); | ||
|
@@ -75,11 +79,30 @@ suite("authentication", function () { | |
}); | ||
|
||
test("should show login message when logout", async () => { | ||
await initMocksAndLogin(); | ||
await logout(); | ||
await waitFor(() => | ||
expect(getEnvironmentsView().message).toContain( | ||
"you are logged out. in order to log in, run the command 'env0.login'" | ||
) | ||
); | ||
}); | ||
|
||
test("should show pick organization message when login", async () => { | ||
const onQuickPick = spyOnQuickPick(); | ||
|
||
const secondOrg = { name: "second org", id: "second-org-id" }; | ||
initMocksAndLogin([secondOrg]); | ||
await waitFor(() => | ||
expect(onQuickPick).toHaveBeenCalledWith( | ||
[selectedOrg, secondOrg].map((org) => ({ | ||
label: org.name, | ||
description: org.id, | ||
})), | ||
{ | ||
placeHolder: "Select an organization", | ||
} | ||
) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,11 +41,12 @@ import { | |
} from "../mocks/notification-message"; | ||
|
||
const auth = { keyId: "key-id", secret: "key-secret" }; | ||
const orgId = "org-id"; | ||
const organization = { name: "my org", id: "org-id" }; | ||
const orgId = organization.id; | ||
|
||
const initTest = async (environments: EnvironmentModel[]) => { | ||
mockGetOrganization(orgId, auth); | ||
mockGetEnvironment(orgId, environments, auth); | ||
mockGetOrganization([organization], auth); | ||
mockGetEnvironment(organization.id, environments, auth); | ||
mockGitRepoAndBranch("main", "[email protected]:user/repo.git"); | ||
mockGetDeploymentStepsApiResponse(); | ||
spyOnShowMessage(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,11 @@ import { EnvironmentModel } from "../../../get-environments"; | |
import expect from "expect"; | ||
|
||
const auth = { keyId: "key-id", secret: "key-secret" }; | ||
const orgId = "org-id"; | ||
const organization = { name: "my org", id: "org-id" }; | ||
|
||
const initTest = async (environments: EnvironmentModel[]) => { | ||
mockGetOrganization(orgId, auth); | ||
mockGetEnvironment(orgId, environments, auth); | ||
mockGetOrganization([organization], auth); | ||
mockGetEnvironment(organization.id, environments, auth); | ||
mockGitRepoAndBranch("main", "[email protected]:user/repo.git"); | ||
await login(auth); | ||
}; | ||
|
@@ -80,15 +81,15 @@ suite("environments", function () { | |
}), | ||
]; | ||
mockNoGitRepo(); | ||
mockGetOrganization(orgId, auth); | ||
mockGetOrganization([organization], auth); | ||
// we don't await on login because we want to test the loading message | ||
login(auth); | ||
await waitFor( | ||
() => expect(getEnvironmentViewMessage()).toBe("loading environments..."), | ||
10 | ||
); | ||
mockGitRepoAndBranch("main", "[email protected]:user/repo.git"); | ||
mockGetEnvironment(orgId, environments, auth, 2000); | ||
mockGetEnvironment(organization.id, environments, auth, 2000); | ||
await waitFor(() => | ||
expect(getEnvironmentViewMessage()).toBe( | ||
"loading environments for branch main..." | ||
|
@@ -99,7 +100,7 @@ suite("environments", function () { | |
|
||
test("should show could not find git branch message", async () => { | ||
mockNoGitRepo(); | ||
mockGetOrganization(orgId, auth); | ||
mockGetOrganization([organization], auth); | ||
await login(auth); | ||
await waitFor(() => | ||
expect(getEnvironmentViewMessage()).toBe( | ||
|