@@ -1021,6 +1021,206 @@ describe('@apostrophecms/import-export', function () {
10211021 } ) ;
10221022 } ) ;
10231023
1024+ describe . only ( '#overrideDuplicates - overriding locales integration tests' , function ( ) {
1025+ let req ;
1026+ let jobManager ;
1027+ let getFilesData ;
1028+ let rewriteDocsWithCurrentLocale ;
1029+ let insertOrUpdateDoc ;
1030+
1031+ this . beforeEach ( async function ( ) {
1032+ req = apos . task . getReq ( {
1033+ locale : 'en' ,
1034+ body : { }
1035+ } ) ;
1036+ jobManager = apos . modules [ '@apostrophecms/job' ] ;
1037+ getFilesData = apos . modules [ '@apostrophecms/import-export' ] . getFilesData ;
1038+ rewriteDocsWithCurrentLocale = apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale ;
1039+ insertOrUpdateDoc = apos . modules [ '@apostrophecms/import-export' ] . insertOrUpdateDoc ;
1040+
1041+ jobManager . success = ( ) => { } ;
1042+ jobManager . failure = ( ) => { } ;
1043+
1044+ await deletePieces ( apos ) ;
1045+ await deletePage ( apos ) ;
1046+ await deleteAttachments ( apos , attachmentPath ) ;
1047+ } ) ;
1048+
1049+ this . afterEach ( function ( ) {
1050+ apos . modules [ '@apostrophecms/job' ] . jobManager = jobManager ;
1051+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = getFilesData ;
1052+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = rewriteDocsWithCurrentLocale ;
1053+ apos . modules [ '@apostrophecms/import-export' ] . insertOrUpdateDoc = insertOrUpdateDoc ;
1054+ } ) ;
1055+
1056+ describe ( 'when the site has only one locale' , function ( ) {
1057+ it ( 'should not rewrite the docs locale when the locale is not different' , async function ( ) {
1058+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1059+ return {
1060+ docs : [
1061+ {
1062+ _id : '4:en:draft' ,
1063+ aposMode : 'draft' ,
1064+ aposLocale : 'en:draft' ,
1065+ title : 'topic1' ,
1066+ type : 'topic'
1067+ }
1068+ ] ,
1069+ attachmentsInfo : [ ]
1070+ } ;
1071+ } ;
1072+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1073+ throw new Error ( 'should not have been called' ) ;
1074+ } ;
1075+
1076+ await importExportManager . overrideDuplicates ( req ) ;
1077+ } ) ;
1078+
1079+ it ( 'should rewrite the docs locale when the locale is different' , async function ( ) {
1080+ apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1081+ return {
1082+ docs : [
1083+ {
1084+ _id : '4:fr:draft' ,
1085+ aposMode : 'draft' ,
1086+ aposLocale : 'fr:draft' ,
1087+ title : 'topic1' ,
1088+ type : 'topic'
1089+ }
1090+ ] ,
1091+ attachmentsInfo : [ ]
1092+ } ;
1093+ } ;
1094+ apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1095+ assert . deepEqual ( docs , [
1096+ {
1097+ _id : '4:fr:draft' ,
1098+ aposMode : 'draft' ,
1099+ aposLocale : 'fr:draft' ,
1100+ title : 'topic1' ,
1101+ type : 'topic'
1102+ }
1103+ ] ) ;
1104+
1105+ return rewriteDocsWithCurrentLocale ( req , docs ) ;
1106+ } ;
1107+
1108+ await importExportManager . overrideDuplicates ( req ) ;
1109+ } ) ;
1110+ } ) ;
1111+
1112+ describe ( 'when the site has multiple locales' , function ( ) {
1113+ let _apos ;
1114+ let _req ;
1115+ let _importExportManager ;
1116+
1117+ before ( async function ( ) {
1118+ _apos = await t . create ( {
1119+ root : module ,
1120+ testModule : true ,
1121+ modules : getAppConfig ( {
1122+ '@apostrophecms/express' : {
1123+ options : {
1124+ session : { secret : 'supersecret' } ,
1125+ port : 3001
1126+ }
1127+ } ,
1128+ '@apostrophecms/i18n' : {
1129+ options : {
1130+ defaultLocale : 'en' ,
1131+ locales : {
1132+ en : { label : 'English' } ,
1133+ fr : {
1134+ label : 'French' ,
1135+ prefix : '/fr'
1136+ }
1137+ }
1138+ }
1139+ }
1140+ } )
1141+ } ) ;
1142+
1143+ _req = _apos . task . getReq ( {
1144+ locale : 'en' ,
1145+ body : { }
1146+ } ) ;
1147+
1148+ _importExportManager = _apos . modules [ '@apostrophecms/import-export' ] ;
1149+ } ) ;
1150+
1151+ after ( async function ( ) {
1152+ await t . destroy ( _apos ) ;
1153+ } ) ;
1154+
1155+ this . beforeEach ( async function ( ) {
1156+ jobManager = _apos . modules [ '@apostrophecms/job' ] ;
1157+
1158+ jobManager . success = ( ) => { } ;
1159+ jobManager . failure = ( ) => { } ;
1160+ } ) ;
1161+
1162+ it ( 'should not rewrite the docs locale when the locale is not different' , async function ( ) {
1163+ _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1164+ return {
1165+ docs : [
1166+ {
1167+ _id : '4:en:draft' ,
1168+ aposMode : 'draft' ,
1169+ aposLocale : 'en:draft' ,
1170+ title : 'topic1' ,
1171+ type : 'topic'
1172+ }
1173+ ] ,
1174+ attachmentsInfo : [ ]
1175+ } ;
1176+ } ;
1177+ _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1178+ throw new Error ( 'should not have been called' ) ;
1179+ } ;
1180+
1181+ await _importExportManager . overrideDuplicates ( _req ) ;
1182+ } ) ;
1183+
1184+ 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 ( {
1186+ locale : 'en' ,
1187+ body : {
1188+ overrideLocale : true
1189+ }
1190+ } ) ;
1191+
1192+ _apos . modules [ '@apostrophecms/import-export' ] . getFilesData = async exportPath => {
1193+ return {
1194+ docs : [
1195+ {
1196+ _id : '4:fr:draft' ,
1197+ aposMode : 'draft' ,
1198+ aposLocale : 'fr:draft' ,
1199+ title : 'topic1' ,
1200+ type : 'topic'
1201+ }
1202+ ] ,
1203+ attachmentsInfo : [ ]
1204+ } ;
1205+ } ;
1206+ _apos . modules [ '@apostrophecms/import-export' ] . rewriteDocsWithCurrentLocale = ( req , docs ) => {
1207+ assert . deepEqual ( docs , [
1208+ {
1209+ _id : '4:fr:draft' ,
1210+ aposMode : 'draft' ,
1211+ aposLocale : 'fr:draft' ,
1212+ title : 'topic1' ,
1213+ type : 'topic'
1214+ }
1215+ ] ) ;
1216+
1217+ return rewriteDocsWithCurrentLocale ( req , docs ) ;
1218+ } ;
1219+
1220+ await _importExportManager . overrideDuplicates ( _req ) ;
1221+ } ) ;
1222+ } ) ;
1223+ } ) ;
10241224} ) ;
10251225
10261226function extractFileNames ( files ) {
0 commit comments