@@ -15,11 +15,13 @@ afterEach(() => {
15
15
describe ( 'GithubClient' , ( ) => {
16
16
it ( 'should initialise a GithubClient' , ( ) => {
17
17
const github = new GithubClient ( ) ;
18
+ const githubEnterprise = new GithubClient ( { enterprise : true } ) ;
18
19
expect ( github ) . toBeInstanceOf ( GithubClient ) ;
20
+ expect ( githubEnterprise ) . toBeInstanceOf ( GithubClient ) ;
19
21
} ) ;
20
22
21
23
describe ( '#client' , ( ) => {
22
- it ( 'it should contain a client' , ( ) => {
24
+ it ( 'it should contain a grafana client' , ( ) => {
23
25
// @ts -ignore
24
26
const spy = jest . spyOn ( GithubClient . prototype , 'createClient' ) . mockImplementation ( ( ) => fakeClient ) ;
25
27
@@ -33,6 +35,20 @@ describe('GithubClient', () => {
33
35
expect ( client ) . toEqual ( fakeClient ) ;
34
36
} ) ;
35
37
38
+ it ( 'it should contain a grafana enterprise client' , ( ) => {
39
+ // @ts -ignore
40
+ const spy = jest . spyOn ( GithubClient . prototype , 'createClient' ) . mockImplementation ( ( ) => fakeClient ) ;
41
+
42
+ const github = new GithubClient ( { enterprise : true } ) ;
43
+ const client = github . client ;
44
+
45
+ expect ( spy ) . toHaveBeenCalledWith ( {
46
+ baseURL : 'https://api.github.com/repos/grafana/grafana-enterprise' ,
47
+ timeout : 10000 ,
48
+ } ) ;
49
+ expect ( client ) . toEqual ( fakeClient ) ;
50
+ } ) ;
51
+
36
52
describe ( 'when the credentials are required' , ( ) => {
37
53
it ( 'should create the client when the credentials are defined' , ( ) => {
38
54
const username = 'grafana' ;
@@ -44,7 +60,7 @@ describe('GithubClient', () => {
44
60
// @ts -ignore
45
61
const spy = jest . spyOn ( GithubClient . prototype , 'createClient' ) . mockImplementation ( ( ) => fakeClient ) ;
46
62
47
- const github = new GithubClient ( true ) ;
63
+ const github = new GithubClient ( { required : true } ) ;
48
64
const client = github . client ;
49
65
50
66
expect ( spy ) . toHaveBeenCalledWith ( {
@@ -56,11 +72,33 @@ describe('GithubClient', () => {
56
72
expect ( client ) . toEqual ( fakeClient ) ;
57
73
} ) ;
58
74
75
+ it ( 'should create the enterprise client when the credentials are defined' , ( ) => {
76
+ const username = 'grafana' ;
77
+ const token = 'averysecureaccesstoken' ;
78
+
79
+ process . env . GITHUB_USERNAME = username ;
80
+ process . env . GITHUB_ACCESS_TOKEN = token ;
81
+
82
+ // @ts -ignore
83
+ const spy = jest . spyOn ( GithubClient . prototype , 'createClient' ) . mockImplementation ( ( ) => fakeClient ) ;
84
+
85
+ const github = new GithubClient ( { required : true , enterprise : true } ) ;
86
+ const client = github . client ;
87
+
88
+ expect ( spy ) . toHaveBeenCalledWith ( {
89
+ baseURL : 'https://api.github.com/repos/grafana/grafana-enterprise' ,
90
+ timeout : 10000 ,
91
+ auth : { username, password : token } ,
92
+ } ) ;
93
+
94
+ expect ( client ) . toEqual ( fakeClient ) ;
95
+ } ) ;
96
+
59
97
describe ( 'when the credentials are not defined' , ( ) => {
60
98
it ( 'should throw an error' , ( ) => {
61
99
expect ( ( ) => {
62
100
// tslint:disable-next-line
63
- new GithubClient ( true ) ;
101
+ new GithubClient ( { required : true } ) ;
64
102
} ) . toThrow ( / o p e r a t i o n n e e d s a G I T H U B _ U S E R N A M E a n d G I T H U B _ A C C E S S _ T O K E N e n v i r o n m e n t v a r i a b l e s / ) ;
65
103
} ) ;
66
104
} ) ;
0 commit comments