@@ -42,6 +42,22 @@ describe('loopback-component-changestreamer', () => {
4242 . expect ( 200 , done ) ;
4343 } ) ;
4444
45+ it ( 'set user headers' , ( done ) => {
46+ const fooID = uuid . v4 ( ) ;
47+ let foo = { id : fooID , foo : 'habba' } ;
48+ http . get ( changesUrl , ( res ) => {
49+ res . pipe ( outStream ) ;
50+ } ) ;
51+ request ( app ) . post ( '/api/Foos' )
52+ . set ( 'X-Auth-Request-User' , 'test@gmail.com' )
53+ . send ( foo )
54+ . expect ( 200 )
55+ . then ( response => {
56+ messages [ 1 ] . should . equal ( `data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${ fooID } ","meta":{"headers":{"x-auth-request-user":"test@gmail.com"}},"data":{"id":"${ fooID } ","foo":"habba"}}\n\n` ) ;
57+ done ( ) ;
58+ } ) ;
59+ } ) ;
60+
4561 it ( 'should write retry timout as first parameter' , ( done ) => {
4662 http . get ( changesUrl , ( res ) => {
4763 res . pipe ( outStream ) ;
@@ -55,7 +71,7 @@ describe('loopback-component-changestreamer', () => {
5571 } ) ;
5672
5773 context ( 'on model create' , ( ) => {
58- it ( 'should write change event with kind kreate ' , ( done ) => {
74+ it ( 'should write change event with kind create ' , ( done ) => {
5975 const fooID = uuid . v4 ( ) ;
6076 const barID = uuid . v4 ( ) ;
6177 http . get ( changesUrl , ( res ) => {
@@ -68,8 +84,8 @@ describe('loopback-component-changestreamer', () => {
6884 } ) ;
6985 setTimeout ( ( ) => {
7086 messages . length . should . be . equal ( 3 ) ;
71- messages [ 1 ] . should . equal ( `data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${ fooID } ","data":{"id":"${ fooID } ","foo":"habba"}}\n\n` ) ;
72- messages [ 2 ] . should . equal ( `data: {"seqNo":1,"modelName":"Bar","kind":"create","target":"${ barID } ","data":{"id":"${ barID } ","bar":"bahha"}}\n\n` ) ;
87+ messages [ 1 ] . should . equal ( `data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${ fooID } ","meta":{"headers":[]}," data":{"id":"${ fooID } ","foo":"habba"}}\n\n` ) ;
88+ messages [ 2 ] . should . equal ( `data: {"seqNo":1,"modelName":"Bar","kind":"create","target":"${ barID } ","meta":{"headers":[]}," data":{"id":"${ barID } ","bar":"bahha"}}\n\n` ) ;
7389 done ( ) ;
7490 } , 2000 ) ;
7591 } ) ;
@@ -114,7 +130,7 @@ describe('loopback-component-changestreamer', () => {
114130 } ) ;
115131 setTimeout ( ( ) => {
116132 messages . length . should . be . equal ( 2 ) ;
117- messages [ 1 ] . should . equal ( `data: {"seqNo":2,"modelName":"Foo","kind":"update","target":"${ fooID } ","data":{"id":"${ fooID } ","foo":"baz"}}\n\n` ) ;
133+ messages [ 1 ] . should . equal ( `data: {"seqNo":2,"modelName":"Foo","kind":"update","target":"${ fooID } ","meta":{"headers":[]}," data":{"id":"${ fooID } ","foo":"baz"}}\n\n` ) ;
118134 done ( ) ;
119135 } , 2000 ) ;
120136 } ) ;
@@ -128,7 +144,7 @@ describe('loopback-component-changestreamer', () => {
128144 } ) ;
129145 setTimeout ( ( ) => {
130146 messages . length . should . be . equal ( 2 ) ;
131- messages [ 1 ] . should . equal ( `data: {"seqNo":2,"modelName":"Bar","kind":"remove","target":"${ barID } ","where":{"id":"${ barID } "},"data":{"id":"${ barID } ","bar":"bar"}}\n\n` ) ;
147+ messages [ 1 ] . should . equal ( `data: {"seqNo":2,"modelName":"Bar","kind":"remove","target":"${ barID } ","where":{"id":"${ barID } "},"meta":{"headers":[]}," data":{"id":"${ barID } ","bar":"bar"}}\n\n` ) ;
132148 done ( ) ;
133149 } , 2000 ) ;
134150 } ) ;
0 commit comments