@@ -674,78 +674,64 @@ describe('Installations', () => {
674674 } ) ;
675675 } ) ;
676676
677- it ( 'update android device token with duplicate device token' , done => {
677+ it ( 'update android device token with duplicate device token' , async ( ) => {
678678 const installId1 = '11111111-abcd-abcd-abcd-123456789abc' ;
679679 const installId2 = '22222222-abcd-abcd-abcd-123456789abc' ;
680680 const t =
681681 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' ;
682+
682683 let input = {
683684 installationId : installId1 ,
684685 deviceToken : t ,
685686 deviceType : 'android' ,
686687 } ;
687- let firstObject ;
688- let secondObject ;
689- rest
690- . create ( config , auth . nobody ( config ) , '_Installation' , input )
691- . then ( ( ) => {
692- input = {
693- installationId : installId2 ,
694- deviceType : 'android' ,
695- } ;
696- return rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
697- } )
698- . then ( ( ) =>
699- database . adapter . find (
700- '_Installation' ,
701- installationSchema ,
702- { installationId : installId1 } ,
703- { }
704- )
705- )
706- . then ( results => {
707- firstObject = results [ 0 ] ;
708- expect ( results . length ) . toEqual ( 1 ) ;
709- return database . adapter . find (
710- '_Installation' ,
711- installationSchema ,
712- { installationId : installId2 } ,
713- { }
714- ) ;
715- } )
716- . then ( results => {
717- expect ( results . length ) . toEqual ( 1 ) ;
718- secondObject = results [ 0 ] ;
719- // Update second installation to conflict with first installation
720- input = {
721- objectId : secondObject . objectId ,
722- deviceToken : t ,
723- } ;
724- return rest . update (
725- config ,
726- auth . nobody ( config ) ,
727- '_Installation' ,
728- { objectId : secondObject . objectId } ,
729- input
730- ) ;
731- } )
732- . then ( ( ) =>
733- database . adapter . find (
734- '_Installation' ,
735- installationSchema ,
736- { objectId : firstObject . objectId } ,
737- { }
738- )
739- )
740- . then ( results => {
741- // The first object should have been deleted
742- expect ( results . length ) . toEqual ( 0 ) ;
743- done ( ) ;
744- } )
745- . catch ( error => {
746- jfail ( error ) ;
747- done ( ) ;
748- } ) ;
688+ await rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
689+
690+ input = {
691+ installationId : installId2 ,
692+ deviceType : 'android' ,
693+ } ;
694+ await rest . create ( config , auth . nobody ( config ) , '_Installation' , input ) ;
695+ await delay ( 100 ) ;
696+
697+ let results = await database . adapter . find (
698+ '_Installation' ,
699+ installationSchema ,
700+ { installationId : installId1 } ,
701+ { }
702+ ) ;
703+ expect ( results . length ) . toEqual ( 1 ) ;
704+ const firstObject = results [ 0 ] ;
705+
706+ results = await database . adapter . find (
707+ '_Installation' ,
708+ installationSchema ,
709+ { installationId : installId2 } ,
710+ { }
711+ ) ;
712+ expect ( results . length ) . toEqual ( 1 ) ;
713+ const secondObject = results [ 0 ] ;
714+
715+ // Update second installation to conflict with first installation
716+ input = {
717+ objectId : secondObject . objectId ,
718+ deviceToken : t ,
719+ } ;
720+ await rest . update (
721+ config ,
722+ auth . nobody ( config ) ,
723+ '_Installation' ,
724+ { objectId : secondObject . objectId } ,
725+ input
726+ ) ;
727+ await delay ( 100 ) ;
728+ results = await database . adapter . find (
729+ '_Installation' ,
730+ installationSchema ,
731+ { objectId : firstObject . objectId } ,
732+ { }
733+ ) ;
734+ expect ( results . length ) . toEqual ( 0 ) ;
749735 } ) ;
750736
751737 it ( 'update ios device token with duplicate device token' , done => {
0 commit comments