1717 * limitations under the License.
1818 */
1919
20- import { EagerResult , newError , Record , Result , ResultSummary } from '../src'
21- import { createEagerResultFromResult } from '../src/result-eager'
22- import ResultStreamObserverMock from './utils/result-stream-observer.mock'
20+ import { EagerResult , Record , ResultSummary } from '../src'
2321
2422describe ( 'EagerResult' , ( ) => {
2523 it ( 'should construct with keys, records and summary' , ( ) => {
@@ -34,81 +32,3 @@ describe('EagerResult', () => {
3432 expect ( eagerResult . summary ) . toBe ( summary )
3533 } )
3634} )
37-
38- describe ( 'createEagerResultFromResult' , ( ) => {
39- describe ( 'with a valid result' , ( ) => {
40- it ( 'it should return an EagerResult' , async ( ) => {
41- const resultStreamObserverMock = new ResultStreamObserverMock ( )
42- const query = 'Query'
43- const params = { a : 1 }
44- const meta = { db : 'adb' }
45- const result = new Result ( Promise . resolve ( resultStreamObserverMock ) , query , params )
46- const keys = [ 'a' , 'b' ]
47- const rawRecord1 = [ 1 , 2 ]
48- const rawRecord2 = [ 3 , 4 ]
49- resultStreamObserverMock . onKeys ( keys )
50- resultStreamObserverMock . onNext ( rawRecord1 )
51- resultStreamObserverMock . onNext ( rawRecord2 )
52- resultStreamObserverMock . onCompleted ( meta )
53-
54- const eagerResult : EagerResult = await createEagerResultFromResult ( result )
55-
56- expect ( eagerResult . keys ) . toEqual ( keys )
57- expect ( eagerResult . records ) . toEqual ( [
58- new Record ( keys , rawRecord1 ) ,
59- new Record ( keys , rawRecord2 )
60- ] )
61- expect ( eagerResult . summary ) . toEqual (
62- new ResultSummary ( query , params , meta )
63- )
64- } )
65-
66- it ( 'it should return a type-safe EagerResult' , async ( ) => {
67- interface Car {
68- model : string
69- year : number
70- }
71- const resultStreamObserverMock = new ResultStreamObserverMock ( )
72- const query = 'Query'
73- const params = { a : 1 }
74- const meta = { db : 'adb' }
75- const result = new Result ( Promise . resolve ( resultStreamObserverMock ) , query , params )
76- const keys = [ 'model' , 'year' ]
77- const rawRecord1 = [ 'Beautiful Sedan' , 1987 ]
78- const rawRecord2 = [ 'Hot Hatch' , 1995 ]
79-
80- resultStreamObserverMock . onKeys ( keys )
81- resultStreamObserverMock . onNext ( rawRecord1 )
82- resultStreamObserverMock . onNext ( rawRecord2 )
83- resultStreamObserverMock . onCompleted ( meta )
84-
85- const eagerResult : EagerResult < Car > = await createEagerResultFromResult ( result )
86-
87- expect ( eagerResult . keys ) . toEqual ( keys )
88- expect ( eagerResult . records ) . toEqual ( [
89- new Record ( keys , rawRecord1 ) ,
90- new Record ( keys , rawRecord2 )
91- ] )
92- expect ( eagerResult . summary ) . toEqual (
93- new ResultSummary ( query , params , meta )
94- )
95-
96- const [ car1 , car2 ] = eagerResult . records . map ( record => record . toObject ( ) )
97-
98- expect ( car1 . model ) . toEqual ( rawRecord1 [ 0 ] )
99- expect ( car1 . year ) . toEqual ( rawRecord1 [ 1 ] )
100-
101- expect ( car2 . model ) . toEqual ( rawRecord2 [ 0 ] )
102- expect ( car2 . year ) . toEqual ( rawRecord2 [ 1 ] )
103- } )
104- } )
105-
106- describe ( 'when results fail' , ( ) => {
107- it ( 'should propagate the exception' , async ( ) => {
108- const expectedError = newError ( 'expected error' )
109- const result = new Result ( Promise . reject ( expectedError ) , 'query' )
110-
111- await expect ( createEagerResultFromResult ( result ) ) . rejects . toThrow ( expectedError )
112- } )
113- } )
114- } )
0 commit comments