@@ -319,6 +319,57 @@ describe('Store relation data to EmailLabel Table: ', () => {
319319 const response = await DBManager . createEmailLabel ( emailLabelDraft ) ;
320320 expect ( response ) . toBeUndefined ( ) ;
321321 } ) ;
322+
323+ it ( 'Should Add and Remove emailLabel relation to database' , async ( ) => {
324+ const emailUpdateLabels = {
325+ email : {
326+ threadId : 'threadK' ,
327+ key : '12' ,
328+ s3Key : 's3KeyK' ,
329+ subject : 'Greetings' ,
330+ content : '<p>Hello there</p>' ,
331+ preview : 'Hello there' ,
332+ date : '2013-10-07 08:23:20.120' ,
333+ status : 1 ,
334+ unread : false ,
335+ secure : true ,
336+ isMuted : false ,
337+ messageId : 'messageIdK' ,
338+ fromAddress :
'User me <[email protected] >' 339+ } ,
340+ recipients : {
341+ from :
[ 'User me <[email protected] >' ] , 342+ 343+ } ,
344+ labels : [ 3 , 7 ]
345+ } ;
346+ await DBManager . createEmail ( emailUpdateLabels ) ;
347+ const [ email ] = await DBManager . getEmailByKey ( emailUpdateLabels . email . key ) ;
348+ // Add
349+ const emailLabelToAdd = [
350+ { emailId : email . id , labelId : systemLabels . starred . id }
351+ ] ;
352+ const [ addResponse ] = await DBManager . createEmailLabel ( emailLabelToAdd ) ;
353+ expect ( addResponse ) . toEqual ( expect . any ( Number ) ) ;
354+ // Remove
355+ await DBManager . deleteEmailLabel ( {
356+ emailIds : [ email . id ] ,
357+ labelIds : [ systemLabels . starred . id ]
358+ } ) ;
359+ // Check if exists
360+ let existsRelation = false ;
361+ const remainingEmailLabels = await DBManager . getEmailLabelsByEmailId (
362+ email . id
363+ ) ;
364+ for ( const remainingLabel of remainingEmailLabels ) {
365+ const { labelId } = remainingLabel ;
366+ if ( labelId === systemLabels . starred . id ) {
367+ existsRelation = true ;
368+ break ;
369+ }
370+ }
371+ expect ( existsRelation ) . toBe ( false ) ;
372+ } ) ;
322373} ) ;
323374
324375describe ( 'Load data emails from Email Table:' , ( ) => {
0 commit comments