1
1
import { 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
+ }
2
27
3
28
test ( "It loads repositories from data source" , async ( ) => {
4
29
let didLoadRepositories = false
@@ -9,7 +34,9 @@ test("It loads repositories from data source", async () => {
9
34
didLoadRepositories = true
10
35
return [ ]
11
36
}
12
- }
37
+ } ,
38
+ encryptionService : noopEncryptionService ,
39
+ remoteConfigEncoder : base64RemoteConfigEncoder
13
40
} )
14
41
await sut . getProjects ( )
15
42
expect ( didLoadRepositories ) . toBeTruthy ( )
@@ -43,7 +70,9 @@ test("It maps projects including branches and tags", async () => {
43
70
} ]
44
71
} ]
45
72
}
46
- }
73
+ } ,
74
+ encryptionService : noopEncryptionService ,
75
+ remoteConfigEncoder : base64RemoteConfigEncoder
47
76
} )
48
77
const projects = await sut . getProjects ( )
49
78
expect ( projects ) . toEqual ( [ {
@@ -107,7 +136,9 @@ test("It removes suffix from project name", async () => {
107
136
} ]
108
137
} ]
109
138
}
110
- }
139
+ } ,
140
+ encryptionService : noopEncryptionService ,
141
+ remoteConfigEncoder : base64RemoteConfigEncoder
111
142
} )
112
143
const projects = await sut . getProjects ( )
113
144
expect ( projects [ 0 ] . id ) . toEqual ( "acme-foo" )
@@ -147,7 +178,9 @@ test("It supports multiple OpenAPI specifications on a branch", async () => {
147
178
} ]
148
179
} ]
149
180
}
150
- }
181
+ } ,
182
+ encryptionService : noopEncryptionService ,
183
+ remoteConfigEncoder : base64RemoteConfigEncoder
151
184
} )
152
185
const projects = await sut . getProjects ( )
153
186
expect ( projects ) . toEqual ( [ {
@@ -209,7 +242,9 @@ test("It filters away projects with no versions", async () => {
209
242
tags : [ ]
210
243
} ]
211
244
}
212
- }
245
+ } ,
246
+ encryptionService : noopEncryptionService ,
247
+ remoteConfigEncoder : base64RemoteConfigEncoder
213
248
} )
214
249
const projects = await sut . getProjects ( )
215
250
expect ( projects . length ) . toEqual ( 0 )
@@ -243,7 +278,9 @@ test("It filters away branches with no specifications", async () => {
243
278
tags : [ ]
244
279
} ]
245
280
}
246
- }
281
+ } ,
282
+ encryptionService : noopEncryptionService ,
283
+ remoteConfigEncoder : base64RemoteConfigEncoder
247
284
} )
248
285
const projects = await sut . getProjects ( )
249
286
expect ( projects [ 0 ] . versions . length ) . toEqual ( 1 )
@@ -283,7 +320,9 @@ test("It filters away tags with no specifications", async () => {
283
320
} ]
284
321
} ]
285
322
}
286
- }
323
+ } ,
324
+ encryptionService : noopEncryptionService ,
325
+ remoteConfigEncoder : base64RemoteConfigEncoder
287
326
} )
288
327
const projects = await sut . getProjects ( )
289
328
expect ( projects [ 0 ] . versions . length ) . toEqual ( 2 )
@@ -314,7 +353,9 @@ test("It reads image from configuration file with .yml extension", async () => {
314
353
tags : [ ]
315
354
} ]
316
355
}
317
- }
356
+ } ,
357
+ encryptionService : noopEncryptionService ,
358
+ remoteConfigEncoder : base64RemoteConfigEncoder
318
359
} )
319
360
const projects = await sut . getProjects ( )
320
361
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
345
386
tags : [ ]
346
387
} ]
347
388
}
348
- }
389
+ } ,
390
+ encryptionService : noopEncryptionService ,
391
+ remoteConfigEncoder : base64RemoteConfigEncoder
349
392
} )
350
393
const projects = await sut . getProjects ( )
351
394
expect ( projects [ 0 ] . id ) . toEqual ( "acme-foo" )
@@ -378,7 +421,9 @@ test("It reads image from configuration file with .yaml extension", async () =>
378
421
tags : [ ]
379
422
} ]
380
423
}
381
- }
424
+ } ,
425
+ encryptionService : noopEncryptionService ,
426
+ remoteConfigEncoder : base64RemoteConfigEncoder
382
427
} )
383
428
const projects = await sut . getProjects ( )
384
429
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
409
454
tags : [ ]
410
455
} ]
411
456
}
412
- }
457
+ } ,
458
+ encryptionService : noopEncryptionService ,
459
+ remoteConfigEncoder : base64RemoteConfigEncoder
413
460
} )
414
461
const projects = await sut . getProjects ( )
415
462
expect ( projects [ 0 ] . id ) . toEqual ( "acme-foo" )
@@ -478,7 +525,9 @@ test("It sorts projects alphabetically", async () => {
478
525
tags : [ ]
479
526
} ]
480
527
}
481
- }
528
+ } ,
529
+ encryptionService : noopEncryptionService ,
530
+ remoteConfigEncoder : base64RemoteConfigEncoder
482
531
} )
483
532
const projects = await sut . getProjects ( )
484
533
expect ( projects [ 0 ] . name ) . toEqual ( "anne" )
@@ -529,7 +578,9 @@ test("It sorts versions alphabetically", async () => {
529
578
} ]
530
579
} ]
531
580
}
532
- }
581
+ } ,
582
+ encryptionService : noopEncryptionService ,
583
+ remoteConfigEncoder : base64RemoteConfigEncoder
533
584
} )
534
585
const projects = await sut . getProjects ( )
535
586
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
593
644
} ]
594
645
} ]
595
646
}
596
- }
647
+ } ,
648
+ encryptionService : noopEncryptionService ,
649
+ remoteConfigEncoder : base64RemoteConfigEncoder
597
650
} )
598
651
const projects = await sut . getProjects ( )
599
652
expect ( projects [ 0 ] . versions [ 0 ] . name ) . toEqual ( "main" )
@@ -641,7 +694,9 @@ test("It identifies the default branch in returned versions", async () => {
641
694
tags : [ ]
642
695
} ]
643
696
}
644
- }
697
+ } ,
698
+ encryptionService : noopEncryptionService ,
699
+ remoteConfigEncoder : base64RemoteConfigEncoder
645
700
} )
646
701
const projects = await sut . getProjects ( )
647
702
const defaultVersionNames = projects [ 0 ]
@@ -682,7 +737,9 @@ test("It adds remote versions from the project configuration", async () => {
682
737
tags : [ ]
683
738
} ]
684
739
}
685
- }
740
+ } ,
741
+ encryptionService : noopEncryptionService ,
742
+ remoteConfigEncoder : base64RemoteConfigEncoder
686
743
} )
687
744
const projects = await sut . getProjects ( )
688
745
expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -692,11 +749,11 @@ test("It adds remote versions from the project configuration", async () => {
692
749
specifications : [ {
693
750
id : "huey" ,
694
751
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" } ) } `
696
753
} , {
697
754
id : "dewey" ,
698
755
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" } ) } `
700
757
} ]
701
758
} , {
702
759
id : "bobby" ,
@@ -705,7 +762,7 @@ test("It adds remote versions from the project configuration", async () => {
705
762
specifications : [ {
706
763
id : "louie" ,
707
764
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" } ) } `
709
766
} ]
710
767
} ] )
711
768
} )
@@ -745,7 +802,9 @@ test("It modifies ID of remote version if the ID already exists", async () => {
745
802
tags : [ ]
746
803
} ]
747
804
}
748
- }
805
+ } ,
806
+ encryptionService : noopEncryptionService ,
807
+ remoteConfigEncoder : base64RemoteConfigEncoder
749
808
} )
750
809
const projects = await sut . getProjects ( )
751
810
expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -766,7 +825,7 @@ test("It modifies ID of remote version if the ID already exists", async () => {
766
825
specifications : [ {
767
826
id : "baz" ,
768
827
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" } ) } `
770
829
} ]
771
830
} , {
772
831
id : "bar2" ,
@@ -775,7 +834,7 @@ test("It modifies ID of remote version if the ID already exists", async () => {
775
834
specifications : [ {
776
835
id : "hello" ,
777
836
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" } ) } `
779
838
} ]
780
839
} ] )
781
840
} )
@@ -806,7 +865,9 @@ test("It lets users specify the ID of a remote version", async () => {
806
865
tags : [ ]
807
866
} ]
808
867
}
809
- }
868
+ } ,
869
+ encryptionService : noopEncryptionService ,
870
+ remoteConfigEncoder : base64RemoteConfigEncoder
810
871
} )
811
872
const projects = await sut . getProjects ( )
812
873
expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -816,7 +877,7 @@ test("It lets users specify the ID of a remote version", async () => {
816
877
specifications : [ {
817
878
id : "baz" ,
818
879
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" } ) } `
820
881
} ]
821
882
} ] )
822
883
} )
@@ -847,7 +908,9 @@ test("It lets users specify the ID of a remote specification", async () => {
847
908
tags : [ ]
848
909
} ]
849
910
}
850
- }
911
+ } ,
912
+ encryptionService : noopEncryptionService ,
913
+ remoteConfigEncoder : base64RemoteConfigEncoder
851
914
} )
852
915
const projects = await sut . getProjects ( )
853
916
expect ( projects [ 0 ] . versions ) . toEqual ( [ {
@@ -857,7 +920,7 @@ test("It lets users specify the ID of a remote specification", async () => {
857
920
specifications : [ {
858
921
id : "some-spec" ,
859
922
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" } ) } `
861
924
} ]
862
925
} ] )
863
926
} )
0 commit comments