@@ -39,14 +39,28 @@ describe("client-js", () => {
39
39
c . request ( "foo" , [ ] ) ;
40
40
} ) ;
41
41
42
- it ( "can batch a request" , async ( ) => {
42
+ it ( "can error on batchng a request" , async ( ) => {
43
+ const transport = new EventEmitterTransport ( "foo://unique-uri" ) ;
44
+ const c = new RequestManager ( [ transport ] ) ;
45
+ return c . connect ( ) . then ( ( ) => {
46
+ expect ( ( ) => c . endBatch ( ) ) . toThrow ( ) ;
47
+ } ) ;
48
+ } ) ;
49
+
50
+ it ( "can return errors on batchng requests" , async ( ) => {
43
51
const transport = new EventEmitterTransport ( "foo://unique-uri" ) ;
44
52
transport . sendData = ( data ) => {
45
53
const result = JSON . stringify ( [
46
54
{
47
55
jsonrpc : "2.0" ,
48
56
id : 3 ,
49
- result : "foo" ,
57
+ error : {
58
+ code : 509 ,
59
+ message : "too much 509" ,
60
+ data : {
61
+ test : "data" ,
62
+ } ,
63
+ } ,
50
64
} ,
51
65
{
52
66
jsonrpc : "2.0" ,
@@ -57,6 +71,43 @@ describe("client-js", () => {
57
71
transport . connection . emit ( "message" , result ) ;
58
72
} ;
59
73
74
+ const c = new RequestManager ( [ transport ] ) ;
75
+ return c . connect ( ) . then ( ( ) => {
76
+ c . startBatch ( ) ;
77
+ const requests = [
78
+ c . request ( "foo" , [ ] ) ,
79
+ c . request ( "foo" , [ ] ) ,
80
+ ] ;
81
+ c . endBatch ( ) ;
82
+ expect ( Promise . all ( requests ) ) . rejects . toEqual ( {
83
+ code : 509 ,
84
+ message : "too much 509" ,
85
+ data : {
86
+ test : "data" ,
87
+ } ,
88
+ } ) ;
89
+ c . close ( ) ;
90
+ } ) ;
91
+ } ) ;
92
+
93
+ it ( "can batch a request" , async ( ) => {
94
+ const transport = new EventEmitterTransport ( "foo://unique-uri" ) ;
95
+ transport . sendData = ( data ) => {
96
+ const result = JSON . stringify ( [
97
+ {
98
+ jsonrpc : "2.0" ,
99
+ id : 5 ,
100
+ result : "foo" ,
101
+ } ,
102
+ {
103
+ jsonrpc : "2.0" ,
104
+ id : 6 ,
105
+ result : "bar" ,
106
+ } ,
107
+ ] ) ;
108
+ transport . connection . emit ( "message" , result ) ;
109
+ } ;
110
+
60
111
const c = new RequestManager ( [ transport ] ) ;
61
112
return c . connect ( ) . then ( ( ) => {
62
113
c . startBatch ( ) ;
@@ -81,7 +132,7 @@ describe("client-js", () => {
81
132
transport . connection . on ( "message" , ( ) => {
82
133
fn ( JSON . stringify ( {
83
134
jsonrpc : "2.0" ,
84
- id : 3 ,
135
+ id : 7 ,
85
136
error : {
86
137
code : 0 ,
87
138
message : "out of order" ,
0 commit comments