1- import Collaborators from '../../../../lib/plugins/collaborators'
21import { jest } from '@jest/globals'
2+ import { when } from 'jest-when'
3+
4+ import Collaborators from '../../../../lib/plugins/collaborators'
35
46describe ( 'Collaborators' , ( ) => {
57 let github
8+ const repoOwner = 'bkeepers'
9+ const repoName = 'test'
610
711 function configure ( config ) {
8- return new Collaborators ( github , { owner : 'bkeepers' , repo : 'test' } , config )
12+ return new Collaborators ( github , { owner : repoOwner , repo : repoName } , config )
913 }
1014
1115 beforeEach ( ( ) => {
12- github = {
13- repos : {
14- listCollaborators : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( [ ] ) ) ,
15- removeCollaborator : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ,
16- addCollaborator : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) )
17- }
18- }
16+ github = { request : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) ) }
1917 } )
2018
2119 describe ( 'sync' , ( ) => {
@@ -27,41 +25,41 @@ describe('Collaborators', () => {
2725 { username : 'DIFFERENTcase' , permission : 'push' }
2826 ] )
2927
30- github . repos . listCollaborators . mockReturnValueOnce (
31- Promise . resolve ( {
28+ when ( github . request )
29+ . calledWith ( 'GET /repos/{owner}/{repo}/collaborators' , {
30+ repo : repoName ,
31+ owner : repoOwner ,
32+ affiliation : 'direct'
33+ } )
34+ . mockResolvedValue ( {
3235 data : [
3336 { login : 'bkeepers' , permissions : { admin : true , push : true , pull : true } } ,
3437 { login : 'updated-permission' , permissions : { admin : false , push : false , pull : true } } ,
3538 { login : 'removed-user' , permissions : { admin : false , push : true , pull : true } } ,
3639 { login : 'differentCase' , permissions : { admin : false , push : true , pull : true } }
3740 ]
3841 } )
39- )
4042
4143 return plugin . sync ( ) . then ( ( ) => {
42- expect ( github . repos . addCollaborator ) . toHaveBeenCalledWith ( {
44+ expect ( github . request ) . toHaveBeenCalledWith ( 'PUT /repos/{owner}/{repo}/collaborators/{username}' , {
4345 owner : 'bkeepers' ,
4446 repo : 'test' ,
4547 username : 'added-user' ,
4648 permission : 'push'
4749 } )
4850
49- expect ( github . repos . addCollaborator ) . toHaveBeenCalledWith ( {
51+ expect ( github . request ) . toHaveBeenCalledWith ( 'PUT /repos/{owner}/{repo}/collaborators/{username}' , {
5052 owner : 'bkeepers' ,
5153 repo : 'test' ,
5254 username : 'updated-permission' ,
5355 permission : 'push'
5456 } )
5557
56- expect ( github . repos . addCollaborator ) . toHaveBeenCalledTimes ( 2 )
57-
58- expect ( github . repos . removeCollaborator ) . toHaveBeenCalledWith ( {
58+ expect ( github . request ) . toHaveBeenCalledWith ( 'DELETE /repos/{owner}/{repo}/collaborators/{username}' , {
5959 owner : 'bkeepers' ,
6060 repo : 'test' ,
6161 username : 'removed-user'
6262 } )
63-
64- expect ( github . repos . removeCollaborator ) . toHaveBeenCalledTimes ( 1 )
6563 } )
6664 } )
6765 } )
0 commit comments