@@ -1526,23 +1526,71 @@ describe('/ deprecated', () => {
15261526 } ) ;
15271527
15281528 describe ( 'syncDetails' , ( ) => {
1529-
1529+ const uniqueDBname = process . env . REPLAY ? Date . now ( ) : '1637871012346' ;
1530+ before ( function ( ) {
1531+ debug ( '/syncDetails' , process . env . REPLAY ) ;
15301532
1531- it . only ( 'should try to create all corpora listed in the user' , async function ( ) {
1532- const testUsername = 'test1765217361392' ;
1533- const uniqueDBname = '1765217361394'
1533+ this . timeout ( 40000 ) ;
1534+ return supertest ( authWebService )
1535+ . post ( '/register' )
1536+ . set ( 'x-request-id' , `${ requestId } -prep-syncDetails` )
1537+ . send ( {
1538+ username : testUsername ,
1539+ password : 'test' ,
1540+
1541+ } )
1542+ . then ( ( res ) => {
1543+ debug ( `register ${ testUsername } ` , res . body ) ;
1544+ } ) ;
1545+ } ) ;
1546+
1547+ it ( 'should try to create all corpora listed in the user' , async function ( ) {
15341548 // The corpus creation can be delayed and finish after the request to login finishes
15351549 this . retries ( 3 ) ;
1536- return supertest ( `http://${ testUsername } :test@localhost:5984` )
1537- . get ( `/${ testUsername } -an_offline_corpus_created_in_the_prototype${ uniqueDBname } /_all_docs` )
1550+ return supertest ( authWebService )
1551+ . post ( '/login' )
1552+ . set ( 'x-request-id' , `${ requestId } -syncDetails` )
1553+ . send ( {
1554+ username : testUsername ,
1555+ password : 'test' ,
1556+ syncDetails : true ,
1557+ syncUserDetails : {
1558+ newCorpusConnections : [ {
1559+ dbname : `${ testUsername } -firstcorpus` ,
1560+ } , { } , {
1561+ dbname : 'someoneelsesdb-shouldnt_be_creatable' ,
1562+ } , {
1563+ dbname : `${ testUsername } -an_offline_corpus_created_in_the_prototype${ uniqueDBname } ` ,
1564+ } , {
1565+ dbname : `${ testUsername } -firstcorpus` ,
1566+ } ] ,
1567+ } ,
1568+ } )
1569+ . then ( ( res ) => {
1570+ expect ( res . body . user && res . body . user . corpora && res . body . user . corpora . length >= 1 )
1571+ . to . equal ( true , JSON . stringify ( res . body ) ) ;
1572+ expect ( res . body . user . newCorpora && res . body . user . newCorpora . length )
1573+ . above ( 2 , JSON . stringify ( res . body . user . newCorpora ) ) ;
1574+
1575+ return supertest ( `http://${ testUsername } :test@localhost:5984` )
1576+ . get ( '/someoneelsesdb-shouldnt_be_creatable' )
1577+ . set ( 'x-request-id' , `${ requestId } -syncDetails-after` )
1578+ . set ( 'Accept' , 'application/json' ) ;
1579+ } )
1580+ . then ( ( res ) => {
1581+ expect ( res . status ) . to . equal ( 404 ) ;
1582+
1583+ return supertest ( `http://${ testUsername } :test@localhost:5984` )
1584+ . get ( `/${ testUsername } -an_offline_corpus_created_in_the_prototype${ uniqueDBname } /_design/deprecated/_view/corpora` )
15381585 . set ( 'x-request-id' , `${ requestId } -syncDetails` )
1539- . set ( 'Accept' , 'application/json' )
1586+ . set ( 'Accept' , 'application/json' ) ;
1587+ } )
15401588 . then ( ( res ) => {
15411589 if ( res . status === 200 ) {
1542- expect ( res . body . total_rows ) . to . be . at . least ( 6 , JSON . stringify ( res . body ) ) ;
1590+ expect ( res . body . total_rows ) . to . equal ( 1 , JSON . stringify ( res . body ) ) ;
15431591 } else {
15441592 debug ( 'syncDetails' , JSON . stringify ( res . body ) ) ;
1545- // FIXME roles for the offline corpora are not being updated on the user
1593+ // FIXME roles for the offline corpora are not being updated on the user due to a conflict when saving the user
15461594 expect ( res . status ) . to . be . oneOf ( [ 403 ] , JSON . stringify ( res . body ) ) ;
15471595 }
15481596 } ) ;
0 commit comments