22 getBaseApiUrl ,
33 getV1ApiUrl ,
44 getRestApiUrl ,
5+ getRootUrl ,
56} from '../../../../src/lib/config/api-url' ;
67
78const urls = [
@@ -10,72 +11,84 @@ const urls = [
1011 expectedBase : 'https://snyk.io/api/' ,
1112 expectedV1 : 'https://snyk.io/api/v1' ,
1213 expectedRest : 'https://api.snyk.io/rest' ,
14+ expectedRoot : 'https://snyk.io' ,
1315 } ,
1416 {
1517 userInput : 'https://snyk.io/api' ,
1618 expectedBase : 'https://snyk.io/api' ,
1719 expectedV1 : 'https://snyk.io/api/v1' ,
1820 expectedRest : 'https://api.snyk.io/rest' ,
21+ expectedRoot : 'https://snyk.io' ,
1922 } ,
2023 {
2124 userInput : 'https://app.snyk.io/api' ,
2225 expectedBase : 'https://app.snyk.io/api' ,
2326 expectedV1 : 'https://app.snyk.io/api/v1' ,
2427 expectedRest : 'https://api.snyk.io/rest' ,
28+ expectedRoot : 'https://app.snyk.io' ,
2529 } ,
2630 {
2731 userInput : 'https://app.snyk.io/api/v1' ,
2832 expectedBase : 'https://app.snyk.io/api/' ,
2933 expectedV1 : 'https://app.snyk.io/api/v1' ,
3034 expectedRest : 'https://api.snyk.io/rest' ,
35+ expectedRoot : 'https://app.snyk.io' ,
3136 } ,
3237 {
3338 userInput : 'https://api.snyk.io/v1' ,
3439 expectedBase : 'https://api.snyk.io/' ,
3540 expectedV1 : 'https://api.snyk.io/v1' ,
3641 expectedRest : 'https://api.snyk.io/rest' ,
42+ expectedRoot : 'https://snyk.io' ,
3743 } ,
3844 {
3945 userInput : 'https://api.snyk.io' ,
4046 expectedBase : 'https://api.snyk.io' ,
4147 expectedV1 : 'https://api.snyk.io/v1' ,
4248 expectedRest : 'https://api.snyk.io/rest' ,
49+ expectedRoot : 'https://snyk.io' ,
4350 } ,
4451 {
4552 userInput : 'https://api.snyk.io/' ,
4653 expectedBase : 'https://api.snyk.io/' ,
4754 expectedV1 : 'https://api.snyk.io/v1' ,
4855 expectedRest : 'https://api.snyk.io/rest' ,
56+ expectedRoot : 'https://snyk.io' ,
4957 } ,
5058 {
5159 userInput : 'https://api.custom.snyk.io' ,
5260 expectedBase : 'https://api.custom.snyk.io' ,
5361 expectedV1 : 'https://api.custom.snyk.io/v1' ,
5462 expectedRest : 'https://api.custom.snyk.io/rest' ,
63+ expectedRoot : 'https://custom.snyk.io' ,
5564 } ,
5665 {
5766 userInput : 'http://localhost:9000/' ,
5867 expectedBase : 'http://localhost:9000/' ,
5968 expectedV1 : 'http://localhost:9000/v1' ,
6069 expectedRest : 'http://localhost:9000/rest' ,
70+ expectedRoot : 'http://localhost:9000' ,
6171 } ,
6272 {
6373 userInput : 'http://localhost:9000/api/v1' ,
6474 expectedBase : 'http://localhost:9000/api/' ,
6575 expectedV1 : 'http://localhost:9000/api/v1' ,
6676 expectedRest : 'http://localhost:9000/rest' ,
77+ expectedRoot : 'http://localhost:9000' ,
6778 } ,
6879 {
6980 userInput : 'http://alpha:omega@localhost:9000' ,
7081 expectedBase : 'http://alpha:omega@localhost:9000' ,
7182 expectedV1 : 'http://alpha:omega@localhost:9000/v1' ,
7283 expectedRest : 'http://alpha:omega@localhost:9000/rest' ,
84+ expectedRoot : 'http://localhost:9000' ,
7385 } ,
7486 {
7587 userInput : 'https://app.dev.snyk.io/api/v1' ,
7688 expectedBase : 'https://app.dev.snyk.io/api/' ,
7789 expectedV1 : 'https://app.dev.snyk.io/api/v1' ,
7890 expectedRest : 'https://api.dev.snyk.io/rest' ,
91+ expectedRoot : 'https://app.dev.snyk.io' ,
7992 } ,
8093] ;
8194
@@ -152,4 +165,12 @@ describe('CLI config - API URL', () => {
152165 } ) ;
153166 } ) ;
154167 } ) ;
168+
169+ describe ( 'getRootUrl' , ( ) => {
170+ urls . forEach ( ( url ) => {
171+ it ( `returns ROOT URL ${ url . userInput } ` , ( ) => {
172+ expect ( getRootUrl ( url . userInput ) ) . toEqual ( url . expectedRoot ) ;
173+ } ) ;
174+ } ) ;
175+ } ) ;
155176} ) ;
0 commit comments