@@ -12,23 +12,46 @@ import InviteMembersModal from 'sentry/components/modals/inviteMembersModal';
12
12
import { ORG_ROLES } from 'sentry/constants' ;
13
13
import TeamStore from 'sentry/stores/teamStore' ;
14
14
import type { DetailedTeam , Scope } from 'sentry/types' ;
15
+ import { isActiveSuperuser } from 'sentry/utils/isActiveSuperuser' ;
15
16
import useOrganization from 'sentry/utils/useOrganization' ;
16
17
17
18
jest . mock ( 'sentry/utils/useOrganization' ) ;
19
+ jest . mock ( 'sentry/utils/isActiveSuperuser' , ( ) => ( {
20
+ isActiveSuperuser : jest . fn ( ) ,
21
+ } ) ) ;
18
22
19
23
describe ( 'InviteMembersModal' , function ( ) {
20
24
const styledWrapper = styled ( c => c . children ) ;
21
25
22
26
type MockApiResponseFn = (
23
27
client : typeof MockApiClient ,
24
28
orgSlug : string ,
29
+ is_superuser : boolean ,
30
+ verified_email : boolean ,
25
31
roles ?: object [ ]
26
32
) => jest . Mock ;
27
- const defaultMockOrganizationRoles : MockApiResponseFn = ( client , orgSlug , roles ) => {
33
+ const defaultMockOrganizationRoles : MockApiResponseFn = (
34
+ client ,
35
+ orgSlug ,
36
+ is_superuser ,
37
+ verified_email ,
38
+ roles
39
+ ) => {
28
40
return client . addMockResponse ( {
29
41
url : `/organizations/${ orgSlug } /members/me/` ,
30
42
method : 'GET' ,
31
- body : { orgRoleList : roles } ,
43
+ body : {
44
+ user : {
45
+ isSuperuser : is_superuser ,
46
+ emails : [
47
+ {
48
+ email : 'test@dev.getsentry.net' ,
49
+ is_verified : verified_email ,
50
+ } ,
51
+ ] ,
52
+ } ,
53
+ orgRoleList : roles ,
54
+ } ,
32
55
} ) ;
33
56
} ;
34
57
@@ -50,6 +73,8 @@ describe('InviteMembersModal', function () {
50
73
const setupView = ( {
51
74
orgTeams = [ TeamFixture ( ) ] ,
52
75
orgAccess = [ 'member:write' ] ,
76
+ is_superuser = false ,
77
+ verified_email = false ,
53
78
roles = [
54
79
{
55
80
id : 'admin' ,
@@ -69,11 +94,13 @@ describe('InviteMembersModal', function () {
69
94
modalProps = defaultMockModalProps ,
70
95
mockApiResponses = [ defaultMockOrganizationRoles ] ,
71
96
} : {
97
+ is_superuser ?: boolean ;
72
98
mockApiResponses ?: MockApiResponseFn [ ] ;
73
99
modalProps ?: ComponentProps < typeof InviteMembersModal > ;
74
100
orgAccess ?: Scope [ ] ;
75
101
orgTeams ?: DetailedTeam [ ] ;
76
102
roles ?: object [ ] ;
103
+ verified_email ?: boolean ;
77
104
} = { } ) => {
78
105
const org = OrganizationFixture ( { access : orgAccess , teams : orgTeams } ) ;
79
106
TeamStore . reset ( ) ;
@@ -82,7 +109,9 @@ describe('InviteMembersModal', function () {
82
109
MockApiClient . clearMockResponses ( ) ;
83
110
const mocks : jest . Mock [ ] = [ ] ;
84
111
mockApiResponses . forEach ( mockApiResponse => {
85
- mocks . push ( mockApiResponse ( MockApiClient , org . slug , roles ) ) ;
112
+ mocks . push (
113
+ mockApiResponse ( MockApiClient , org . slug , is_superuser , verified_email , roles )
114
+ ) ;
86
115
} ) ;
87
116
jest . mocked ( useOrganization ) . mockReturnValue ( org ) ;
88
117
@@ -106,7 +135,7 @@ describe('InviteMembersModal', function () {
106
135
} ;
107
136
108
137
it ( 'renders' , async function ( ) {
109
- setupView ( ) ;
138
+ setupView ( { verified_email : true } ) ;
110
139
await waitFor ( ( ) => {
111
140
// Starts with one invite row
112
141
expect ( screen . getByRole ( 'listitem' ) ) . toBeInTheDocument ( ) ;
@@ -120,9 +149,7 @@ describe('InviteMembersModal', function () {
120
149
} ) ;
121
150
122
151
it ( 'renders for superuser' , async function ( ) {
123
- jest . mock ( 'sentry/utils/isActiveSuperuser' , ( ) => ( {
124
- isActiveSuperuser : jest . fn ( ) ,
125
- } ) ) ;
152
+ jest . mocked ( isActiveSuperuser ) . mockReturnValue ( true ) ;
126
153
127
154
const errorResponse : MockApiResponseFn = ( client , orgSlug , _ ) => {
128
155
return client . addMockResponse ( {
0 commit comments