@@ -43,7 +43,7 @@ const expectExpiration = (expires: Date) => {
4343 expect ( isBefore ( expires , add ( oneDayFromNow , { minutes : 1 } ) ) ) . toBeTruthy ( ) ;
4444} ;
4545
46- const createEtherpad = async ( app ) => {
46+ const createEtherpad = async ( app , parentId ?: string ) => {
4747 // create an existing etherpad item to test reading it
4848 setUpApi ( {
4949 createGroupIfNotExistsFor : [
@@ -58,6 +58,7 @@ const createEtherpad = async (app) => {
5858 payload : {
5959 name : faker . word . sample ( ) ,
6060 } ,
61+ query : parentId ? { parentId } : undefined ,
6162 } ) ;
6263 expect ( res . statusCode ) . toBe ( StatusCodes . OK ) ;
6364 const item = res . json ( ) ;
@@ -271,7 +272,7 @@ describe('Etherpad service API', () => {
271272 mode,
272273 } ,
273274 } ) ;
274- it ( 'views a pad in read mode successfully' , async ( ) => {
275+ it ( 'member views a pad in read mode successfully' , async ( ) => {
275276 const { actor } = await seedFromJson ( ) ;
276277 assertIsDefined ( actor ) ;
277278 mockAuthenticate ( actor ) ;
@@ -301,6 +302,53 @@ describe('Etherpad service API', () => {
301302 padUrl : `${ ETHERPAD_PUBLIC_URL } /p/${ MOCK_PAD_READ_ONLY_ID } ` ,
302303 } ) ;
303304 } ) ;
305+ it ( 'guest views a pad in read mode successfully' , async ( ) => {
306+ const {
307+ actor,
308+ guests : [ guest ] ,
309+ items : [ parentItem ] ,
310+ } = await seedFromJson ( {
311+ items : [
312+ {
313+ memberships : [ { permission : 'write' , account : 'actor' } ] ,
314+ type : 'folder' ,
315+ itemLoginSchema : { guests : [ { } ] } ,
316+ } ,
317+ ] ,
318+ } ) ;
319+ assertIsDefined ( guest ) ;
320+ assertIsDefined ( actor ) ;
321+ // authenticate as actor
322+ mockAuthenticate ( actor ) ;
323+
324+ const item = await createEtherpad ( app , parentItem . id ) ;
325+
326+ // switch to guest authentication
327+ mockAuthenticate ( guest ) ;
328+
329+ const reqParams = setUpApi ( {
330+ getReadOnlyID : [
331+ StatusCodes . OK ,
332+ { code : 0 , message : 'ok' , data : { readOnlyID : MOCK_PAD_READ_ONLY_ID } } ,
333+ ] ,
334+ createAuthorIfNotExistsFor : [
335+ StatusCodes . OK ,
336+ { code : 0 , message : 'ok' , data : { authorID : MOCK_AUTHOR_ID } } ,
337+ ] ,
338+ createSession : [
339+ StatusCodes . OK ,
340+ { code : 0 , message : 'ok' , data : { sessionID : MOCK_SESSION_ID } } ,
341+ ] ,
342+ listSessionsOfAuthor : [ StatusCodes . OK , { code : 0 , message : 'ok' , data : null } ] ,
343+ } ) ;
344+ const res = await app . inject ( payloadView ( 'read' , item . id ) ) ;
345+ const { getReadOnlyID } = await reqParams ;
346+ expect ( getReadOnlyID ?. get ( 'padID' ) ) . toEqual ( item . extra . etherpad . padID ) ;
347+ expect ( res . statusCode ) . toEqual ( StatusCodes . OK ) ;
348+ expect ( res . json ( ) ) . toEqual ( {
349+ padUrl : `${ ETHERPAD_PUBLIC_URL } /p/${ MOCK_PAD_READ_ONLY_ID } ` ,
350+ } ) ;
351+ } ) ;
304352 it ( 'views a pad in write mode successfully' , async ( ) => {
305353 const { actor } = await seedFromJson ( ) ;
306354 assertIsDefined ( actor ) ;
0 commit comments