@@ -447,6 +447,175 @@ describe(__filename, function () {
447447 } ) ;
448448 } ) ;
449449
450+ describe ( 'revisions are supported in txt and html export' , function ( ) {
451+ const makeGoodExport = ( ) => ( {
452+ 'pad:testing' : {
453+ atext : {
454+ text : 'oofoo\n' ,
455+ attribs : '|1+6' ,
456+ } ,
457+ pool : {
458+ numToAttrib : {
459+ 0 : [ 'author' , 'a.foo' ] ,
460+ } ,
461+ nextNum : 1 ,
462+ } ,
463+ head : 2 ,
464+ savedRevisions : [ ] ,
465+ } ,
466+ 'globalAuthor:a.foo' : {
467+ colorId : '#000000' ,
468+ name : 'author foo' ,
469+ timestamp : 1598747784631 ,
470+ padIDs : 'testing' ,
471+ } ,
472+ 'pad:testing:revs:0' : {
473+ changeset : 'Z:1>3+3$foo' ,
474+ meta : {
475+ author : 'a.foo' ,
476+ timestamp : 1597632398288 ,
477+ pool : {
478+ nextNum : 1 ,
479+ numToAttrib : {
480+ 0 : [ 'author' , 'a.foo' ] ,
481+ } ,
482+ } ,
483+ atext : {
484+ text : 'foo\n' ,
485+ attribs : '|1+4' ,
486+ } ,
487+ } ,
488+ } ,
489+ 'pad:testing:revs:1' : {
490+ changeset : 'Z:4>1+1$o' ,
491+ meta : {
492+ author : 'a.foo' ,
493+ timestamp : 1597632398288 ,
494+ pool : {
495+ nextNum : 1 ,
496+ numToAttrib : {
497+ 0 : [ 'author' , 'a.foo' ] ,
498+ } ,
499+ } ,
500+ atext : {
501+ text : 'fooo\n' ,
502+ attribs : '*0|1+5' ,
503+ } ,
504+ } ,
505+ } ,
506+ 'pad:testing:revs:2' : {
507+ changeset : 'Z:5>1+1$o' ,
508+ meta : {
509+ author : 'a.foo' ,
510+ timestamp : 1597632398288 ,
511+ pool : {
512+ numToAttrib : { } ,
513+ nextNum : 0 ,
514+ } ,
515+ atext : {
516+ text : 'foooo\n' ,
517+ attribs : '*0|1+6' ,
518+ } ,
519+ } ,
520+ } ,
521+ } ) ;
522+
523+ const importEtherpad = ( records ) => agent . post ( `/p/${ testPadId } /import` )
524+ . attach ( 'file' , Buffer . from ( JSON . stringify ( records ) , 'utf8' ) , {
525+ filename : '/test.etherpad' ,
526+ contentType : 'application/etherpad' ,
527+ } ) ;
528+
529+ before ( async function ( ) {
530+ // makeGoodExport() is assumed to produce good .etherpad records. Verify that assumption so
531+ // that a buggy makeGoodExport() doesn't cause checks to accidentally pass.
532+ const records = makeGoodExport ( ) ;
533+ await deleteTestPad ( ) ;
534+ await importEtherpad ( records )
535+ . expect ( 200 )
536+ . expect ( 'Content-Type' , / j s o n / )
537+ . expect ( ( res ) => assert . deepEqual ( res . body , {
538+ code : 0 ,
539+ message : 'ok' ,
540+ data : { directDatabaseAccess : true } ,
541+ } ) ) ;
542+ await agent . get ( `/p/${ testPadId } /export/txt` )
543+ . expect ( 200 )
544+ . buffer ( true ) . parse ( superagent . parse . text )
545+ . expect ( ( res ) => assert . equal ( res . text , 'oofoo\n' ) ) ;
546+ } ) ;
547+
548+ it ( 'txt request rev 1' , async function ( ) {
549+ await agent . get ( `/p/${ testPadId } /1/export/txt` )
550+ . expect ( 200 )
551+ . buffer ( true ) . parse ( superagent . parse . text )
552+ . expect ( ( res ) => assert . equal ( res . text , 'ofoo\n' ) ) ;
553+ } ) ;
554+
555+ it ( 'txt request rev 2' , async function ( ) {
556+ await agent . get ( `/p/${ testPadId } /2/export/txt` )
557+ . expect ( 200 )
558+ . buffer ( true ) . parse ( superagent . parse . text )
559+ . expect ( ( res ) => assert . equal ( res . text , 'oofoo\n' ) ) ;
560+ } ) ;
561+
562+ it ( 'txt request rev 1test returns rev 1' , async function ( ) {
563+ await agent . get ( `/p/${ testPadId } /1test/export/txt` )
564+ . expect ( 200 )
565+ . buffer ( true ) . parse ( superagent . parse . text )
566+ . expect ( ( res ) => assert . equal ( res . text , 'ofoo\n' ) ) ;
567+ } ) ;
568+
569+ it ( 'txt request rev test1 is 403' , async function ( ) {
570+ await agent . get ( `/p/${ testPadId } /test1/export/txt` )
571+ . expect ( 500 )
572+ . buffer ( true ) . parse ( superagent . parse . text )
573+ . expect ( ( res ) => assert . match ( res . text , / r e v i s n o t a n u m b e r / ) ) ;
574+ } ) ;
575+
576+ it ( 'txt request rev 5 returns head rev' , async function ( ) {
577+ await agent . get ( `/p/${ testPadId } /5/export/txt` )
578+ . expect ( 200 )
579+ . buffer ( true ) . parse ( superagent . parse . text )
580+ . expect ( ( res ) => assert . equal ( res . text , 'oofoo\n' ) ) ;
581+ } ) ;
582+
583+ it ( 'html request rev 1' , async function ( ) {
584+ await agent . get ( `/p/${ testPadId } /1/export/html` )
585+ . expect ( 200 )
586+ . buffer ( true ) . parse ( superagent . parse . text )
587+ . expect ( ( res ) => assert . match ( res . text , / o f o o < b r > / ) ) ;
588+ } ) ;
589+
590+ it ( 'html request rev 2' , async function ( ) {
591+ await agent . get ( `/p/${ testPadId } /2/export/html` )
592+ . expect ( 200 )
593+ . buffer ( true ) . parse ( superagent . parse . text )
594+ . expect ( ( res ) => assert . match ( res . text , / o o f o o < b r > / ) ) ;
595+ } ) ;
596+
597+ it ( 'html request rev 1test returns rev 1' , async function ( ) {
598+ await agent . get ( `/p/${ testPadId } /1test/export/html` )
599+ . expect ( 200 )
600+ . buffer ( true ) . parse ( superagent . parse . text )
601+ . expect ( ( res ) => assert . match ( res . text , / o f o o < b r > / ) ) ;
602+ } ) ;
603+
604+ it ( 'html request rev test1 results in 500 response' , async function ( ) {
605+ await agent . get ( `/p/${ testPadId } /test1/export/html` )
606+ . expect ( 500 )
607+ . buffer ( true ) . parse ( superagent . parse . text )
608+ . expect ( ( res ) => assert . match ( res . text , / r e v i s n o t a n u m b e r / ) ) ;
609+ } ) ;
610+
611+ it ( 'html request rev 5 returns head rev' , async function ( ) {
612+ await agent . get ( `/p/${ testPadId } /5/export/html` )
613+ . expect ( 200 )
614+ . buffer ( true ) . parse ( superagent . parse . text )
615+ . expect ( ( res ) => assert . match ( res . text , / o o f o o < b r > / ) ) ;
616+ } ) ;
617+ } ) ;
618+
450619 describe ( 'Import authorization checks' , function ( ) {
451620 let authorize ;
452621
0 commit comments