-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Gpl/970-multi-org-tests #20436
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
Merged
Merged
Gpl/970-multi-org-tests #20436
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import { | |
| TeamMembershipInvite, | ||
| WorkspaceTimeoutDuration, | ||
| OrgMemberRole, | ||
| User, | ||
| } from "@gitpod/gitpod-protocol"; | ||
| import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics"; | ||
| import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
|
|
@@ -33,7 +34,7 @@ import { StripeService } from "../billing/stripe-service"; | |
| import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution"; | ||
| import { UsageService } from "./usage-service"; | ||
| import { CostCenter_BillingStrategy } from "@gitpod/gitpod-protocol/lib/usage"; | ||
| import { UserAuthentication } from "../user/user-authentication"; | ||
| import { CreateUserParams, UserAuthentication } from "../user/user-authentication"; | ||
|
|
||
| @injectable() | ||
| export class OrganizationService { | ||
|
|
@@ -324,6 +325,26 @@ export class OrganizationService { | |
| return invite.teamId; | ||
| } | ||
|
|
||
| /** | ||
| * Convenience method, analogue to UserService.createUser() | ||
| `` | ||
| */ | ||
| public async createOrgOwnedUser(params: CreateUserParams & { organizationId: string }): Promise<User> { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the method that before was buried in |
||
| return this.userDB.transaction(async (_, ctx) => { | ||
| const user = await this.userService.createUser(params, ctx); | ||
|
|
||
| await this.addOrUpdateMember( | ||
| SYSTEM_USER_ID, | ||
| params.organizationId, | ||
| user.id, | ||
| "member", | ||
| { flexibleRole: true }, | ||
| ctx, | ||
| ); | ||
| return user; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Add or update member to an organization, if there's no `owner` in the organization, target role will be owner | ||
| * | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -19,15 +19,14 @@ import { Experiments } from "@gitpod/gitpod-protocol/lib/experiments/configcat-s | |
| import * as chai from "chai"; | ||
| import { Container } from "inversify"; | ||
| import "mocha"; | ||
| import { createTestContainer, withTestCtx } from "../test/service-testing-container-module"; | ||
| import { createTestContainer } from "../test/service-testing-container-module"; | ||
| import { resetDB } from "@gitpod/gitpod-db/lib/test/reset-db"; | ||
| import { OrganizationService } from "../orgs/organization-service"; | ||
| import { UserService } from "./user-service"; | ||
| import { expectError } from "../test/expect-utils"; | ||
| import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
| import { EnvVarService } from "./env-var-service"; | ||
| import { ProjectsService } from "../projects/projects-service"; | ||
| import { SYSTEM_USER } from "../authorization/authorizer"; | ||
|
|
||
| const expect = chai.expect; | ||
|
|
||
|
|
@@ -98,9 +97,8 @@ describe("EnvVarService", async () => { | |
|
|
||
| const orgService = container.get<OrganizationService>(OrganizationService); | ||
| org = await orgService.createOrganization(BUILTIN_INSTLLATION_ADMIN_USER_ID, "myOrg"); | ||
| const invite = await orgService.getOrCreateInvite(BUILTIN_INSTLLATION_ADMIN_USER_ID, org.id); | ||
|
|
||
| member = await userService.createUser({ | ||
| member = await orgService.createOrgOwnedUser({ | ||
| organizationId: org.id, | ||
| identity: { | ||
| authId: "foo", | ||
|
|
@@ -109,7 +107,6 @@ describe("EnvVarService", async () => { | |
| primaryEmail: "[email protected]", | ||
| }, | ||
| }); | ||
| await withTestCtx(SYSTEM_USER, () => orgService.joinOrganization(member.id, invite.id)); | ||
| stranger = await userService.createUser({ | ||
| identity: { | ||
| authId: "foo2", | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,14 +10,13 @@ import { Experiments } from "@gitpod/gitpod-protocol/lib/experiments/configcat-s | |
| import * as chai from "chai"; | ||
| import { Container } from "inversify"; | ||
| import "mocha"; | ||
| import { createTestContainer, withTestCtx } from "../test/service-testing-container-module"; | ||
| import { createTestContainer } from "../test/service-testing-container-module"; | ||
| import { resetDB } from "@gitpod/gitpod-db/lib/test/reset-db"; | ||
| import { OrganizationService } from "../orgs/organization-service"; | ||
| import { UserService } from "./user-service"; | ||
| import { expectError } from "../test/expect-utils"; | ||
| import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
| import { GitpodTokenService } from "./gitpod-token-service"; | ||
| import { SYSTEM_USER } from "../authorization/authorizer"; | ||
|
|
||
| const expect = chai.expect; | ||
|
|
||
|
|
@@ -35,10 +34,9 @@ describe("GitpodTokenService", async () => { | |
|
|
||
| const orgService = container.get<OrganizationService>(OrganizationService); | ||
| org = await orgService.createOrganization(BUILTIN_INSTLLATION_ADMIN_USER_ID, "myOrg"); | ||
| const invite = await orgService.getOrCreateInvite(BUILTIN_INSTLLATION_ADMIN_USER_ID, org.id); | ||
|
|
||
| const userService = container.get<UserService>(UserService); | ||
| member = await userService.createUser({ | ||
| member = await orgService.createOrgOwnedUser({ | ||
| organizationId: org.id, | ||
| identity: { | ||
| authId: "foo", | ||
|
|
@@ -47,7 +45,6 @@ describe("GitpodTokenService", async () => { | |
| primaryEmail: "[email protected]", | ||
| }, | ||
| }); | ||
| await withTestCtx(SYSTEM_USER, () => orgService.joinOrganization(member.id, invite.id)); | ||
| stranger = await userService.createUser({ | ||
| identity: { | ||
| authId: "foo2", | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,14 +10,13 @@ import { Experiments } from "@gitpod/gitpod-protocol/lib/experiments/configcat-s | |
| import * as chai from "chai"; | ||
| import { Container } from "inversify"; | ||
| import "mocha"; | ||
| import { createTestContainer, withTestCtx } from "../test/service-testing-container-module"; | ||
| import { createTestContainer } from "../test/service-testing-container-module"; | ||
| import { resetDB } from "@gitpod/gitpod-db/lib/test/reset-db"; | ||
| import { SSHKeyService } from "./sshkey-service"; | ||
| import { OrganizationService } from "../orgs/organization-service"; | ||
| import { UserService } from "./user-service"; | ||
| import { expectError } from "../test/expect-utils"; | ||
| import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; | ||
| import { SYSTEM_USER } from "../authorization/authorizer"; | ||
|
|
||
| const expect = chai.expect; | ||
|
|
||
|
|
@@ -46,10 +45,9 @@ describe("SSHKeyService", async () => { | |
|
|
||
| const orgService = container.get<OrganizationService>(OrganizationService); | ||
| org = await orgService.createOrganization(BUILTIN_INSTLLATION_ADMIN_USER_ID, "myOrg"); | ||
| const invite = await orgService.getOrCreateInvite(BUILTIN_INSTLLATION_ADMIN_USER_ID, org.id); | ||
|
|
||
| const userService = container.get<UserService>(UserService); | ||
| member = await userService.createUser({ | ||
| member = await orgService.createOrgOwnedUser({ | ||
| organizationId: org.id, | ||
| identity: { | ||
| authId: "foo", | ||
|
|
@@ -58,7 +56,6 @@ describe("SSHKeyService", async () => { | |
| primaryEmail: "[email protected]", | ||
| }, | ||
| }); | ||
| await withTestCtx(SYSTEM_USER, () => orgService.joinOrganization(member.id, invite.id)); | ||
| stranger = await userService.createUser({ | ||
| identity: { | ||
| authId: "foo2", | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,12 +8,10 @@ import { Experiments } from "@gitpod/gitpod-protocol/lib/experiments/configcat-s | |
| import * as chai from "chai"; | ||
| import "mocha"; | ||
| import { Container } from "inversify"; | ||
| import { createTestContainer, withTestCtx } from "../test/service-testing-container-module"; | ||
| import { createTestContainer } from "../test/service-testing-container-module"; | ||
| import { BUILTIN_INSTLLATION_ADMIN_USER_ID, TypeORM, UserDB } from "@gitpod/gitpod-db/lib"; | ||
| import { resetDB } from "@gitpod/gitpod-db/lib/test/reset-db"; | ||
| import { OrganizationService } from "../orgs/organization-service"; | ||
| import { SYSTEM_USER } from "../authorization/authorizer"; | ||
| import { UserService } from "./user-service"; | ||
| import { Organization, Token, User } from "@gitpod/gitpod-protocol"; | ||
| import { TokenService } from "./token-service"; | ||
| import { TokenProvider } from "./token-provider"; | ||
|
|
@@ -33,11 +31,9 @@ describe("TokenService", async () => { | |
|
|
||
| let container: Container; | ||
| let tokenService: TokenService; | ||
| let userService: UserService; | ||
| let userDB: UserDB; | ||
| let orgService: OrganizationService; | ||
| let org: Organization; | ||
| let owner: User; | ||
| let user: User; | ||
|
|
||
| let token: Token; | ||
|
|
@@ -127,23 +123,10 @@ describe("TokenService", async () => { | |
|
|
||
| tokenService = container.get<TokenService>(TokenService); | ||
| userDB = container.get<UserDB>(UserDB); | ||
| userService = container.get<UserService>(UserService); | ||
| orgService = container.get<OrganizationService>(OrganizationService); | ||
| org = await orgService.createOrganization(BUILTIN_INSTLLATION_ADMIN_USER_ID, "myOrg"); | ||
| const invite = await orgService.getOrCreateInvite(BUILTIN_INSTLLATION_ADMIN_USER_ID, org.id); | ||
| // first not builtin user join an org will be an owner | ||
| owner = await userService.createUser({ | ||
| organizationId: org.id, | ||
| identity: { | ||
| authId: "foo", | ||
| authName: "bar", | ||
| authProviderId: "github", | ||
| primaryEmail: "[email protected]", | ||
| }, | ||
| }); | ||
| await withTestCtx(SYSTEM_USER, () => orgService.joinOrganization(owner.id, invite.id)); | ||
|
|
||
| user = await userService.createUser({ | ||
| user = await orgService.createOrgOwnedUser({ | ||
| organizationId: org.id, | ||
| identity: { | ||
| authId: githubUserAuthId, | ||
|
|
@@ -159,7 +142,6 @@ describe("TokenService", async () => { | |
| primaryEmail: "[email protected]", | ||
| }); | ||
| await userDB.storeUser(user); | ||
| await withTestCtx(SYSTEM_USER, () => orgService.joinOrganization(user.id, invite.id)); | ||
|
|
||
| // test data | ||
| token = <Token>{ | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@filiptronicek These are the core tests added