@@ -2,6 +2,7 @@ import UserInvitationPage from './UserInvitationPage.vue';
22import { http , HttpResponse } from 'msw' ;
33import userMock from './mocks/userMock.js' ;
44import PageInitConfigMock from './mocks/pageInitConfig' ;
5+ import ReviewerPageInitConfigMock from './mocks/reviewerPageInitConfig' ;
56
67export default { title : 'Pages/UserInvitation' , component : UserInvitationPage } ;
78
@@ -118,3 +119,87 @@ export const Init = {
118119 } ,
119120 args : PageInitConfigMock ,
120121} ;
122+
123+ export const Reviewer = {
124+ render : ( args ) => ( {
125+ components : { UserInvitationPage} ,
126+ setup ( ) {
127+ return { args} ;
128+ } ,
129+ template : '<UserInvitationPage v-bind="args" />' ,
130+ } ) ,
131+ parameters : {
132+ msw : {
133+ handlers : [
134+ http . post (
135+ 'https://mock/index.php/publicknowledge/api/v1/invitations/add/reviewerAccess' ,
136+ ( ) => {
137+ return HttpResponse . json ( { invitationId : 15 } ) ;
138+ } ,
139+ ) ,
140+ http . post (
141+ 'https://mock/index.php/publicknowledge/api/v1/invitations/15/populate' ,
142+ async ( { request} ) => {
143+ const data = await request . json ( ) ;
144+ let errors = { } ;
145+
146+ data . invitationData . userGroupsToAdd . forEach ( ( element , index ) => {
147+ Object . keys ( element ) . forEach ( ( key ) => {
148+ if ( element [ key ] === null ) {
149+ errors = {
150+ ...errors ,
151+ [ 'userGroupsToAdd.' + index + '.' + key ] : [
152+ 'This field is required' ,
153+ ] ,
154+ } ;
155+ }
156+ } ) ;
157+ } ) ;
158+
159+ if ( data . invitationData . email === '' ) {
160+ errors [ 'email' ] = [ 'This field is required' ] ;
161+ }
162+ if ( data . invitationData . familyName === '' ) {
163+ errors [ 'familyName' ] = [ 'This field is required' ] ;
164+ }
165+ if ( data . invitationData . givenName === '' ) {
166+ errors [ 'givenName' ] = [ 'This field is required' ] ;
167+ }
168+
169+ if ( data . invitationData . emailComposer ) {
170+ Object . keys ( data . invitationData . emailComposer ) . forEach (
171+ ( element ) => {
172+ if ( data . invitationData . emailComposer [ element ] === '' ) {
173+ errors [ 'emailComposer' ] = {
174+ ...errors [ 'emailComposer' ] ,
175+ [ element ] : [ 'This field is required' ] ,
176+ } ;
177+ }
178+ } ,
179+ ) ;
180+ }
181+
182+ if ( Object . keys ( errors ) . length > 0 ) {
183+ return HttpResponse . json ( { errors : errors } , { status : 422 } ) ;
184+ }
185+
186+ return HttpResponse . json ( { status : 201 } ) ;
187+ } ,
188+ ) ,
189+ http . post (
190+ 'https://mock/index.php/publicknowledge/api/v1/invitations/15/invite' ,
191+ ( ) => {
192+ return HttpResponse . json ( { } ) ;
193+ } ,
194+ ) ,
195+ http . post (
196+ 'https://mock/index.php/publicknowledge/api/v1/user/_invite' ,
197+ ( ) => {
198+ return HttpResponse . json ( 'invitation send successfully' ) ;
199+ } ,
200+ ) ,
201+ ] ,
202+ } ,
203+ } ,
204+ args : ReviewerPageInitConfigMock ,
205+ } ;
0 commit comments