6
6
} from "../../../src/common/github-url-identifier-helper" ;
7
7
8
8
describe ( "github url identifier helper" , ( ) => {
9
+ const githubUrl = new URL ( "https://github.com" ) ;
10
+
9
11
describe ( "valid GitHub Nwo Or Owner method" , ( ) => {
10
12
it ( "should return true for valid owner" , ( ) => {
11
13
expect ( isValidGitHubOwner ( "github" ) ) . toBe ( true ) ;
@@ -23,51 +25,96 @@ describe("github url identifier helper", () => {
23
25
24
26
describe ( "getNwoFromGitHubUrl method" , ( ) => {
25
27
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 (
28
36
undefined ,
29
37
) ;
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 ) ;
33
40
} ) ;
34
41
35
42
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 (
41
50
"foo/bar" ,
42
51
) ;
43
- expect ( getNwoFromGitHubUrl ( "https ://github.com/foo/bar/sub/pages" ) ) . toBe (
52
+ expect ( getNwoFromGitHubUrl ( "http ://github.com/foo/bar" , githubUrl ) ) . toBe (
44
53
"foo/bar" ,
45
54
) ;
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" ) ;
46
67
} ) ;
47
68
} ) ;
48
69
49
70
describe ( "getOwnerFromGitHubUrl method" , ( ) => {
50
71
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 ) ;
57
81
} ) ;
58
82
59
83
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 (
63
104
"foo" ,
64
105
) ;
65
106
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
+ ) ,
67
117
) . 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" ) ;
71
118
} ) ;
72
119
} ) ;
73
120
} ) ;
0 commit comments