@@ -62,24 +62,86 @@ describe('DatabaseBuilder', () => {
6262 resource : 'projects/_/instances/subdomains/refs/users' ,
6363 } as any ) ;
6464 } ) ;
65+ } ) ;
6566
66- it ( 'should interpolate params until the server does it' , ( ) => {
67- let handler = database . ref ( '/users/{id}' ) . onWrite ( event => {
68- expect ( event . resource ) . to . equal ( 'projects/_/instances/subdomain/refs/users/aUserId' ) ;
67+ describe ( '#onCreate()' , ( ) => {
68+ it ( 'should return "ref.create" as the event type' , ( ) => {
69+ let eventType = database . ref ( 'foo' ) . onCreate ( ( ) => null ) . __trigger . eventTrigger . eventType ;
70+ expect ( eventType ) . to . eq ( 'providers/google.firebase.database/eventTypes/ref.create' ) ;
71+ } ) ;
72+
73+ it ( 'should construct a proper resource path' , ( ) => {
74+ let resource = database . ref ( 'foo' ) . onCreate ( ( ) => null ) . __trigger . eventTrigger . resource ;
75+ expect ( resource ) . to . eq ( 'projects/_/instances/subdomain/refs/foo' ) ;
76+ } ) ;
77+
78+ it ( 'should return a handler that emits events with a proper DeltaSnapshot' , ( ) => {
79+ let handler = database . ref ( '/users/{id}' ) . onCreate ( event => {
80+ expect ( event . data . val ( ) ) . to . deep . equal ( { foo : 'bar' } ) ;
6981 } ) ;
7082
7183 return handler ( {
7284 data : {
7385 data : null ,
74- delta : 'hello' ,
86+ delta : { foo : 'bar' } ,
7587 } ,
76- resource : 'projects/_/instances/subdomain/refs/users/{id}' ,
77- params : {
78- id : 'aUserId' ,
88+ resource : 'projects/_/instances/subdomains/refs/users' ,
89+ } as any ) ;
90+ } ) ;
91+ } ) ;
92+
93+ describe ( '#onUpdate()' , ( ) => {
94+ it ( 'should return "ref.update" as the event type' , ( ) => {
95+ let eventType = database . ref ( 'foo' ) . onUpdate ( ( ) => null ) . __trigger . eventTrigger . eventType ;
96+ expect ( eventType ) . to . eq ( 'providers/google.firebase.database/eventTypes/ref.update' ) ;
97+ } ) ;
98+
99+ it ( 'should construct a proper resource path' , ( ) => {
100+ let resource = database . ref ( 'foo' ) . onUpdate ( ( ) => null ) . __trigger . eventTrigger . resource ;
101+ expect ( resource ) . to . eq ( 'projects/_/instances/subdomain/refs/foo' ) ;
102+ } ) ;
103+
104+ it ( 'should return a handler that emits events with a proper DeltaSnapshot' , ( ) => {
105+ let handler = database . ref ( '/users/{id}' ) . onUpdate ( event => {
106+ expect ( event . data . val ( ) ) . to . deep . equal ( { foo : 'bar' } ) ;
107+ } ) ;
108+
109+ return handler ( {
110+ data : {
111+ data : null ,
112+ delta : { foo : 'bar' } ,
79113 } ,
114+ resource : 'projects/_/instances/subdomains/refs/users' ,
115+ } as any ) ;
116+ } ) ;
117+ } ) ;
118+
119+ describe ( '#onDelete()' , ( ) => {
120+ it ( 'should return "ref.delete" as the event type' , ( ) => {
121+ let eventType = database . ref ( 'foo' ) . onDelete ( ( ) => null ) . __trigger . eventTrigger . eventType ;
122+ expect ( eventType ) . to . eq ( 'providers/google.firebase.database/eventTypes/ref.delete' ) ;
123+ } ) ;
124+
125+ it ( 'should construct a proper resource path' , ( ) => {
126+ let resource = database . ref ( 'foo' ) . onDelete ( ( ) => null ) . __trigger . eventTrigger . resource ;
127+ expect ( resource ) . to . eq ( 'projects/_/instances/subdomain/refs/foo' ) ;
128+ } ) ;
129+
130+ it ( 'should return a handler that emits events with a proper DeltaSnapshot' , ( ) => {
131+ let handler = database . ref ( '/users/{id}' ) . onDelete ( event => {
132+ expect ( event . data . val ( ) ) . to . deep . equal ( { foo : 'bar' } ) ;
80133 } ) ;
134+
135+ return handler ( {
136+ data : {
137+ data : null ,
138+ delta : { foo : 'bar' } ,
139+ } ,
140+ resource : 'projects/_/instances/subdomains/refs/users' ,
141+ } as any ) ;
81142 } ) ;
82143 } ) ;
144+
83145} ) ;
84146
85147describe ( 'DeltaSnapshot' , ( ) => {
0 commit comments