11import { GitHubProjectDataSource } from "@/features/projects/data"
2+ import RemoteConfig from "@/features/projects/domain/RemoteConfig"
3+
4+ /**
5+ * Simple encryption service for testing. Does nothing.
6+ */
7+ const noopEncryptionService = {
8+ encrypt : function ( data : string ) : string {
9+ return data
10+ } ,
11+ decrypt : function ( encryptedDataBase64 : string ) : string {
12+ return encryptedDataBase64
13+ }
14+ }
15+
16+ /**
17+ * Simple encoder for testing
18+ */
19+ const base64RemoteConfigEncoder = {
20+ encode : function ( remoteConfig : RemoteConfig ) : string {
21+ return Buffer . from ( JSON . stringify ( remoteConfig ) ) . toString ( "base64" )
22+ } ,
23+ decode : function ( encodedString : string ) : RemoteConfig {
24+ return JSON . parse ( Buffer . from ( encodedString , "base64" ) . toString ( ) )
25+ }
26+ }
227
328test ( "It loads repositories from data source" , async ( ) => {
429 let didLoadRepositories = false
@@ -9,7 +34,9 @@ test("It loads repositories from data source", async () => {
934 didLoadRepositories = true
1035 return [ ]
1136 }
12- }
37+ } ,
38+ encryptionService : noopEncryptionService ,
39+ remoteConfigEncoder : base64RemoteConfigEncoder
1340 } )
1441 await sut . getProjects ( )
1542 expect ( didLoadRepositories ) . toBeTruthy ( )
@@ -43,7 +70,9 @@ test("It maps projects including branches and tags", async () => {
4370 } ]
4471 } ]
4572 }
46- }
73+ } ,
74+ encryptionService : noopEncryptionService ,
75+ remoteConfigEncoder : base64RemoteConfigEncoder
4776 } )
4877 const projects = await sut . getProjects ( )
4978 expect ( projects ) . toEqual ( [ {
@@ -107,7 +136,9 @@ test("It removes suffix from project name", async () => {
107136 } ]
108137 } ]
109138 }
110- }
139+ } ,
140+ encryptionService : noopEncryptionService ,
141+ remoteConfigEncoder : base64RemoteConfigEncoder
111142 } )
112143 const projects = await sut . getProjects ( )
113144 expect ( projects [ 0 ] . id ) . toEqual ( "acme-foo" )
@@ -147,7 +178,9 @@ test("It supports multiple OpenAPI specifications on a branch", async () => {
147178 } ]
148179 } ]
149180 }
150- }
181+ } ,
182+ encryptionService : noopEncryptionService ,
183+ remoteConfigEncoder : base64RemoteConfigEncoder
151184 } )
152185 const projects = await sut . getProjects ( )
153186 expect ( projects ) . toEqual ( [ {
@@ -209,7 +242,9 @@ test("It filters away projects with no versions", async () => {
209242 tags : [ ]
210243 } ]
211244 }
212- }
245+ } ,
246+ encryptionService : noopEncryptionService ,
247+ remoteConfigEncoder : base64RemoteConfigEncoder
213248 } )
214249 const projects = await sut . getProjects ( )
215250 expect ( projects . length ) . toEqual ( 0 )
@@ -243,7 +278,9 @@ test("It filters away branches with no specifications", async () => {
243278 tags : [ ]
244279 } ]
245280 }
246- }
281+ } ,
282+ encryptionService : noopEncryptionService ,
283+ remoteConfigEncoder : base64RemoteConfigEncoder
247284 } )
248285 const projects = await sut . getProjects ( )
249286 expect ( projects [ 0 ] . versions . length ) . toEqual ( 1 )
@@ -283,7 +320,9 @@ test("It filters away tags with no specifications", async () => {
283320 } ]
284321 } ]
285322 }
286- }
323+ } ,
324+ encryptionService : noopEncryptionService ,
325+ remoteConfigEncoder : base64RemoteConfigEncoder
287326 } )
288327 const projects = await sut . getProjects ( )
289328 expect ( projects [ 0 ] . versions . length ) . toEqual ( 2 )
@@ -314,7 +353,9 @@ test("It reads image from configuration file with .yml extension", async () => {
314353 tags : [ ]
315354 } ]
316355 }
317- }
356+ } ,
357+ encryptionService : noopEncryptionService ,
358+ remoteConfigEncoder : base64RemoteConfigEncoder
318359 } )
319360 const projects = await sut . getProjects ( )
320361 expect ( projects [ 0 ] . imageURL ) . toEqual ( "/api/blob/acme/foo-openapi/icon.png?ref=12345678" )
@@ -345,7 +386,9 @@ test("It reads display name from configuration file with .yml extension", async
345386 tags : [ ]
346387 } ]
347388 }
348- }
389+ } ,
390+ encryptionService : noopEncryptionService ,
391+ remoteConfigEncoder : base64RemoteConfigEncoder
349392 } )
350393 const projects = await sut . getProjects ( )
351394 expect ( projects [ 0 ] . id ) . toEqual ( "acme-foo" )
@@ -378,7 +421,9 @@ test("It reads image from configuration file with .yaml extension", async () =>
378421 tags : [ ]
379422 } ]
380423 }
381- }
424+ } ,
425+ encryptionService : noopEncryptionService ,
426+ remoteConfigEncoder : base64RemoteConfigEncoder
382427 } )
383428 const projects = await sut . getProjects ( )
384429 expect ( projects [ 0 ] . imageURL ) . toEqual ( "/api/blob/acme/foo-openapi/icon.png?ref=12345678" )
@@ -409,7 +454,9 @@ test("It reads display name from configuration file with .yaml extension", async
409454 tags : [ ]
410455 } ]
411456 }
412- }
457+ } ,
458+ encryptionService : noopEncryptionService ,
459+ remoteConfigEncoder : base64RemoteConfigEncoder
413460 } )
414461 const projects = await sut . getProjects ( )
415462 expect ( projects [ 0 ] . id ) . toEqual ( "acme-foo" )
@@ -478,7 +525,9 @@ test("It sorts projects alphabetically", async () => {
478525 tags : [ ]
479526 } ]
480527 }
481- }
528+ } ,
529+ encryptionService : noopEncryptionService ,
530+ remoteConfigEncoder : base64RemoteConfigEncoder
482531 } )
483532 const projects = await sut . getProjects ( )
484533 expect ( projects [ 0 ] . name ) . toEqual ( "anne" )
@@ -529,7 +578,9 @@ test("It sorts versions alphabetically", async () => {
529578 } ]
530579 } ]
531580 }
532- }
581+ } ,
582+ encryptionService : noopEncryptionService ,
583+ remoteConfigEncoder : base64RemoteConfigEncoder
533584 } )
534585 const projects = await sut . getProjects ( )
535586 expect ( projects [ 0 ] . versions [ 0 ] . name ) . toEqual ( "1.0" )
@@ -593,7 +644,9 @@ test("It prioritizes main, master, develop, and development branch names when so
593644 } ]
594645 } ]
595646 }
596- }
647+ } ,
648+ encryptionService : noopEncryptionService ,
649+ remoteConfigEncoder : base64RemoteConfigEncoder
597650 } )
598651 const projects = await sut . getProjects ( )
599652 expect ( projects [ 0 ] . versions [ 0 ] . name ) . toEqual ( "main" )
@@ -641,7 +694,9 @@ test("It identifies the default branch in returned versions", async () => {
641694 tags : [ ]
642695 } ]
643696 }
644- }
697+ } ,
698+ encryptionService : noopEncryptionService ,
699+ remoteConfigEncoder : base64RemoteConfigEncoder
645700 } )
646701 const projects = await sut . getProjects ( )
647702 const defaultVersionNames = projects [ 0 ]
@@ -682,7 +737,9 @@ test("It adds remote versions from the project configuration", async () => {
682737 tags : [ ]
683738 } ]
684739 }
685- }
740+ } ,
741+ encryptionService : noopEncryptionService ,
742+ remoteConfigEncoder : base64RemoteConfigEncoder
686743 } )
687744 const projects = await sut . getProjects ( )
688745 expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -692,11 +749,11 @@ test("It adds remote versions from the project configuration", async () => {
692749 specifications : [ {
693750 id : "huey" ,
694751 name : "Huey" ,
695- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/huey.yml" ) } `
752+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/huey.yml" } ) } `
696753 } , {
697754 id : "dewey" ,
698755 name : "Dewey" ,
699- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/dewey.yml" ) } `
756+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/dewey.yml" } ) } `
700757 } ]
701758 } , {
702759 id : "bobby" ,
@@ -705,7 +762,7 @@ test("It adds remote versions from the project configuration", async () => {
705762 specifications : [ {
706763 id : "louie" ,
707764 name : "Louie" ,
708- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/louie.yml" ) } `
765+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/louie.yml" } ) } `
709766 } ]
710767 } ] )
711768} )
@@ -745,7 +802,9 @@ test("It modifies ID of remote version if the ID already exists", async () => {
745802 tags : [ ]
746803 } ]
747804 }
748- }
805+ } ,
806+ encryptionService : noopEncryptionService ,
807+ remoteConfigEncoder : base64RemoteConfigEncoder
749808 } )
750809 const projects = await sut . getProjects ( )
751810 expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -766,7 +825,7 @@ test("It modifies ID of remote version if the ID already exists", async () => {
766825 specifications : [ {
767826 id : "baz" ,
768827 name : "Baz" ,
769- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/baz.yml" ) } `
828+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/baz.yml" } ) } `
770829 } ]
771830 } , {
772831 id : "bar2" ,
@@ -775,7 +834,7 @@ test("It modifies ID of remote version if the ID already exists", async () => {
775834 specifications : [ {
776835 id : "hello" ,
777836 name : "Hello" ,
778- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/hello.yml" ) } `
837+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/hello.yml" } ) } `
779838 } ]
780839 } ] )
781840} )
@@ -806,7 +865,9 @@ test("It lets users specify the ID of a remote version", async () => {
806865 tags : [ ]
807866 } ]
808867 }
809- }
868+ } ,
869+ encryptionService : noopEncryptionService ,
870+ remoteConfigEncoder : base64RemoteConfigEncoder
810871 } )
811872 const projects = await sut . getProjects ( )
812873 expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -816,7 +877,7 @@ test("It lets users specify the ID of a remote version", async () => {
816877 specifications : [ {
817878 id : "baz" ,
818879 name : "Baz" ,
819- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/baz.yml" ) } `
880+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/baz.yml" } ) } `
820881 } ]
821882 } ] )
822883} )
@@ -847,7 +908,9 @@ test("It lets users specify the ID of a remote specification", async () => {
847908 tags : [ ]
848909 } ]
849910 }
850- }
911+ } ,
912+ encryptionService : noopEncryptionService ,
913+ remoteConfigEncoder : base64RemoteConfigEncoder
851914 } )
852915 const projects = await sut . getProjects ( )
853916 expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -857,7 +920,7 @@ test("It lets users specify the ID of a remote specification", async () => {
857920 specifications : [ {
858921 id : "some-spec" ,
859922 name : "Baz" ,
860- url : `/api/proxy?url= ${ encodeURIComponent ( "https://example.com/baz.yml" ) } `
923+ url : `/api/remotes/ ${ base64RemoteConfigEncoder . encode ( { url : "https://example.com/baz.yml" } ) } `
861924 } ]
862925 } ] )
863926} )
0 commit comments