1
1
const Author = require ( '../../../lib/filters/author' )
2
2
const Helper = require ( '../../../__fixtures__/unit/helper' )
3
+ const Teams = require ( '../../../lib/validators/options_processor/teams' )
4
+
5
+ const authorName = 'mergeabletestauthorname'
6
+ const otherAuthorName = 'someone-else'
3
7
4
8
test ( 'should fail with unexpected author' , async ( ) => {
5
9
const author = new Author ( )
6
10
const settings = {
7
11
do : 'author' ,
8
12
must_include : {
9
- regex : 'someone-else'
13
+ regex : otherAuthorName
10
14
}
11
15
}
12
- const filter = await author . processFilter ( createMockContext ( 'mergeable' ) , settings )
16
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
13
17
expect ( filter . status ) . toBe ( 'fail' )
14
18
} )
15
19
@@ -18,10 +22,10 @@ test('should pass with expected author', async () => {
18
22
const settings = {
19
23
do : 'author' ,
20
24
must_include : {
21
- regex : 'mergeable'
25
+ regex : authorName
22
26
}
23
27
}
24
- const filter = await author . processFilter ( createMockContext ( 'mergeable' ) , settings )
28
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
25
29
expect ( filter . status ) . toBe ( 'pass' )
26
30
} )
27
31
@@ -30,10 +34,10 @@ test('should fail with excluded author', async () => {
30
34
const settings = {
31
35
do : 'author' ,
32
36
must_exclude : {
33
- regex : 'mergeable'
37
+ regex : authorName
34
38
}
35
39
}
36
- const filter = await author . processFilter ( createMockContext ( 'mergeable' ) , settings )
40
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
37
41
expect ( filter . status ) . toBe ( 'fail' )
38
42
} )
39
43
@@ -42,13 +46,78 @@ test('should pass with excluded author', async () => {
42
46
const settings = {
43
47
do : 'author' ,
44
48
must_exclude : {
45
- regex : 'someone-else'
49
+ regex : otherAuthorName
46
50
}
47
51
}
48
- const filter = await author . processFilter ( createMockContext ( 'mergeable' ) , settings )
52
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
53
+ expect ( filter . status ) . toBe ( 'pass' )
54
+ } )
55
+
56
+ test ( 'should pass with expected author from correct team' , async ( ) => {
57
+ const author = new Author ( )
58
+ const settings = {
59
+ do : 'author' ,
60
+ must_include : {
61
+ regex : authorName
62
+ } ,
63
+ team : 'org/team-slug'
64
+ }
65
+ Teams . extractTeamMemberships = jest . fn ( ) . mockReturnValue ( [ authorName ] )
66
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
49
67
expect ( filter . status ) . toBe ( 'pass' )
50
68
} )
51
69
70
+ test ( 'should fail with expected author from incorrect team' , async ( ) => {
71
+ const author = new Author ( )
72
+ const settings = {
73
+ do : 'author' ,
74
+ must_include : {
75
+ regex : authorName
76
+ } ,
77
+ team : 'org/team-slug'
78
+ }
79
+ Teams . extractTeamMemberships = jest . fn ( ) . mockReturnValue ( [ ] )
80
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
81
+ expect ( filter . status ) . toBe ( 'fail' )
82
+ } )
83
+
84
+ test ( 'should fail with unexpected author from correct team' , async ( ) => {
85
+ const author = new Author ( )
86
+ const settings = {
87
+ do : 'author' ,
88
+ must_include : {
89
+ regex : otherAuthorName
90
+ } ,
91
+ team : 'org/team-slug'
92
+ }
93
+ Teams . extractTeamMemberships = jest . fn ( ) . mockReturnValue ( [ authorName ] )
94
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
95
+ expect ( filter . status ) . toBe ( 'fail' )
96
+ } )
97
+
98
+ test ( 'should pass when the author is a member of the team' , async ( ) => {
99
+ const author = new Author ( )
100
+ const settings = {
101
+ do : 'author' ,
102
+ team : 'org/team-slug'
103
+ }
104
+ Teams . extractTeamMemberships = jest . fn ( ) . mockReturnValue ( [ authorName ] )
105
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
106
+ expect ( filter . status ) . toBe ( 'pass' )
107
+ } )
108
+
109
+ test ( 'should fail when the author is not a member of the team' , async ( ) => {
110
+ const author = new Author ( )
111
+ const authorName = 'mergeable'
112
+ const settings = {
113
+ do : 'author' ,
114
+ team : 'org/team-slug'
115
+ }
116
+ Teams . extractTeamMemberships = jest . fn ( ) . mockReturnValue ( [ otherAuthorName ] )
117
+ const filter = await author . processFilter ( createMockContext ( authorName ) , settings )
118
+ expect ( filter . status ) . toBe ( 'fail' )
119
+ } )
120
+
52
121
const createMockContext = ( author ) => {
53
122
return Helper . mockContext ( { author } )
54
123
}
0 commit comments