@@ -835,12 +835,22 @@ describe('@apostrophecms/import-export', function () {
835835 } ) ;
836836
837837 describe ( 'when the site has multiple locales' , function ( ) {
838- let _apos ;
839- let _req ;
840- let _importExportManager ;
838+ let apos ;
839+ let importExportManager ;
841840
842- before ( async function ( ) {
843- _apos = await t . create ( {
841+ let req ;
842+ let notify ;
843+ let getFilesData ;
844+ let readExportFile ;
845+ let rewriteDocsWithCurrentLocale ;
846+ let insertDocs ;
847+
848+ after ( async function ( ) {
849+ await t . destroy ( apos ) ;
850+ } ) ;
851+
852+ before ( async function ( ) {
853+ apos = await t . create ( {
844854 root : module ,
845855 testModule : true ,
846856 modules : getAppConfig ( {
@@ -865,25 +875,45 @@ describe('@apostrophecms/import-export', function () {
865875 } )
866876 } ) ;
867877
868- _req = _apos . task . getReq ( {
878+ importExportManager = apos . modules [ '@apostrophecms/import-export' ] ;
879+ importExportManager . removeExportFileFromUploadFs = ( ) => { } ;
880+ importExportManager . cleanFile = ( ) => { } ;
881+
882+ await insertAdminUser ( apos ) ;
883+ await insertPieces ( apos ) ;
884+ } ) ;
885+
886+ this . beforeEach ( async function ( ) {
887+ req = apos . task . getReq ( {
869888 locale : 'en' ,
870889 body : { }
871890 } ) ;
872-
873- _importExportManager = _apos . modules [ '@apostrophecms/import-export' ] ;
891+ notify = apos . notify ;
892+ getFilesData = apos . modules [ '@apostrophecms/import-export' ] . getFilesData ;
893+ readExportFile = apos . modules [ '@apostrophecms/import-export' ] . readExportFile ;
894+ rewriteDocsWithCurrentLocale = apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale ;
895+ insertDocs = apos . modules [ '@apostrophecms/import-export' ] . insertDocs ;
896+
897+ await deletePieces ( apos ) ;
898+ await deletePage ( apos ) ;
899+ await deleteAttachments ( apos , attachmentPath ) ;
874900 } ) ;
875901
876- after ( async function ( ) {
877- await t . destroy ( _apos ) ;
902+ this . afterEach ( function ( ) {
903+ apos . notify = notify ;
904+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = getFilesData ;
905+ apos . modules [ '@apostrophecms/import-export' ] . readExportFile = readExportFile ;
906+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = rewriteDocsWithCurrentLocale ;
907+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = insertDocs ;
878908 } ) ;
879909
880910 it ( 'should not rewrite the docs locale nor ask about it when the locale is not different' , async function ( ) {
881- const _req = _apos . task . getReq ( {
911+ const req = apos . task . getReq ( {
882912 locale : 'fr' ,
883913 body : { }
884914 } ) ;
885915
886- _apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
916+ apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
887917 return {
888918 docs : [
889919 {
@@ -897,10 +927,10 @@ describe('@apostrophecms/import-export', function () {
897927 attachmentsInfo : [ ]
898928 } ;
899929 } ;
900- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
930+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
901931 throw new Error ( 'should not have been called' ) ;
902932 } ;
903- _apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
933+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
904934 assert . deepEqual ( docs , [
905935 {
906936 _id : '4:fr:draft' ,
@@ -917,18 +947,18 @@ describe('@apostrophecms/import-export', function () {
917947 failedIds : [ ]
918948 } ;
919949 } ;
920- _apos . notify = async ( req , message , options ) => {
950+ apos . notify = async ( req , message , options ) => {
921951 if ( options ?. event ?. name === 'import-locale-differs' ) {
922952 throw new Error ( 'should not have been called with event "import-locale-differ"' ) ;
923953 }
924954 return { } ;
925955 } ;
926956
927- await _importExportManager . import ( _req ) ;
957+ await importExportManager . import ( req ) ;
928958 } ) ;
929959
930960 it ( 'should not rewrite the docs locales nor insert them but ask about it when the locale is different' , async function ( ) {
931- _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
961+ apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
932962 return {
933963 docs : [
934964 {
@@ -943,28 +973,28 @@ describe('@apostrophecms/import-export', function () {
943973 } ;
944974 } ;
945975
946- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
976+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
947977 throw new Error ( 'should not have been called' ) ;
948978 } ;
949- _apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
979+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
950980 throw new Error ( 'should not have been called' ) ;
951981 } ;
952- _apos . notify = async ( req , message , options ) => {
982+ apos . notify = async ( req , message , options ) => {
953983 assert . equal ( options . event . name , 'import-locale-differs' ) ;
954984 } ;
955985
956- await _importExportManager . import ( _req ) ;
986+ await importExportManager . import ( req ) ;
957987 } ) ;
958988
959989 it ( 'should rewrite the docs locale when the locale is different and the `overrideLocale` param is provided' , async function ( ) {
960- const _req = _apos . task . getReq ( {
990+ const req = apos . task . getReq ( {
961991 locale : 'en' ,
962992 body : {
963993 overrideLocale : true
964994 }
965995 } ) ;
966996
967- _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
997+ apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
968998 return {
969999 docs : [
9701000 {
@@ -979,7 +1009,7 @@ describe('@apostrophecms/import-export', function () {
9791009 } ;
9801010 } ;
9811011
982- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1012+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
9831013 assert . deepEqual ( docs , [
9841014 {
9851015 _id : '4:fr:draft' ,
@@ -992,7 +1022,7 @@ describe('@apostrophecms/import-export', function () {
9921022
9931023 return rewriteDocsWithCurrentLocale ( req , docs ) ;
9941024 } ;
995- _apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
1025+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
9961026 assert . deepEqual ( docs , [
9971027 {
9981028 _id : '4:en:draft' ,
@@ -1009,24 +1039,23 @@ describe('@apostrophecms/import-export', function () {
10091039 failedIds : [ ]
10101040 } ;
10111041 } ;
1012- _apos . notify = async ( req , message , options ) => {
1042+ apos . notify = async ( req , message , options ) => {
10131043 if ( options ?. event ?. name === 'import-locale-differs' ) {
10141044 throw new Error ( 'should not have been called with event "import-locale-differ"' ) ;
10151045 }
10161046 return { } ;
10171047 } ;
10181048
1019- await _importExportManager . import ( _req ) ;
1049+ await importExportManager . import ( req ) ;
10201050 } ) ;
10211051 } ) ;
10221052 } ) ;
10231053
10241054 describe ( '#overrideDuplicates - overriding locales integration tests' , function ( ) {
10251055 let req ;
1026- let jobManager ;
10271056 let getFilesData ;
10281057 let rewriteDocsWithCurrentLocale ;
1029- let insertOrUpdateDoc ;
1058+ let jobManager ;
10301059
10311060 this . beforeEach ( async function ( ) {
10321061 req = apos . task . getReq ( {
@@ -1036,7 +1065,6 @@ describe('@apostrophecms/import-export', function () {
10361065 jobManager = apos . modules [ '@apostrophecms/job' ] ;
10371066 getFilesData = apos . modules [ '@apostrophecms/import-export' ] . getFilesData ;
10381067 rewriteDocsWithCurrentLocale = apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale ;
1039- insertOrUpdateDoc = apos . modules [ '@apostrophecms/import-export' ] . insertOrUpdateDoc ;
10401068
10411069 jobManager . success = ( ) => { } ;
10421070 jobManager . failure = ( ) => { } ;
@@ -1050,7 +1078,6 @@ describe('@apostrophecms/import-export', function () {
10501078 apos . modules [ '@apostrophecms/job' ] . jobManager = jobManager ;
10511079 apos . modules [ '@apostrophecms/import-export' ] . getFilesData = getFilesData ;
10521080 apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = rewriteDocsWithCurrentLocale ;
1053- apos . modules [ '@apostrophecms/import-export' ] . insertOrUpdateDoc = insertOrUpdateDoc ;
10541081 } ) ;
10551082
10561083 describe ( 'when the site has only one locale' , function ( ) {
@@ -1110,12 +1137,18 @@ describe('@apostrophecms/import-export', function () {
11101137 } ) ;
11111138
11121139 describe ( 'when the site has multiple locales' , function ( ) {
1113- let _apos ;
1114- let _req ;
1115- let _importExportManager ;
1140+ let apos ;
1141+ let importExportManager ;
1142+
1143+ let getFilesData ;
1144+ let rewriteDocsWithCurrentLocale ;
1145+
1146+ after ( async function ( ) {
1147+ await t . destroy ( apos ) ;
1148+ } ) ;
11161149
1117- before ( async function ( ) {
1118- _apos = await t . create ( {
1150+ before ( async function ( ) {
1151+ apos = await t . create ( {
11191152 root : module ,
11201153 testModule : true ,
11211154 modules : getAppConfig ( {
@@ -1140,27 +1173,38 @@ describe('@apostrophecms/import-export', function () {
11401173 } )
11411174 } ) ;
11421175
1143- _req = _apos . task . getReq ( {
1144- locale : 'en' ,
1145- body : { }
1146- } ) ;
1147-
1148- _importExportManager = _apos . modules [ '@apostrophecms/import-export' ] ;
1149- } ) ;
1176+ importExportManager = apos . modules [ '@apostrophecms/import-export' ] ;
1177+ importExportManager . removeExportFileFromUploadFs = ( ) => { } ;
1178+ importExportManager . cleanFile = ( ) => { } ;
11501179
1151- after ( async function ( ) {
1152- await t . destroy ( _apos ) ;
1180+ await insertAdminUser ( apos ) ;
1181+ await insertPieces ( apos ) ;
11531182 } ) ;
11541183
11551184 this . beforeEach ( async function ( ) {
1156- jobManager = _apos . modules [ '@apostrophecms/job' ] ;
1185+ req = apos . task . getReq ( {
1186+ locale : 'en' ,
1187+ body : { }
1188+ } ) ;
1189+ getFilesData = apos . modules [ '@apostrophecms/import-export' ] . getFilesData ;
1190+ rewriteDocsWithCurrentLocale = apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale ;
11571191
1192+ jobManager = apos . modules [ '@apostrophecms/job' ] ;
11581193 jobManager . success = ( ) => { } ;
11591194 jobManager . failure = ( ) => { } ;
1195+
1196+ await deletePieces ( apos ) ;
1197+ await deletePage ( apos ) ;
1198+ await deleteAttachments ( apos , attachmentPath ) ;
1199+ } ) ;
1200+
1201+ this . afterEach ( function ( ) {
1202+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = getFilesData ;
1203+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = rewriteDocsWithCurrentLocale ;
11601204 } ) ;
11611205
11621206 it ( 'should not rewrite the docs locale when the locale is not different' , async function ( ) {
1163- _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1207+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
11641208 return {
11651209 docs : [
11661210 {
@@ -1174,22 +1218,22 @@ describe('@apostrophecms/import-export', function () {
11741218 attachmentsInfo : [ ]
11751219 } ;
11761220 } ;
1177- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1221+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
11781222 throw new Error ( 'should not have been called' ) ;
11791223 } ;
11801224
1181- await _importExportManager . overrideDuplicates ( _req ) ;
1225+ await importExportManager . overrideDuplicates ( req ) ;
11821226 } ) ;
11831227
11841228 it ( 'should rewrite the docs locale when the locale is different and the `overrideLocale` param is provided' , async function ( ) {
1185- const _req = _apos . task . getReq ( {
1229+ const req = apos . task . getReq ( {
11861230 locale : 'en' ,
11871231 body : {
11881232 overrideLocale : true
11891233 }
11901234 } ) ;
11911235
1192- _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1236+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
11931237 return {
11941238 docs : [
11951239 {
@@ -1203,7 +1247,7 @@ describe('@apostrophecms/import-export', function () {
12031247 attachmentsInfo : [ ]
12041248 } ;
12051249 } ;
1206- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1250+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
12071251 assert . deepEqual ( docs , [
12081252 {
12091253 _id : '4:fr:draft' ,
@@ -1217,7 +1261,7 @@ describe('@apostrophecms/import-export', function () {
12171261 return rewriteDocsWithCurrentLocale ( req , docs ) ;
12181262 } ;
12191263
1220- await _importExportManager . overrideDuplicates ( _req ) ;
1264+ await importExportManager . overrideDuplicates ( req ) ;
12211265 } ) ;
12221266 } ) ;
12231267 } ) ;
0 commit comments