@@ -56,5 +56,39 @@ describe('File DB', () => {
5656 expect ( repoModule . db . findOne . calledWith ( sinon . match ( { url : 'https://github.com/finos/git-proxy.git' } ) ) ) . to . be . true ;
5757 expect ( result ) . to . equal ( repoData ) ;
5858 } ) ;
59+
60+ it ( 'should get the repo using the url, ignoring the case' , async ( ) => {
61+ const repoData = {
62+ name : 'sample' ,
63+ users : { canPush : [ ] } ,
64+ url : 'https://github.com/finos/git-proxy.git' ,
65+ } ;
66+
67+ sandbox . stub ( repoModule . db , 'findOne' ) . callsFake ( ( query , cb ) => cb ( null , repoData ) ) ;
68+
69+ const result = await repoModule . getRepoByUrl ( 'https://github.com/Finos/Git-Proxy.git' ) ;
70+ expect ( result ) . to . equal ( repoData ) ;
71+ expect ( repoModule . db . findOne . calledWith ( sinon . match ( { url : 'https://github.com/finos/git-proxy.git' } ) ) ) . to . be . true ;
72+ } ) ;
73+
74+ it ( 'should return null if the repo is not found' , async ( ) => {
75+ sandbox . stub ( repoModule . db , 'findOne' ) . callsFake ( ( query , cb ) => cb ( null , null ) ) ;
76+
77+ const result = await repoModule . getRepoByUrl ( 'https://github.com/finos/missing-repo.git' ) ;
78+ expect ( result ) . to . be . null ;
79+ expect ( repoModule . db . findOne . calledWith ( sinon . match ( { url : 'https://github.com/finos/missing-repo.git' } ) ) ,
80+ ) . to . be . true ;
81+ } ) ;
82+
83+ it ( 'should reject if the database returns an error' , async ( ) => {
84+ sandbox . stub ( repoModule . db , 'findOne' ) . callsFake ( ( query , cb ) => cb ( new Error ( 'DB error' ) ) ) ;
85+
86+ try {
87+ await repoModule . getRepoByUrl ( 'https://github.com/finos/git-proxy.git' ) ;
88+ expect . fail ( 'Expected promise to be rejected' ) ;
89+ } catch ( err ) {
90+ expect ( err . message ) . to . equal ( 'DB error' ) ;
91+ }
92+ } ) ;
5993 } ) ;
6094} ) ;
0 commit comments