import { app } from 'egg-mock/bootstrap' ; import { InstallationType } from '../../app/plugin/installation-manager/types' ; import { Agent } from 'egg' ; import { initWebhooks } from '../plugin/github/GitHubTestUtil' ; import { prepareTestApplication , testClear } from '../Util' ; import { MockApplication } from 'egg-mock' ; describe ( 'Component Controller' , ( ) => { class MockCompService { getLatestConfigStructure ( ) { return { foo : 'bar' } ; } getConfigStructureByVersion ( name , version ) { return { name , version } ; } } class MockPlatform { compService : MockCompService ; constructor ( ) { this . compService = new MockCompService ( ) ; } } beforeEach ( async ( ) => { app . installation . getInstallationInfoByName = ( iName ) : { id : number ; type : InstallationType ; } => { return { id : 0 , type : iName as any } ; } ; app . github . getHostPlatform = ( _ ) : any => { return new MockPlatform ( ) ; } ; app . gitlab . getHostPlatform = ( _ ) : any => { return new MockPlatform ( ) ; } ; } ) ; describe ( 'GET /component/:installationName' , ( ) => { it ( 'should status 200 and get the body' , ( ) => { return app . httpRequest ( ) . get ( '/component/github' ) . expect ( 200 ) . expect ( { foo : 'bar' } ) ; } ) ; it ( 'should status 200 and get the body' , ( ) => { return app . httpRequest ( ) . get ( '/component/gitlab' ) . expect ( 200 ) . expect ( { foo : 'bar' } ) ; } ) ; it ( 'should status 200 and get {}' , ( ) => { return app . httpRequest ( ) . get ( '/component/not_exist' ) . expect ( 200 ) . expect ( { } ) ; } ) ; } ) ; describe ( 'GET /component/:installationName/:name/:version' , ( ) => { it ( 'should status 200 and get the body' , ( ) => { return app . httpRequest ( ) . get ( '/component/github/testRepo/1' ) . expect ( 200 ) . expect ( { name : 'testRepo' , version : '1' } ) ; } ) ; it ( 'should status 200 and get the body' , ( ) => { return app . httpRequest ( ) . get ( '/component/gitlab/testRepo/1' ) . expect ( 200 ) . expect ( { name : 'testRepo' , version : '1' } ) ; } ) ; it ( 'should status 200 and get {}' , ( ) => { return app . httpRequest ( ) . get ( '/component/not_exist/testRepo/1' ) . expect ( 200 ) . expect ( { } ) ; } ) ; } ) ; } ) ; describe ( 'Real Component Controller' , ( ) => { let app ; let agent ; before ( async ( ) => { ( { app , agent } = await prepareTestApplication ( ) as any ) ; await initWebhooks ( app ) ; } ) ; after ( ( ) => { testClear ( app , agent ) ; } ) ; describe ( 'GET /component/:installationName' , ( ) => { it ( 'should status 200 and get the body' , ( ) => { return app . httpRequest ( ) . get ( '/component/github' ) . expect ( 200 ) ; } ) ; } ) ; describe ( 'GET /component/:installationName/:name/:version' , ( ) => { it ( 'should status 200 and get the body' , ( ) => { return app . httpRequest ( ) . get ( '/component/github/approve/1' ) . expect ( 200 ) ; } ) ; } ) ; } ) ;