@@ -939,8 +939,33 @@ describe('Result', () => {
939
939
const it = result [ Symbol . asyncIterator ] ( )
940
940
await it . next ( )
941
941
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
942
- const { value , done } = await it . return ! ( summary )
942
+ const summaryPromise = it . return ! ( summary )
943
943
944
+ streamObserverMock . onCompleted ( { } )
945
+
946
+ const { value, done } = await summaryPromise
947
+ expect ( value ) . toBe ( summary )
948
+ expect ( done ) . toEqual ( true )
949
+ } )
950
+
951
+ it ( 'should return resultant summary when it get called without params' , async ( ) => {
952
+ const keys = [ 'a' , 'b' ]
953
+ const rawRecord1 = [ 1 , 2 ]
954
+ const rawRecord2 = [ 3 , 4 ]
955
+ const summary = new ResultSummary ( 'query' , { } , { } )
956
+
957
+ streamObserverMock . onKeys ( keys )
958
+ streamObserverMock . onNext ( rawRecord1 )
959
+ streamObserverMock . onNext ( rawRecord2 )
960
+
961
+ const it = result [ Symbol . asyncIterator ] ( )
962
+ await it . next ( )
963
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
964
+ const summaryPromise = it . return ! ( )
965
+
966
+ streamObserverMock . onCompleted ( { } )
967
+
968
+ const { value, done } = await summaryPromise
944
969
expect ( value ) . toEqual ( summary )
945
970
expect ( done ) . toEqual ( true )
946
971
} )
@@ -953,6 +978,7 @@ describe('Result', () => {
953
978
streamObserverMock . onKeys ( keys )
954
979
streamObserverMock . onNext ( rawRecord1 )
955
980
streamObserverMock . onNext ( rawRecord2 )
981
+ streamObserverMock . onCompleted ( { } )
956
982
957
983
const it = result [ Symbol . asyncIterator ] ( )
958
984
@@ -966,8 +992,9 @@ describe('Result', () => {
966
992
expect ( done ) . toEqual ( true )
967
993
} )
968
994
969
- it ( 'should not subscribe to the observer when it is the first api called' , async ( ) => {
995
+ it ( 'should subscribe to the observer when it is the first api called' , async ( ) => {
970
996
const subscribe = jest . spyOn ( streamObserverMock , 'subscribe' )
997
+ streamObserverMock . onCompleted ( { } )
971
998
972
999
const it = result [ Symbol . asyncIterator ] ( )
973
1000
@@ -976,11 +1003,12 @@ describe('Result', () => {
976
1003
977
1004
await it . next ( )
978
1005
979
- expect ( subscribe ) . not . toBeCalled ( )
1006
+ expect ( subscribe ) . toBeCalled ( )
980
1007
} )
981
1008
982
1009
it ( 'should not canceld stream when it is the first api called' , async ( ) => {
983
1010
const cancel = jest . spyOn ( streamObserverMock , 'cancel' )
1011
+ streamObserverMock . onCompleted ( { } )
984
1012
985
1013
const it = result [ Symbol . asyncIterator ] ( )
986
1014
@@ -1001,6 +1029,7 @@ describe('Result', () => {
1001
1029
streamObserverMock . onKeys ( keys )
1002
1030
streamObserverMock . onNext ( rawRecord1 )
1003
1031
streamObserverMock . onNext ( rawRecord2 )
1032
+ streamObserverMock . onCompleted ( { } )
1004
1033
1005
1034
const it = result [ Symbol . asyncIterator ] ( )
1006
1035
@@ -1013,26 +1042,28 @@ describe('Result', () => {
1013
1042
1014
1043
it ( 'should prevent following next requests to subscribe to the stream' , async ( ) => {
1015
1044
const subscribe = jest . spyOn ( streamObserverMock , 'subscribe' )
1045
+ streamObserverMock . onCompleted ( { } )
1016
1046
1017
1047
const it = result [ Symbol . asyncIterator ] ( )
1018
1048
1019
1049
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1020
1050
await it . return ! ( new ResultSummary ( 'query' , { } , { } ) )
1021
1051
await it . next ( )
1022
1052
1023
- expect ( subscribe ) . not . toBeCalled ( )
1053
+ expect ( subscribe ) . toBeCalledTimes ( 1 )
1024
1054
} )
1025
1055
1026
1056
it ( 'should prevent following peek requests to subscribe to the stream' , async ( ) => {
1027
1057
const subscribe = jest . spyOn ( streamObserverMock , 'subscribe' )
1058
+ streamObserverMock . onCompleted ( { } )
1028
1059
1029
1060
const it = result [ Symbol . asyncIterator ] ( )
1030
1061
1031
1062
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1032
1063
await it . return ! ( new ResultSummary ( 'query' , { } , { } ) )
1033
1064
await it . peek ( )
1034
1065
1035
- expect ( subscribe ) . not . toBeCalled ( )
1066
+ expect ( subscribe ) . toBeCalledTimes ( 1 )
1036
1067
} )
1037
1068
} )
1038
1069
0 commit comments