@@ -7,31 +7,66 @@ import { suite, test } from "mocha-typescript";
7
7
import { APIUserService } from "./user" ;
8
8
import { Container } from "inversify" ;
9
9
import { testContainer } from "@gitpod/gitpod-db/lib" ;
10
+ import { API } from "./server" ;
11
+ import * as http from "http" ;
12
+ import { createConnectTransport } from "@bufbuild/connect-node" ;
13
+ import { Code , ConnectError , PromiseClient , createPromiseClient } from "@bufbuild/connect" ;
14
+ import { AddressInfo } from "net" ;
15
+ import { TeamsService as TeamsServiceDefinition } from "@gitpod/public-api/lib/gitpod/experimental/v1/teams_connectweb" ;
10
16
import { WorkspaceStarter } from "../workspace/workspace-starter" ;
11
17
import { UserService } from "../user/user-service" ;
12
- import { BlockUserRequest , BlockUserResponse } from "@gitpod/public-api/lib/gitpod/experimental/v1/user_pb" ;
13
- import { User } from "@gitpod/gitpod-protocol" ;
14
- import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib" ;
15
- import { Workspace } from "@gitpod/gitpod-protocol/lib/protocol" ;
16
- import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
17
- import { v4 as uuidv4 } from "uuid" ;
18
- import { ConnectError , Code } from "@bufbuild/connect" ;
18
+ import { APITeamsService } from "./teams" ;
19
19
import * as chai from "chai" ;
20
20
21
21
const expect = chai . expect ;
22
22
23
23
@suite ( )
24
24
export class APITeamsServiceSpec {
25
25
private container : Container ;
26
+ private server : http . Server ;
27
+
28
+ private client : PromiseClient < typeof TeamsServiceDefinition > ;
26
29
27
30
async before ( ) {
28
31
this . container = testContainer . createChild ( ) ;
32
+ this . container . bind ( API ) . toSelf ( ) . inSingletonScope ( ) ;
29
33
this . container . bind ( APIUserService ) . toSelf ( ) . inSingletonScope ( ) ;
34
+ this . container . bind ( APITeamsService ) . toSelf ( ) . inSingletonScope ( ) ;
35
+
36
+ this . container . bind ( WorkspaceStarter ) . toConstantValue ( { } as WorkspaceStarter ) ;
37
+ this . container . bind ( UserService ) . toConstantValue ( { } as UserService ) ;
38
+
39
+ this . server = this . container . get < API > ( API ) . listen ( 0 ) ;
40
+
41
+ const address = this . server . address ( ) as AddressInfo ;
42
+ const transport = createConnectTransport ( {
43
+ baseUrl : `http://localhost:${ address . port } ` ,
44
+ httpVersion : "1.1" ,
45
+ } ) ;
46
+
47
+ this . client = createPromiseClient ( TeamsServiceDefinition , transport ) ;
30
48
}
31
49
32
- @test async getTeam_respondsWithTeamMembersAndInvite ( ) {
33
- const sut = this . container . get < APIUserService > ( APIUserService ) ;
50
+ async after ( ) {
51
+ await new Promise ( ( resolve , reject ) => {
52
+ this . server . close ( ( err ) => {
53
+ if ( err ) {
54
+ return reject ( err ) ;
55
+ }
56
+ resolve ( null ) ;
57
+ } ) ;
58
+ } ) ;
59
+ }
34
60
35
- const ;
61
+ @test async getTeam_rejectsMissingTeamID ( ) {
62
+ try {
63
+ await this . client . getTeam ( {
64
+ teamId : "" ,
65
+ } ) ;
66
+ expect . fail ( "getteam did not throw an exception" ) ;
67
+ } catch ( err ) {
68
+ expect ( err ) . to . be . an . instanceof ( ConnectError ) ;
69
+ expect ( err . code ) . to . equal ( Code . InvalidArgument ) ;
70
+ }
36
71
}
37
72
}
0 commit comments