@@ -136,7 +136,7 @@ describe('Members API', function () {
136136 } ) ;
137137 } ) ;
138138
139- it ( 'Can import CSV with minimum one field' , function ( ) {
139+ it ( 'Can import CSV with minimum one field and labels ' , function ( ) {
140140 return request
141141 . post ( localUtils . API . getApiQuery ( `members/upload/` ) )
142142 . field ( 'labels' , [ 'global-label-1' , 'global-label-1' ] )
@@ -184,6 +184,55 @@ describe('Members API', function () {
184184 } ) ;
185185 } ) ;
186186
187+ it ( 'Can import CSV with mapped fields' , function ( ) {
188+ return request
189+ . post ( localUtils . API . getApiQuery ( `members/upload/` ) )
190+ . field ( 'mapping[email]' , 'correo_electrpnico' )
191+ . field ( 'mapping[name]' , 'nombre' )
192+ . attach ( 'membersfile' , path . join ( __dirname , '/../../../../utils/fixtures/csv/members-with-mappings.csv' ) )
193+ . set ( 'Origin' , config . get ( 'url' ) )
194+ . expect ( 'Content-Type' , / j s o n / )
195+ . expect ( 'Cache-Control' , testUtils . cacheRules . private )
196+ . expect ( 201 )
197+ . then ( ( res ) => {
198+ should . not . exist ( res . headers [ 'x-cache-invalidate' ] ) ;
199+ const jsonResponse = res . body ;
200+
201+ should . exist ( jsonResponse ) ;
202+ should . exist ( jsonResponse . meta ) ;
203+ should . exist ( jsonResponse . meta . stats ) ;
204+
205+ jsonResponse . meta . stats . imported . count . should . equal ( 1 ) ;
206+ jsonResponse . meta . stats . invalid . count . should . equal ( 0 ) ;
207+ } )
208+ . then ( ( ) => {
209+ return request
210+ . get ( localUtils . API . getApiQuery ( `members/?search=${ encodeURIComponent ( '[email protected] ' ) } ` ) ) 211+ . set ( 'Origin' , config . get ( 'url' ) )
212+ . expect ( 'Content-Type' , / j s o n / )
213+ . expect ( 'Cache-Control' , testUtils . cacheRules . private )
214+ . expect ( 200 ) ;
215+ } )
216+ . then ( ( res ) => {
217+ should . not . exist ( res . headers [ 'x-cache-invalidate' ] ) ;
218+ const jsonResponse = res . body ;
219+
220+ should . exist ( jsonResponse ) ;
221+ should . exist ( jsonResponse . members ) ;
222+ should . exist ( jsonResponse . members [ 0 ] ) ;
223+
224+ const importedMember1 = jsonResponse . members [ 0 ] ;
225+ should ( importedMember1 . email ) . equal ( '[email protected] ' ) ; 226+ should ( importedMember1 . name ) . equal ( 'Hannah' ) ;
227+ should ( importedMember1 . note ) . equal ( 'no need to map me' ) ;
228+ importedMember1 . subscribed . should . equal ( true ) ;
229+ importedMember1 . comped . should . equal ( false ) ;
230+ importedMember1 . stripe . should . not . be . undefined ( ) ;
231+ importedMember1 . stripe . subscriptions . length . should . equal ( 0 ) ;
232+ importedMember1 . labels . length . should . equal ( 0 ) ;
233+ } ) ;
234+ } ) ;
235+
187236 it ( 'Can import CSV with labels and provide additional labels' , function ( ) {
188237 return request
189238 . post ( localUtils . API . getApiQuery ( `members/upload/` ) )
@@ -274,7 +323,7 @@ describe('Members API', function () {
274323 should . exist ( jsonResponse . new_today ) ;
275324
276325 // 3 from fixtures and 5 imported in previous tests
277- jsonResponse . total . should . equal ( 7 ) ;
326+ jsonResponse . total . should . equal ( 8 ) ;
278327 } ) ;
279328 } ) ;
280329
@@ -298,7 +347,7 @@ describe('Members API', function () {
298347 should . exist ( jsonResponse . new_today ) ;
299348
300349 // 3 from fixtures and 5 imported in previous tests
301- jsonResponse . total . should . equal ( 7 ) ;
350+ jsonResponse . total . should . equal ( 8 ) ;
302351 } ) ;
303352 } ) ;
304353
@@ -322,7 +371,7 @@ describe('Members API', function () {
322371 should . exist ( jsonResponse . new_today ) ;
323372
324373 // 3 from fixtures and 5 imported in previous tests
325- jsonResponse . total . should . equal ( 7 ) ;
374+ jsonResponse . total . should . equal ( 8 ) ;
326375 } ) ;
327376 } ) ;
328377
0 commit comments