21
21
// SOFTWARE.
22
22
23
23
import { expect } from 'chai' ;
24
+ import { PathPattern } from '../../../src/utilities/path-pattern' ;
24
25
import * as database from '../../../src/v2/providers/database' ;
25
26
26
27
const RAW_RTDB_EVENT : database . RawRTDBCloudEvent = {
@@ -41,144 +42,6 @@ const RAW_RTDB_EVENT: database.RawRTDBCloudEvent = {
41
42
type : 'type' ,
42
43
} ;
43
44
44
- describe ( 'matchParams' , ( ) => {
45
- it ( 'should parse without multi segment' , ( ) => {
46
- const params = { } ;
47
-
48
- database . matchParams (
49
- '{a}/something/else/{b}/end/{c}' . split ( '/' ) ,
50
- [ '{a}' , '{b}' , '{c}' ] ,
51
- 'match_a/something/else/match_b/end/match_c' . split ( '/' ) ,
52
- params
53
- ) ;
54
-
55
- expect ( params ) . to . deep . equal ( {
56
- a : 'match_a' ,
57
- b : 'match_b' ,
58
- c : 'match_c' ,
59
- } ) ;
60
- } ) ;
61
-
62
- it ( 'should parse multi segment with params after' , ( ) => {
63
- const params = { } ;
64
-
65
- database . matchParams (
66
- 'something/**/else/{a}/hello/{b}/world' . split ( '/' ) ,
67
- [ '{a}' , '{b}' ] ,
68
- 'something/is/a/thing/else/nothing/hello/user/world' . split ( '/' ) ,
69
- params
70
- ) ;
71
-
72
- expect ( params ) . to . deep . equal ( {
73
- a : 'nothing' ,
74
- b : 'user' ,
75
- } ) ;
76
- } ) ;
77
-
78
- it ( 'should parse multi segment param with params after' , ( ) => {
79
- const params = { } ;
80
-
81
- database . matchParams (
82
- 'something/{path=**}/else/{a}/hello/{b}/world' . split ( '/' ) ,
83
- [ '{path=**}' , '{a}' , '{b}' ] ,
84
- 'something/is/a/thing/else/nothing/hello/user/world' . split ( '/' ) ,
85
- params
86
- ) ;
87
-
88
- expect ( params ) . to . deep . equal ( {
89
- path : 'is/a/thing' ,
90
- a : 'nothing' ,
91
- b : 'user' ,
92
- } ) ;
93
- } ) ;
94
-
95
- it ( 'should parse multi segment with params before' , ( ) => {
96
- const params = { } ;
97
-
98
- database . matchParams (
99
- '{a}/something/{b}/**/end' . split ( '/' ) ,
100
- [ '{a}' , '{b}' ] ,
101
- 'match_a/something/match_b/thing/else/nothing/hello/user/end' . split ( '/' ) ,
102
- params
103
- ) ;
104
-
105
- expect ( params ) . to . deep . equal ( {
106
- a : 'match_a' ,
107
- b : 'match_b' ,
108
- } ) ;
109
- } ) ;
110
-
111
- it ( 'should parse multi segment param with params before' , ( ) => {
112
- const params = { } ;
113
-
114
- database . matchParams (
115
- '{a}/something/{b}/{path=**}/end' . split ( '/' ) ,
116
- [ '{a}' , '{b}' , '{path=**}' ] ,
117
- 'match_a/something/match_b/thing/else/nothing/hello/user/end' . split ( '/' ) ,
118
- params
119
- ) ;
120
-
121
- expect ( params ) . to . deep . equal ( {
122
- a : 'match_a' ,
123
- b : 'match_b' ,
124
- path : 'thing/else/nothing/hello/user' ,
125
- } ) ;
126
- } ) ;
127
-
128
- it ( 'should parse multi segment with params before and after' , ( ) => {
129
- const params = { } ;
130
-
131
- database . matchParams (
132
- '{a}/something/**/{b}/end' . split ( '/' ) ,
133
- [ '{a}' , '{b}' ] ,
134
- 'match_a/something/thing/else/nothing/hello/user/match_b/end' . split ( '/' ) ,
135
- params
136
- ) ;
137
-
138
- expect ( params ) . to . deep . equal ( {
139
- a : 'match_a' ,
140
- b : 'match_b' ,
141
- } ) ;
142
- } ) ;
143
-
144
- it ( 'should parse multi segment param with params before' , ( ) => {
145
- const params = { } ;
146
-
147
- database . matchParams (
148
- '{a}/something/{path=**}/{b}/end' . split ( '/' ) ,
149
- [ '{a}' , '{path=**}' , '{b}' ] ,
150
- 'match_a/something/thing/else/nothing/hello/user/match_b/end' . split ( '/' ) ,
151
- params
152
- ) ;
153
-
154
- expect ( params ) . to . deep . equal ( {
155
- a : 'match_a' ,
156
- b : 'match_b' ,
157
- path : 'thing/else/nothing/hello/user' ,
158
- } ) ;
159
- } ) ;
160
-
161
- // handle an instance param
162
- it ( 'should parse an instance' , ( ) => {
163
- const params = { } ;
164
-
165
- database . matchParams (
166
- [ '{a}-something-{b}-else-{c}' ] ,
167
- [ '{a}' , '{b}' , '{c}' ] ,
168
- [ 'match_a-something-match_b-else-match_c' ] ,
169
- params
170
- ) ;
171
-
172
- expect ( params ) . to . deep . equal ( { } ) ;
173
-
174
- database . matchParams ( [ '{a}' ] , [ '{a}' ] , [ 'match_a' ] , params ) ;
175
-
176
- expect ( params ) . to . deep . equal ( {
177
- a : 'match_a' ,
178
- } ) ;
179
- } ) ;
180
- } ) ;
181
-
182
45
describe ( 'makeParams' , ( ) => {
183
46
it ( 'should make params with basic path' , ( ) => {
184
47
const event : database . RawRTDBCloudEvent = {
@@ -187,7 +50,11 @@ describe('makeParams', () => {
187
50
} ;
188
51
189
52
expect (
190
- database . makeParams ( event , '{a}/something/else/*/end/{b}' , '*' )
53
+ database . makeParams (
54
+ event ,
55
+ new PathPattern ( '{a}/something/else/*/end/{b}' ) ,
56
+ new PathPattern ( '*' )
57
+ )
191
58
) . to . deep . equal ( {
192
59
a : 'match_a' ,
193
60
b : 'match_b' ,
@@ -201,7 +68,11 @@ describe('makeParams', () => {
201
68
} ;
202
69
203
70
expect (
204
- database . makeParams ( event , 'something/**/else/{a}/hello/{b}/world' , '*' )
71
+ database . makeParams (
72
+ event ,
73
+ new PathPattern ( 'something/**/else/{a}/hello/{b}/world' ) ,
74
+ new PathPattern ( '*' )
75
+ )
205
76
) . to . deep . equal ( {
206
77
a : 'match_a' ,
207
78
b : 'match_b' ,
@@ -217,8 +88,8 @@ describe('makeParams', () => {
217
88
expect (
218
89
database . makeParams (
219
90
event ,
220
- 'something/{path=**}/else/{a}/hello/{b}/world' ,
221
- '*'
91
+ new PathPattern ( 'something/{path=**}/else/{a}/hello/{b}/world' ) ,
92
+ new PathPattern ( '*' )
222
93
)
223
94
) . to . deep . equal ( {
224
95
path : 'is/a/thing' ,
@@ -236,8 +107,8 @@ describe('makeParams', () => {
236
107
expect (
237
108
database . makeParams (
238
109
event ,
239
- 'something/{path=**}/else/{a}/hello/{b}/world' ,
240
- '{inst}'
110
+ new PathPattern ( 'something/{path=**}/else/{a}/hello/{b}/world' ) ,
111
+ new PathPattern ( '{inst}' )
241
112
)
242
113
) . to . deep . equal ( {
243
114
path : 'is/a/thing' ,
@@ -279,8 +150,7 @@ describe('onOperation', () => {
279
150
const func = database . onOperation (
280
151
database . writtenEventType ,
281
152
'/foo/{bar}/' ,
282
- ( event ) => 2 ,
283
- true
153
+ ( event ) => 2
284
154
) ;
285
155
286
156
expect ( func . __endpoint ) . to . deep . equal ( {
@@ -302,8 +172,7 @@ describe('onOperation', () => {
302
172
const func = database . onOperation (
303
173
database . createdEventType ,
304
174
'/foo/{bar}/' ,
305
- ( event ) => 2 ,
306
- true
175
+ ( event ) => 2
307
176
) ;
308
177
309
178
expect ( func . __endpoint ) . to . deep . equal ( {
@@ -325,8 +194,7 @@ describe('onOperation', () => {
325
194
const func = database . onOperation (
326
195
database . updatedEventType ,
327
196
'/foo/{bar}/' ,
328
- ( event ) => 2 ,
329
- true
197
+ ( event ) => 2
330
198
) ;
331
199
332
200
expect ( func . __endpoint ) . to . deep . equal ( {
@@ -348,8 +216,7 @@ describe('onOperation', () => {
348
216
const func = database . onOperation (
349
217
database . deletedEventType ,
350
218
'/foo/{bar}/' ,
351
- ( event ) => 2 ,
352
- true
219
+ ( event ) => 2
353
220
) ;
354
221
355
222
expect ( func . __endpoint ) . to . deep . equal ( {
@@ -377,8 +244,7 @@ describe('onOperation', () => {
377
244
cpu : 'gcf_gen1' ,
378
245
minInstances : 2 ,
379
246
} ,
380
- ( event ) => 2 ,
381
- true
247
+ ( event ) => 2
382
248
) ;
383
249
384
250
expect ( func . __endpoint ) . to . deep . equal ( {
0 commit comments