@@ -4,46 +4,51 @@ import { expect } from "chai";
44import * as gcb from "../../../gcp/cloudbuild" ;
55import * as prompt from "../../../prompt" ;
66import * as poller from "../../../operation-poller" ;
7- import { FirebaseError } from "../../../error" ;
87import * as repo from "../../../init/features/frameworks/repo" ;
98import * as utils from "../../../utils" ;
9+ import { Connection } from "../../../gcp/cloudbuild" ;
10+ import { FirebaseError } from "../../../error" ;
1011
1112describe ( "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 ( ) ;
4115
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+ } ) ;
4551
46- describe ( "connect GitHub repo" , ( ) => {
4752 const projectId = "projectId" ;
4853 const location = "us-central1" ;
4954 const connectionId = `frameworks-${ location } ` ;
@@ -130,4 +135,58 @@ describe("composer", () => {
130135 await expect ( repo . linkGitHubRepository ( projectId , location ) ) . to . be . rejected ;
131136 } ) ;
132137 } ) ;
138+
139+ describe ( "listFrameworksConnections" , ( ) => {
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-frameworks 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 . listFrameworksConnections ( 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+ } ) ;
133192} ) ;
0 commit comments