@@ -4,46 +4,51 @@ import { expect } from "chai";
4
4
import * as gcb from "../../../gcp/cloudbuild" ;
5
5
import * as prompt from "../../../prompt" ;
6
6
import * as poller from "../../../operation-poller" ;
7
- import { FirebaseError } from "../../../error" ;
8
7
import * as repo from "../../../init/features/frameworks/repo" ;
9
8
import * as utils from "../../../utils" ;
9
+ import { Connection } from "../../../gcp/cloudbuild" ;
10
+ import { FirebaseError } from "../../../error" ;
10
11
11
12
describe ( "composer" , ( ) => {
12
- const sandbox : sinon . SinonSandbox = sinon . createSandbox ( ) ;
13
-
14
- let promptOnceStub : sinon . SinonStub ;
15
- let pollOperationStub : sinon . SinonStub ;
16
- let getConnectionStub : sinon . SinonStub ;
17
- let getRepositoryStub : sinon . SinonStub ;
18
- let createConnectionStub : sinon . SinonStub ;
19
- let createRepositoryStub : sinon . SinonStub ;
20
- let fetchLinkableRepositoriesStub : sinon . SinonStub ;
21
-
22
- beforeEach ( ( ) => {
23
- promptOnceStub = sandbox . stub ( prompt , "promptOnce" ) . throws ( "Unexpected promptOnce call" ) ;
24
- pollOperationStub = sandbox
25
- . stub ( poller , "pollOperation" )
26
- . throws ( "Unexpected pollOperation call" ) ;
27
- getConnectionStub = sandbox . stub ( gcb , "getConnection" ) . throws ( "Unexpected getConnection call" ) ;
28
- getRepositoryStub = sandbox . stub ( gcb , "getRepository" ) . throws ( "Unexpected getRepository call" ) ;
29
- createConnectionStub = sandbox
30
- . stub ( gcb , "createConnection" )
31
- . throws ( "Unexpected createConnection call" ) ;
32
- createRepositoryStub = sandbox
33
- . stub ( gcb , "createRepository" )
34
- . throws ( "Unexpected createRepository call" ) ;
35
- fetchLinkableRepositoriesStub = sandbox
36
- . stub ( gcb , "fetchLinkableRepositories" )
37
- . throws ( "Unexpected fetchLinkableRepositories call" ) ;
38
-
39
- sandbox . stub ( utils , "openInBrowser" ) . resolves ( ) ;
40
- } ) ;
13
+ describe ( "connect GitHub repo" , ( ) => {
14
+ const sandbox : sinon . SinonSandbox = sinon . createSandbox ( ) ;
41
15
42
- afterEach ( ( ) => {
43
- sandbox . verifyAndRestore ( ) ;
44
- } ) ;
16
+ let promptOnceStub : sinon . SinonStub ;
17
+ let pollOperationStub : sinon . SinonStub ;
18
+ let getConnectionStub : sinon . SinonStub ;
19
+ let getRepositoryStub : sinon . SinonStub ;
20
+ let createConnectionStub : sinon . SinonStub ;
21
+ let createRepositoryStub : sinon . SinonStub ;
22
+ let fetchLinkableRepositoriesStub : sinon . SinonStub ;
23
+
24
+ beforeEach ( ( ) => {
25
+ promptOnceStub = sandbox . stub ( prompt , "promptOnce" ) . throws ( "Unexpected promptOnce call" ) ;
26
+ pollOperationStub = sandbox
27
+ . stub ( poller , "pollOperation" )
28
+ . throws ( "Unexpected pollOperation call" ) ;
29
+ getConnectionStub = sandbox
30
+ . stub ( gcb , "getConnection" )
31
+ . throws ( "Unexpected getConnection call" ) ;
32
+ getRepositoryStub = sandbox
33
+ . stub ( gcb , "getRepository" )
34
+ . throws ( "Unexpected getRepository call" ) ;
35
+ createConnectionStub = sandbox
36
+ . stub ( gcb , "createConnection" )
37
+ . throws ( "Unexpected createConnection call" ) ;
38
+ createRepositoryStub = sandbox
39
+ . stub ( gcb , "createRepository" )
40
+ . throws ( "Unexpected createRepository call" ) ;
41
+ fetchLinkableRepositoriesStub = sandbox
42
+ . stub ( gcb , "fetchLinkableRepositories" )
43
+ . throws ( "Unexpected fetchLinkableRepositories call" ) ;
44
+
45
+ sandbox . stub ( utils , "openInBrowser" ) . resolves ( ) ;
46
+ } ) ;
47
+
48
+ afterEach ( ( ) => {
49
+ sandbox . verifyAndRestore ( ) ;
50
+ } ) ;
45
51
46
- describe ( "connect GitHub repo" , ( ) => {
47
52
const projectId = "projectId" ;
48
53
const location = "us-central1" ;
49
54
const connectionId = `frameworks-${ location } ` ;
@@ -130,4 +135,58 @@ describe("composer", () => {
130
135
await expect ( repo . linkGitHubRepository ( projectId , location ) ) . to . be . rejected ;
131
136
} ) ;
132
137
} ) ;
138
+
139
+ describe ( "listAppHostingConnections" , ( ) => {
140
+ const sandbox : sinon . SinonSandbox = sinon . createSandbox ( ) ;
141
+ let listConnectionsStub : sinon . SinonStub ;
142
+
143
+ const projectId = "projectId" ;
144
+ const location = "us-central1" ;
145
+
146
+ function mockConn ( id : string ) : Connection {
147
+ return {
148
+ name : `projects/${ projectId } /locations/${ location } /connections/${ id } ` ,
149
+ disabled : false ,
150
+ createTime : "0" ,
151
+ updateTime : "1" ,
152
+ installationState : {
153
+ stage : "COMPLETE" ,
154
+ message : "complete" ,
155
+ actionUri : "https://google.com" ,
156
+ } ,
157
+ reconciling : false ,
158
+ } ;
159
+ }
160
+
161
+ function extractId ( name : string ) : string {
162
+ const parts = name . split ( "/" ) ;
163
+ return parts . pop ( ) ?? "" ;
164
+ }
165
+
166
+ beforeEach ( ( ) => {
167
+ listConnectionsStub = sandbox
168
+ . stub ( gcb , "listConnections" )
169
+ . throws ( "Unexpected getConnection call" ) ;
170
+ } ) ;
171
+
172
+ afterEach ( ( ) => {
173
+ sandbox . verifyAndRestore ( ) ;
174
+ } ) ;
175
+
176
+ it ( "filters out non-App Hosting connections" , async ( ) => {
177
+ listConnectionsStub . resolves ( [
178
+ mockConn ( "frameworks-github-conn-baddcafe" ) ,
179
+ mockConn ( "hooray-conn" ) ,
180
+ mockConn ( "frameworks-github-conn-deadbeef" ) ,
181
+ mockConn ( "frameworks-github-oauth" ) ,
182
+ ] ) ;
183
+
184
+ const conns = await repo . listAppHostingConnections ( projectId ) ;
185
+ expect ( conns ) . to . have . length ( 2 ) ;
186
+ expect ( conns . map ( ( c ) => extractId ( c . name ) ) ) . to . include . members ( [
187
+ "frameworks-github-conn-baddcafe" ,
188
+ "frameworks-github-conn-deadbeef" ,
189
+ ] ) ;
190
+ } ) ;
191
+ } ) ;
133
192
} ) ;
0 commit comments