@@ -9,15 +9,7 @@ const queryHashValue = 'hash';
9
9
const testUserId = 'userId' ;
10
10
const testClassName = 'TestObject' ;
11
11
12
- const ASYNC_TEST_WAIT_TIME = 100 ;
13
-
14
- function resolveAfter ( result , msTimeout ) {
15
- return new Promise ( res => {
16
- setTimeout ( ( ) => {
17
- res ( result ) ;
18
- } , msTimeout ) ;
19
- } ) ;
20
- }
12
+ const timeout = ( ) => jasmine . timeout ( 100 ) ;
21
13
22
14
describe ( 'ParseLiveQueryServer' , function ( ) {
23
15
beforeEach ( function ( done ) {
@@ -760,10 +752,10 @@ describe('ParseLiveQueryServer', function () {
760
752
761
753
// Make sure we send command to client, since _matchesACL is async, we have to
762
754
// wait and check
763
- setTimeout ( function ( ) {
764
- expect ( client . pushDelete ) . toHaveBeenCalled ( ) ;
765
- done ( ) ;
766
- } , ASYNC_TEST_WAIT_TIME ) ;
755
+ await timeout ( ) ;
756
+
757
+ expect ( client . pushDelete ) . toHaveBeenCalled ( ) ;
758
+ done ( ) ;
767
759
} ) ;
768
760
769
761
it ( 'has no subscription and can handle object save command' , async ( ) => {
@@ -795,14 +787,14 @@ describe('ParseLiveQueryServer', function () {
795
787
parseLiveQueryServer . _onAfterSave ( message ) ;
796
788
797
789
// Make sure we do not send command to client
798
- setTimeout ( function ( ) {
799
- expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
800
- expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
801
- expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
802
- expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
803
- expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
804
- done ( ) ;
805
- } , ASYNC_TEST_WAIT_TIME ) ;
790
+ await timeout ( ) ;
791
+
792
+ expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
793
+ expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
794
+ expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
795
+ expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
796
+ expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
797
+ done ( ) ;
806
798
} ) ;
807
799
808
800
it ( 'can handle object enter command which matches some subscriptions' , async done => {
@@ -832,14 +824,14 @@ describe('ParseLiveQueryServer', function () {
832
824
parseLiveQueryServer . _onAfterSave ( message ) ;
833
825
834
826
// Make sure we send enter command to client
835
- setTimeout ( function ( ) {
836
- expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
837
- expect ( client . pushEnter ) . toHaveBeenCalled ( ) ;
838
- expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
839
- expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
840
- expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
841
- done ( ) ;
842
- } , ASYNC_TEST_WAIT_TIME ) ;
827
+ await timeout ( ) ;
828
+
829
+ expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
830
+ expect ( client . pushEnter ) . toHaveBeenCalled ( ) ;
831
+ expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
832
+ expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
833
+ expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
834
+ done ( ) ;
843
835
} ) ;
844
836
845
837
it ( 'can handle object update command which matches some subscriptions' , async done => {
@@ -865,14 +857,14 @@ describe('ParseLiveQueryServer', function () {
865
857
parseLiveQueryServer . _onAfterSave ( message ) ;
866
858
867
859
// Make sure we send update command to client
868
- setTimeout ( function ( ) {
869
- expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
870
- expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
871
- expect ( client . pushUpdate ) . toHaveBeenCalled ( ) ;
872
- expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
873
- expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
874
- done ( ) ;
875
- } , ASYNC_TEST_WAIT_TIME ) ;
860
+ await timeout ( ) ;
861
+
862
+ expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
863
+ expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
864
+ expect ( client . pushUpdate ) . toHaveBeenCalled ( ) ;
865
+ expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
866
+ expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
867
+ done ( ) ;
876
868
} ) ;
877
869
878
870
it ( 'can handle object leave command which matches some subscriptions' , async done => {
@@ -902,22 +894,22 @@ describe('ParseLiveQueryServer', function () {
902
894
parseLiveQueryServer . _onAfterSave ( message ) ;
903
895
904
896
// Make sure we send leave command to client
905
- setTimeout ( function ( ) {
906
- expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
907
- expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
908
- expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
909
- expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
910
- expect ( client . pushLeave ) . toHaveBeenCalled ( ) ;
911
- done ( ) ;
912
- } , ASYNC_TEST_WAIT_TIME ) ;
897
+ await timeout ( ) ;
898
+
899
+ expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
900
+ expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
901
+ expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
902
+ expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
903
+ expect ( client . pushLeave ) . toHaveBeenCalled ( ) ;
904
+ done ( ) ;
913
905
} ) ;
914
906
915
- it ( 'can handle object multiple commands which matches some subscriptions' , async done => {
907
+ it ( 'sends correct events for object with multiple subscriptions' , async done => {
916
908
const parseLiveQueryServer = new ParseLiveQueryServer ( { } ) ;
917
909
918
910
Parse . Cloud . afterLiveQueryEvent ( 'TestObject' , ( ) => {
919
911
// Simulate delay due to trigger, auth, etc.
920
- return resolveAfter ( null , 10 ) ;
912
+ return jasmine . timeout ( 10 ) ;
921
913
} ) ;
922
914
923
915
// Make mock request message
@@ -954,29 +946,29 @@ describe('ParseLiveQueryServer', function () {
954
946
} ;
955
947
parseLiveQueryServer . _matchesACL = function ( ) {
956
948
// Simulate call
957
- return resolveAfter ( true , 10 ) ;
949
+ return jasmine . timeout ( 10 ) . then ( ( ) => true ) ;
958
950
} ;
959
951
parseLiveQueryServer . _onAfterSave ( message ) ;
960
952
961
953
// Make sure we send leave and enter command to client
962
- setTimeout ( function ( ) {
963
- expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
964
- expect ( client . pushEnter ) . toHaveBeenCalledTimes ( 1 ) ;
965
- expect ( client . pushEnter ) . toHaveBeenCalledWith (
966
- requestId3 ,
967
- { key : 'value' , className : 'TestObject' } ,
968
- { key : 'originalValue ' , className : 'TestObject' }
969
- ) ;
970
- expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
971
- expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
972
- expect ( client . pushLeave ) . toHaveBeenCalledTimes ( 1 ) ;
973
- expect ( client . pushLeave ) . toHaveBeenCalledWith (
974
- requestId2 ,
975
- { key : 'value' , className : 'TestObject' } ,
976
- { key : 'originalValue ' , className : 'TestObject' }
977
- ) ;
978
- done ( ) ;
979
- } , ASYNC_TEST_WAIT_TIME ) ;
954
+ await timeout ( ) ;
955
+
956
+ expect ( client . pushCreate ) . not . toHaveBeenCalled ( ) ;
957
+ expect ( client . pushEnter ) . toHaveBeenCalledTimes ( 1 ) ;
958
+ expect ( client . pushEnter ) . toHaveBeenCalledWith (
959
+ requestId3 ,
960
+ { key : 'value ' , className : 'TestObject' } ,
961
+ { key : 'originalValue' , className : 'TestObject' }
962
+ ) ;
963
+ expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
964
+ expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
965
+ expect ( client . pushLeave ) . toHaveBeenCalledTimes ( 1 ) ;
966
+ expect ( client . pushLeave ) . toHaveBeenCalledWith (
967
+ requestId2 ,
968
+ { key : 'value ' , className : 'TestObject' } ,
969
+ { key : 'originalValue' , className : 'TestObject' }
970
+ ) ;
971
+ done ( ) ;
980
972
} ) ;
981
973
982
974
it ( 'can handle update command with original object' , async done => {
@@ -1013,15 +1005,15 @@ describe('ParseLiveQueryServer', function () {
1013
1005
parseLiveQueryServer . _onAfterSave ( message ) ;
1014
1006
1015
1007
// Make sure we send update command to client
1016
- setTimeout ( function ( ) {
1017
- expect ( client . pushUpdate ) . toHaveBeenCalled ( ) ;
1018
- const args = parseWebSocket . send . calls . mostRecent ( ) . args ;
1019
- const toSend = JSON . parse ( args [ 0 ] ) ;
1008
+ await timeout ( ) ;
1020
1009
1021
- expect ( toSend . object ) . toBeDefined ( ) ;
1022
- expect ( toSend . original ) . toBeDefined ( ) ;
1023
- done ( ) ;
1024
- } , ASYNC_TEST_WAIT_TIME ) ;
1010
+ expect ( client . pushUpdate ) . toHaveBeenCalled ( ) ;
1011
+ const args = parseWebSocket . send . calls . mostRecent ( ) . args ;
1012
+ const toSend = JSON . parse ( args [ 0 ] ) ;
1013
+
1014
+ expect ( toSend . object ) . toBeDefined ( ) ;
1015
+ expect ( toSend . original ) . toBeDefined ( ) ;
1016
+ done ( ) ;
1025
1017
} ) ;
1026
1018
1027
1019
it ( 'can handle object create command which matches some subscriptions' , async done => {
@@ -1047,14 +1039,14 @@ describe('ParseLiveQueryServer', function () {
1047
1039
parseLiveQueryServer . _onAfterSave ( message ) ;
1048
1040
1049
1041
// Make sure we send create command to client
1050
- setTimeout ( function ( ) {
1051
- expect ( client . pushCreate ) . toHaveBeenCalled ( ) ;
1052
- expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
1053
- expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
1054
- expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
1055
- expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
1056
- done ( ) ;
1057
- } , ASYNC_TEST_WAIT_TIME ) ;
1042
+ await timeout ( ) ;
1043
+
1044
+ expect ( client . pushCreate ) . toHaveBeenCalled ( ) ;
1045
+ expect ( client . pushEnter ) . not . toHaveBeenCalled ( ) ;
1046
+ expect ( client . pushUpdate ) . not . toHaveBeenCalled ( ) ;
1047
+ expect ( client . pushDelete ) . not . toHaveBeenCalled ( ) ;
1048
+ expect ( client . pushLeave ) . not . toHaveBeenCalled ( ) ;
1049
+ done ( ) ;
1058
1050
} ) ;
1059
1051
1060
1052
it ( 'can handle create command with fields' , async done => {
@@ -1097,14 +1089,14 @@ describe('ParseLiveQueryServer', function () {
1097
1089
parseLiveQueryServer . _onAfterSave ( message ) ;
1098
1090
1099
1091
// Make sure we send create command to client
1100
- setTimeout ( function ( ) {
1101
- expect ( client . pushCreate ) . toHaveBeenCalled ( ) ;
1102
- const args = parseWebSocket . send . calls . mostRecent ( ) . args ;
1103
- const toSend = JSON . parse ( args [ 0 ] ) ;
1104
- expect ( toSend . object ) . toBeDefined ( ) ;
1105
- expect ( toSend . original ) . toBeUndefined ( ) ;
1106
- done ( ) ;
1107
- } , ASYNC_TEST_WAIT_TIME ) ;
1092
+ await timeout ( ) ;
1093
+
1094
+ expect ( client . pushCreate ) . toHaveBeenCalled ( ) ;
1095
+ const args = parseWebSocket . send . calls . mostRecent ( ) . args ;
1096
+ const toSend = JSON . parse ( args [ 0 ] ) ;
1097
+ expect ( toSend . object ) . toBeDefined ( ) ;
1098
+ expect ( toSend . original ) . toBeUndefined ( ) ;
1099
+ done ( ) ;
1108
1100
} ) ;
1109
1101
1110
1102
it ( 'can match subscription for null or undefined parse object' , function ( ) {
0 commit comments