@@ -205,165 +205,52 @@ describe('grpc/main', () => {
205205 expect ( res ) . toEqual ( '' ) ;
206206 } ) ;
207207
208- describe ( 'state' , ( ) => {
209- it ( 'should be able to save the state' , async ( ) => {
210- await client . state . save ( 'state-redis' , [
211- {
212- key : 'key-1' ,
213- value : 'value-1' ,
214- } ,
215- {
216- key : 'key-2' ,
217- value : 2 ,
218- } ,
219- {
220- key : 'key-3' ,
221- value : true ,
222- } ,
223- {
224- key : 'key-4' ,
225- value : {
226- nested : {
227- str : 'string' ,
228- num : 123 ,
229- } ,
230- } ,
231- } ,
232- ] ) ;
233-
234- const res = await Promise . all ( [
235- client . state . get ( 'state-redis' , 'key-1' ) ,
236- client . state . get ( 'state-redis' , 'key-2' ) ,
237- client . state . get ( 'state-redis' , 'key-3' ) ,
238- client . state . get ( 'state-redis' , 'key-4' ) ,
239- ] ) ;
240-
241- expect ( res ) . toEqual ( [
242- 'value-1' ,
243- 2 ,
244- true ,
245- {
246- nested : {
247- str : 'string' ,
248- num : 123 ,
249- } ,
250- } ,
251- ] ) ;
252- } ) ;
253-
254- it ( 'should be able to get the state in bulk' , async ( ) => {
255- await client . state . save ( 'state-redis' , [
256- {
257- key : 'key-1' ,
258- value : 'value-1' ,
259- } ,
260- {
261- key : 'key-2' ,
262- value : 2 ,
263- } ,
264- {
265- key : 'key-3' ,
266- value : true ,
267- } ,
268- {
269- key : 'key-4' ,
270- value : {
271- nested : {
272- str : 'string' ,
273- num : 123 ,
274- } ,
275- } ,
276- } ,
277- ] ) ;
278-
279- const res = await client . state . getBulk ( 'state-redis' , [ 'key-3' , 'key-2' , 'key-1' , 'key-4' ] ) ;
280-
281- expect ( res ) . toEqual (
282- expect . arrayContaining ( [
283- expect . objectContaining ( { key : 'key-1' , data : 'value-1' } ) ,
284- expect . objectContaining ( { key : 'key-2' , data : 2 } ) ,
285- expect . objectContaining ( { key : 'key-3' , data : true } ) ,
286- expect . objectContaining ( {
287- key : 'key-4' ,
288- data : {
289- nested : {
290- str : 'string' ,
291- num : 123 ,
292- } ,
293- } ,
294- } ) ,
295- ] ) ,
296- ) ;
297- } ) ;
298-
299- it ( 'should be able to delete a key from the state store' , async ( ) => {
300- await client . state . save ( 'state-redis' , [
301- {
208+ it ( 'should be able to perform a transaction that replaces a key and deletes another' , async ( ) => {
209+ await client . state . transaction ( 'state-redis' , [
210+ {
211+ operation : 'upsert' ,
212+ request : {
302213 key : 'key-1' ,
303- value : 'value-1' ,
304- } ,
305- {
306- key : 'key-2' ,
307- value : 'value-2' ,
214+ value : 'my-new-data-1' ,
308215 } ,
309- {
216+ } ,
217+ {
218+ operation : 'delete' ,
219+ request : {
310220 key : 'key-3' ,
311- value : 'value-3' ,
312221 } ,
313- ] ) ;
222+ } ,
223+ ] ) ;
314224
315- await client . state . delete ( 'state-redis' , 'key-2' ) ;
316- const res = await client . state . get ( 'state-redis' , 'key-2' ) ;
317- expect ( res ) . toEqual ( '' ) ;
318- } ) ;
225+ const resTransactionDelete = await client . state . get ( 'state-redis' , 'key-3' ) ;
226+ const resTransactionUpsert = await client . state . get ( 'state-redis' , 'key-1' ) ;
227+ expect ( resTransactionDelete ) . toEqual ( '' ) ;
228+ expect ( resTransactionUpsert ) . toEqual ( 'my-new-data-1' ) ;
229+ } ) ;
319230
320- it ( 'should be able to perform a transaction that replaces a key and deletes another' , async ( ) => {
321- await client . state . transaction ( 'state-redis' , [
322- {
323- operation : 'upsert' ,
324- request : {
325- key : 'key-1' ,
326- value : 'my-new-data-1' ,
327- } ,
231+ it ( 'should be able to perform a transaction with metadata' , async ( ) => {
232+ await client . state . transaction ( 'state-redis' , [
233+ {
234+ operation : 'upsert' ,
235+ request : {
236+ key : 'key-with-metadata-1' ,
237+ value : 'my-new-data-with-metadata-1' ,
328238 } ,
329- {
330- operation : 'delete' ,
331- request : {
332- key : 'key-3' ,
333- } ,
239+ } ,
240+ {
241+ operation : 'delete' ,
242+ request : {
243+ key : 'key-with-metadata-2' ,
334244 } ,
335- ] ) ;
336-
337- const resTransactionDelete = await client . state . get ( 'state-redis' , 'key-3' ) ;
338- const resTransactionUpsert = await client . state . get ( 'state-redis' , 'key-1' ) ;
339- expect ( resTransactionDelete ) . toEqual ( '' ) ;
340- expect ( resTransactionUpsert ) . toEqual ( 'my-new-data-1' ) ;
245+ } ,
246+ ] , {
247+ trace_id : 'mock trace id here' ,
341248 } ) ;
342249
343- it ( 'should be able to perform a transaction with metadata' , async ( ) => {
344- await client . state . transaction ( 'state-redis' , [
345- {
346- operation : 'upsert' ,
347- request : {
348- key : 'key-with-metadata-1' ,
349- value : 'my-new-data-with-metadata-1' ,
350- } ,
351- } ,
352- {
353- operation : 'delete' ,
354- request : {
355- key : 'key-with-metadata-2' ,
356- } ,
357- } ,
358- ] , {
359- trace_id : 'mock trace id here' ,
360- } ) ;
361-
362- const resTransactionDelete = await client . state . get ( 'state-redis' , 'key-with-metadata-2' ) ;
363- const resTransactionUpsert = await client . state . get ( 'state-redis' , 'key-with-metadata-1' ) ;
364- expect ( resTransactionDelete ) . toEqual ( '' ) ;
365- expect ( resTransactionUpsert ) . toEqual ( 'my-new-data-with-metadata-1' ) ;
366- } ) ;
250+ const resTransactionDelete = await client . state . get ( 'state-redis' , 'key-with-metadata-2' ) ;
251+ const resTransactionUpsert = await client . state . get ( 'state-redis' , 'key-with-metadata-1' ) ;
252+ expect ( resTransactionDelete ) . toEqual ( '' ) ;
253+ expect ( resTransactionUpsert ) . toEqual ( 'my-new-data-with-metadata-1' ) ;
367254 } ) ;
368255 } ) ;
369256
0 commit comments