@@ -835,12 +835,22 @@ describe('@apostrophecms/import-export', function () {
835
835
} ) ;
836
836
837
837
describe ( 'when the site has multiple locales' , function ( ) {
838
- let _apos ;
839
- let _req ;
840
- let _importExportManager ;
838
+ let apos ;
839
+ let importExportManager ;
841
840
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 ( {
844
854
root : module ,
845
855
testModule : true ,
846
856
modules : getAppConfig ( {
@@ -865,25 +875,45 @@ describe('@apostrophecms/import-export', function () {
865
875
} )
866
876
} ) ;
867
877
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 ( {
869
888
locale : 'en' ,
870
889
body : { }
871
890
} ) ;
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 ) ;
874
900
} ) ;
875
901
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 ;
878
908
} ) ;
879
909
880
910
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 ( {
882
912
locale : 'fr' ,
883
913
body : { }
884
914
} ) ;
885
915
886
- _apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
916
+ apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
887
917
return {
888
918
docs : [
889
919
{
@@ -897,10 +927,10 @@ describe('@apostrophecms/import-export', function () {
897
927
attachmentsInfo : [ ]
898
928
} ;
899
929
} ;
900
- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
930
+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
901
931
throw new Error ( 'should not have been called' ) ;
902
932
} ;
903
- _apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
933
+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
904
934
assert . deepEqual ( docs , [
905
935
{
906
936
_id : '4:fr:draft' ,
@@ -917,18 +947,18 @@ describe('@apostrophecms/import-export', function () {
917
947
failedIds : [ ]
918
948
} ;
919
949
} ;
920
- _apos . notify = async ( req , message , options ) => {
950
+ apos . notify = async ( req , message , options ) => {
921
951
if ( options ?. event ?. name === 'import-locale-differs' ) {
922
952
throw new Error ( 'should not have been called with event "import-locale-differ"' ) ;
923
953
}
924
954
return { } ;
925
955
} ;
926
956
927
- await _importExportManager . import ( _req ) ;
957
+ await importExportManager . import ( req ) ;
928
958
} ) ;
929
959
930
960
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 => {
932
962
return {
933
963
docs : [
934
964
{
@@ -943,28 +973,28 @@ describe('@apostrophecms/import-export', function () {
943
973
} ;
944
974
} ;
945
975
946
- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
976
+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( ) => {
947
977
throw new Error ( 'should not have been called' ) ;
948
978
} ;
949
- _apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
979
+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
950
980
throw new Error ( 'should not have been called' ) ;
951
981
} ;
952
- _apos . notify = async ( req , message , options ) => {
982
+ apos . notify = async ( req , message , options ) => {
953
983
assert . equal ( options . event . name , 'import-locale-differs' ) ;
954
984
} ;
955
985
956
- await _importExportManager . import ( _req ) ;
986
+ await importExportManager . import ( req ) ;
957
987
} ) ;
958
988
959
989
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 ( {
961
991
locale : 'en' ,
962
992
body : {
963
993
overrideLocale : true
964
994
}
965
995
} ) ;
966
996
967
- _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
997
+ apos . modules [ '@apostrophecms/import-export' ] . readExportFile = async req => {
968
998
return {
969
999
docs : [
970
1000
{
@@ -979,7 +1009,7 @@ describe('@apostrophecms/import-export', function () {
979
1009
} ;
980
1010
} ;
981
1011
982
- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1012
+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
983
1013
assert . deepEqual ( docs , [
984
1014
{
985
1015
_id : '4:fr:draft' ,
@@ -992,7 +1022,7 @@ describe('@apostrophecms/import-export', function () {
992
1022
993
1023
return rewriteDocsWithCurrentLocale ( req , docs ) ;
994
1024
} ;
995
- _apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
1025
+ apos . modules [ '@apostrophecms/import-export' ] . insertDocs = async ( req , docs ) => {
996
1026
assert . deepEqual ( docs , [
997
1027
{
998
1028
_id : '4:en:draft' ,
@@ -1009,24 +1039,23 @@ describe('@apostrophecms/import-export', function () {
1009
1039
failedIds : [ ]
1010
1040
} ;
1011
1041
} ;
1012
- _apos . notify = async ( req , message , options ) => {
1042
+ apos . notify = async ( req , message , options ) => {
1013
1043
if ( options ?. event ?. name === 'import-locale-differs' ) {
1014
1044
throw new Error ( 'should not have been called with event "import-locale-differ"' ) ;
1015
1045
}
1016
1046
return { } ;
1017
1047
} ;
1018
1048
1019
- await _importExportManager . import ( _req ) ;
1049
+ await importExportManager . import ( req ) ;
1020
1050
} ) ;
1021
1051
} ) ;
1022
1052
} ) ;
1023
1053
1024
1054
describe ( '#overrideDuplicates - overriding locales integration tests' , function ( ) {
1025
1055
let req ;
1026
- let jobManager ;
1027
1056
let getFilesData ;
1028
1057
let rewriteDocsWithCurrentLocale ;
1029
- let insertOrUpdateDoc ;
1058
+ let jobManager ;
1030
1059
1031
1060
this . beforeEach ( async function ( ) {
1032
1061
req = apos . task . getReq ( {
@@ -1036,7 +1065,6 @@ describe('@apostrophecms/import-export', function () {
1036
1065
jobManager = apos . modules [ '@apostrophecms/job' ] ;
1037
1066
getFilesData = apos . modules [ '@apostrophecms/import-export' ] . getFilesData ;
1038
1067
rewriteDocsWithCurrentLocale = apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale ;
1039
- insertOrUpdateDoc = apos . modules [ '@apostrophecms/import-export' ] . insertOrUpdateDoc ;
1040
1068
1041
1069
jobManager . success = ( ) => { } ;
1042
1070
jobManager . failure = ( ) => { } ;
@@ -1050,7 +1078,6 @@ describe('@apostrophecms/import-export', function () {
1050
1078
apos . modules [ '@apostrophecms/job' ] . jobManager = jobManager ;
1051
1079
apos . modules [ '@apostrophecms/import-export' ] . getFilesData = getFilesData ;
1052
1080
apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = rewriteDocsWithCurrentLocale ;
1053
- apos . modules [ '@apostrophecms/import-export' ] . insertOrUpdateDoc = insertOrUpdateDoc ;
1054
1081
} ) ;
1055
1082
1056
1083
describe ( 'when the site has only one locale' , function ( ) {
@@ -1110,12 +1137,18 @@ describe('@apostrophecms/import-export', function () {
1110
1137
} ) ;
1111
1138
1112
1139
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
+ } ) ;
1116
1149
1117
- before ( async function ( ) {
1118
- _apos = await t . create ( {
1150
+ before ( async function ( ) {
1151
+ apos = await t . create ( {
1119
1152
root : module ,
1120
1153
testModule : true ,
1121
1154
modules : getAppConfig ( {
@@ -1140,27 +1173,38 @@ describe('@apostrophecms/import-export', function () {
1140
1173
} )
1141
1174
} ) ;
1142
1175
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 = ( ) => { } ;
1150
1179
1151
- after ( async function ( ) {
1152
- await t . destroy ( _apos ) ;
1180
+ await insertAdminUser ( apos ) ;
1181
+ await insertPieces ( apos ) ;
1153
1182
} ) ;
1154
1183
1155
1184
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 ;
1157
1191
1192
+ jobManager = apos . modules [ '@apostrophecms/job' ] ;
1158
1193
jobManager . success = ( ) => { } ;
1159
1194
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 ;
1160
1204
} ) ;
1161
1205
1162
1206
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 => {
1164
1208
return {
1165
1209
docs : [
1166
1210
{
@@ -1174,22 +1218,22 @@ describe('@apostrophecms/import-export', function () {
1174
1218
attachmentsInfo : [ ]
1175
1219
} ;
1176
1220
} ;
1177
- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1221
+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1178
1222
throw new Error ( 'should not have been called' ) ;
1179
1223
} ;
1180
1224
1181
- await _importExportManager . overrideDuplicates ( _req ) ;
1225
+ await importExportManager . overrideDuplicates ( req ) ;
1182
1226
} ) ;
1183
1227
1184
1228
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 ( {
1186
1230
locale : 'en' ,
1187
1231
body : {
1188
1232
overrideLocale : true
1189
1233
}
1190
1234
} ) ;
1191
1235
1192
- _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1236
+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1193
1237
return {
1194
1238
docs : [
1195
1239
{
@@ -1203,7 +1247,7 @@ describe('@apostrophecms/import-export', function () {
1203
1247
attachmentsInfo : [ ]
1204
1248
} ;
1205
1249
} ;
1206
- _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1250
+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1207
1251
assert . deepEqual ( docs , [
1208
1252
{
1209
1253
_id : '4:fr:draft' ,
@@ -1217,7 +1261,7 @@ describe('@apostrophecms/import-export', function () {
1217
1261
return rewriteDocsWithCurrentLocale ( req , docs ) ;
1218
1262
} ;
1219
1263
1220
- await _importExportManager . overrideDuplicates ( _req ) ;
1264
+ await importExportManager . overrideDuplicates ( req ) ;
1221
1265
} ) ;
1222
1266
} ) ;
1223
1267
} ) ;
0 commit comments