66} from "../../../src/common/github-url-identifier-helper" ;
77
88describe ( "github url identifier helper" , ( ) => {
9+ const githubUrl = new URL ( "https://github.com" ) ;
10+
911 describe ( "valid GitHub Nwo Or Owner method" , ( ) => {
1012 it ( "should return true for valid owner" , ( ) => {
1113 expect ( isValidGitHubOwner ( "github" ) ) . toBe ( true ) ;
@@ -23,51 +25,96 @@ describe("github url identifier helper", () => {
2325
2426 describe ( "getNwoFromGitHubUrl method" , ( ) => {
2527 it ( "should handle invalid urls" , ( ) => {
26- expect ( getNwoFromGitHubUrl ( "" ) ) . toBe ( undefined ) ;
27- expect ( getNwoFromGitHubUrl ( "https://ww.github.com/foo/bar" ) ) . toBe (
28+ expect ( getNwoFromGitHubUrl ( "" , githubUrl ) ) . toBe ( undefined ) ;
29+ expect (
30+ getNwoFromGitHubUrl ( "https://ww.github.com/foo/bar" , githubUrl ) ,
31+ ) . toBe ( undefined ) ;
32+ expect (
33+ getNwoFromGitHubUrl ( "https://tenant.ghe.com/foo/bar" , githubUrl ) ,
34+ ) . toBe ( undefined ) ;
35+ expect ( getNwoFromGitHubUrl ( "https://www.github.com/foo" , githubUrl ) ) . toBe (
2836 undefined ,
2937 ) ;
30- expect ( getNwoFromGitHubUrl ( "https://www.github.com/foo" ) ) . toBe ( undefined ) ;
31- expect ( getNwoFromGitHubUrl ( "foo" ) ) . toBe ( undefined ) ;
32- expect ( getNwoFromGitHubUrl ( "foo/bar" ) ) . toBe ( undefined ) ;
38+ expect ( getNwoFromGitHubUrl ( "foo" , githubUrl ) ) . toBe ( undefined ) ;
39+ expect ( getNwoFromGitHubUrl ( "foo/bar" , githubUrl ) ) . toBe ( undefined ) ;
3340 } ) ;
3441
3542 it ( "should handle valid urls" , ( ) => {
36- expect ( getNwoFromGitHubUrl ( "github.com/foo/bar" ) ) . toBe ( "foo/bar" ) ;
37- expect ( getNwoFromGitHubUrl ( "www.github.com/foo/bar" ) ) . toBe ( "foo/bar" ) ;
38- expect ( getNwoFromGitHubUrl ( "https://github.com/foo/bar" ) ) . toBe ( "foo/bar" ) ;
39- expect ( getNwoFromGitHubUrl ( "http://github.com/foo/bar" ) ) . toBe ( "foo/bar" ) ;
40- expect ( getNwoFromGitHubUrl ( "https://www.github.com/foo/bar" ) ) . toBe (
43+ expect ( getNwoFromGitHubUrl ( "github.com/foo/bar" , githubUrl ) ) . toBe (
44+ "foo/bar" ,
45+ ) ;
46+ expect ( getNwoFromGitHubUrl ( "www.github.com/foo/bar" , githubUrl ) ) . toBe (
47+ "foo/bar" ,
48+ ) ;
49+ expect ( getNwoFromGitHubUrl ( "https://github.com/foo/bar" , githubUrl ) ) . toBe (
4150 "foo/bar" ,
4251 ) ;
43- expect ( getNwoFromGitHubUrl ( "https ://github.com/foo/bar/sub/pages" ) ) . toBe (
52+ expect ( getNwoFromGitHubUrl ( "http ://github.com/foo/bar" , githubUrl ) ) . toBe (
4453 "foo/bar" ,
4554 ) ;
55+ expect (
56+ getNwoFromGitHubUrl ( "https://www.github.com/foo/bar" , githubUrl ) ,
57+ ) . toBe ( "foo/bar" ) ;
58+ expect (
59+ getNwoFromGitHubUrl ( "https://github.com/foo/bar/sub/pages" , githubUrl ) ,
60+ ) . toBe ( "foo/bar" ) ;
61+ expect (
62+ getNwoFromGitHubUrl (
63+ "https://tenant.ghe.com/foo/bar" ,
64+ new URL ( "https://tenant.ghe.com" ) ,
65+ ) ,
66+ ) . toBe ( "foo/bar" ) ;
4667 } ) ;
4768 } ) ;
4869
4970 describe ( "getOwnerFromGitHubUrl method" , ( ) => {
5071 it ( "should handle invalid urls" , ( ) => {
51- expect ( getOwnerFromGitHubUrl ( "" ) ) . toBe ( undefined ) ;
52- expect ( getOwnerFromGitHubUrl ( "https://ww.github.com/foo/bar" ) ) . toBe (
53- undefined ,
54- ) ;
55- expect ( getOwnerFromGitHubUrl ( "foo" ) ) . toBe ( undefined ) ;
56- expect ( getOwnerFromGitHubUrl ( "foo/bar" ) ) . toBe ( undefined ) ;
72+ expect ( getOwnerFromGitHubUrl ( "" , githubUrl ) ) . toBe ( undefined ) ;
73+ expect (
74+ getOwnerFromGitHubUrl ( "https://ww.github.com/foo/bar" , githubUrl ) ,
75+ ) . toBe ( undefined ) ;
76+ expect (
77+ getOwnerFromGitHubUrl ( "https://tenant.ghe.com/foo/bar" , githubUrl ) ,
78+ ) . toBe ( undefined ) ;
79+ expect ( getOwnerFromGitHubUrl ( "foo" , githubUrl ) ) . toBe ( undefined ) ;
80+ expect ( getOwnerFromGitHubUrl ( "foo/bar" , githubUrl ) ) . toBe ( undefined ) ;
5781 } ) ;
5882
5983 it ( "should handle valid urls" , ( ) => {
60- expect ( getOwnerFromGitHubUrl ( "http://github.com/foo/bar" ) ) . toBe ( "foo" ) ;
61- expect ( getOwnerFromGitHubUrl ( "https://github.com/foo/bar" ) ) . toBe ( "foo" ) ;
62- expect ( getOwnerFromGitHubUrl ( "https://www.github.com/foo/bar" ) ) . toBe (
84+ expect (
85+ getOwnerFromGitHubUrl ( "http://github.com/foo/bar" , githubUrl ) ,
86+ ) . toBe ( "foo" ) ;
87+ expect (
88+ getOwnerFromGitHubUrl ( "https://github.com/foo/bar" , githubUrl ) ,
89+ ) . toBe ( "foo" ) ;
90+ expect (
91+ getOwnerFromGitHubUrl ( "https://www.github.com/foo/bar" , githubUrl ) ,
92+ ) . toBe ( "foo" ) ;
93+ expect (
94+ getOwnerFromGitHubUrl (
95+ "https://github.com/foo/bar/sub/pages" ,
96+ githubUrl ,
97+ ) ,
98+ ) . toBe ( "foo" ) ;
99+ expect (
100+ getOwnerFromGitHubUrl ( "https://www.github.com/foo" , githubUrl ) ,
101+ ) . toBe ( "foo" ) ;
102+ expect ( getOwnerFromGitHubUrl ( "github.com/foo" , githubUrl ) ) . toBe ( "foo" ) ;
103+ expect ( getOwnerFromGitHubUrl ( "www.github.com/foo" , githubUrl ) ) . toBe (
63104 "foo" ,
64105 ) ;
65106 expect (
66- getOwnerFromGitHubUrl ( "https://github.com/foo/bar/sub/pages" ) ,
107+ getOwnerFromGitHubUrl (
108+ "https://tenant.ghe.com/foo/bar" ,
109+ new URL ( "https://tenant.ghe.com" ) ,
110+ ) ,
111+ ) . toBe ( "foo" ) ;
112+ expect (
113+ getOwnerFromGitHubUrl (
114+ "https://tenant.ghe.com/foo" ,
115+ new URL ( "https://tenant.ghe.com" ) ,
116+ ) ,
67117 ) . toBe ( "foo" ) ;
68- expect ( getOwnerFromGitHubUrl ( "https://www.github.com/foo" ) ) . toBe ( "foo" ) ;
69- expect ( getOwnerFromGitHubUrl ( "github.com/foo" ) ) . toBe ( "foo" ) ;
70- expect ( getOwnerFromGitHubUrl ( "www.github.com/foo" ) ) . toBe ( "foo" ) ;
71118 } ) ;
72119 } ) ;
73120} ) ;
0 commit comments