@@ -49,6 +49,41 @@ void main() {
49
49
expect (configuration.globalMiddleware, isNotNull);
50
50
});
51
51
52
+ test ('endpoint includes multiple routes when conflicts exist' , () {
53
+ final directory = Directory (
54
+ path.join (
55
+ Directory .current.path,
56
+ 'test' ,
57
+ '.fixtures' ,
58
+ 'single_conflict' ,
59
+ ),
60
+ )..createSync (recursive: true );
61
+ final routes = Directory (path.join (directory.path, 'routes' ))
62
+ ..createSync ();
63
+ File (path.join (routes.path, 'users.dart' )).createSync ();
64
+ final usersDirectory = Directory (path.join (routes.path, 'users' ))
65
+ ..createSync ();
66
+ File (path.join (usersDirectory.path, 'index.dart' )).createSync ();
67
+ final configuration = buildRouteConfiguration (directory);
68
+ expect (
69
+ configuration.endpoints,
70
+ equals ({
71
+ '/users' : [
72
+ isA <RouteFile >().having (
73
+ (r) => r.path,
74
+ 'path' ,
75
+ '../routes/users.dart' ,
76
+ ),
77
+ isA <RouteFile >().having (
78
+ (r) => r.path,
79
+ 'path' ,
80
+ '../routes/users/index.dart' ,
81
+ )
82
+ ]
83
+ }),
84
+ );
85
+ });
86
+
52
87
test ('includes single index route' , () {
53
88
const expected = [
54
89
{
@@ -71,6 +106,18 @@ void main() {
71
106
configuration.directories.map ((d) => d.toJson ()).toList (),
72
107
equals (expected),
73
108
);
109
+ expect (
110
+ configuration.endpoints,
111
+ equals ({
112
+ '/' : [
113
+ isA <RouteFile >().having (
114
+ (r) => r.path,
115
+ 'path' ,
116
+ '../routes/index.dart' ,
117
+ )
118
+ ]
119
+ }),
120
+ );
74
121
});
75
122
76
123
test ('includes multiple top-level routes' , () {
@@ -102,6 +149,25 @@ void main() {
102
149
configuration.directories.map ((d) => d.toJson ()).toList (),
103
150
equals (expected),
104
151
);
152
+ expect (
153
+ configuration.endpoints,
154
+ equals ({
155
+ '/' : [
156
+ isA <RouteFile >().having (
157
+ (r) => r.path,
158
+ 'path' ,
159
+ '../routes/index.dart' ,
160
+ )
161
+ ],
162
+ '/hello' : [
163
+ isA <RouteFile >().having (
164
+ (r) => r.path,
165
+ 'path' ,
166
+ '../routes/hello.dart' ,
167
+ )
168
+ ]
169
+ }),
170
+ );
105
171
});
106
172
107
173
test ('includes nested routes' , () {
@@ -141,6 +207,25 @@ void main() {
141
207
configuration.directories.map ((d) => d.toJson ()).toList (),
142
208
equals (expected),
143
209
);
210
+ expect (
211
+ configuration.endpoints,
212
+ equals ({
213
+ '/' : [
214
+ isA <RouteFile >().having (
215
+ (r) => r.path,
216
+ 'path' ,
217
+ '../routes/index.dart' ,
218
+ )
219
+ ],
220
+ '/echo/message' : [
221
+ isA <RouteFile >().having (
222
+ (r) => r.path,
223
+ 'path' ,
224
+ '../routes/echo/message.dart' ,
225
+ )
226
+ ]
227
+ }),
228
+ );
144
229
});
145
230
146
231
test ('includes nested directories' , () {
@@ -185,6 +270,18 @@ void main() {
185
270
configuration.directories.map ((d) => d.toJson ()).toList (),
186
271
equals (expected),
187
272
);
273
+ expect (
274
+ configuration.endpoints,
275
+ equals ({
276
+ '/echo/message' : [
277
+ isA <RouteFile >().having (
278
+ (r) => r.path,
279
+ 'path' ,
280
+ '../routes/echo/message/index.dart' ,
281
+ )
282
+ ]
283
+ }),
284
+ );
188
285
});
189
286
190
287
test ('includes dynamic route' , () {
@@ -224,6 +321,25 @@ void main() {
224
321
configuration.directories.map ((d) => d.toJson ()).toList (),
225
322
equals (expected),
226
323
);
324
+ expect (
325
+ configuration.endpoints,
326
+ equals ({
327
+ '/' : [
328
+ isA <RouteFile >().having (
329
+ (r) => r.path,
330
+ 'path' ,
331
+ '../routes/index.dart' ,
332
+ )
333
+ ],
334
+ '/echo/<message>' : [
335
+ isA <RouteFile >().having (
336
+ (r) => r.path,
337
+ 'path' ,
338
+ '../routes/echo/[message].dart' ,
339
+ )
340
+ ]
341
+ }),
342
+ );
227
343
});
228
344
229
345
test ('includes dynamic nested directory routes' , () {
@@ -269,6 +385,32 @@ void main() {
269
385
configuration.directories.map ((d) => d.toJson ()).toList (),
270
386
equals (expected),
271
387
);
388
+ expect (
389
+ configuration.endpoints,
390
+ equals ({
391
+ '/' : [
392
+ isA <RouteFile >().having (
393
+ (r) => r.path,
394
+ 'path' ,
395
+ '../routes/index.dart' ,
396
+ )
397
+ ],
398
+ '/<user>/<name>' : [
399
+ isA <RouteFile >().having (
400
+ (r) => r.path,
401
+ 'path' ,
402
+ '../routes/[user]/[name].dart' ,
403
+ )
404
+ ],
405
+ '/<user>/<id>' : [
406
+ isA <RouteFile >().having (
407
+ (r) => r.path,
408
+ 'path' ,
409
+ '../routes/[user]/[id]/index.dart' ,
410
+ )
411
+ ]
412
+ }),
413
+ );
272
414
});
273
415
274
416
test ('supports /[id]/api/index.dart' , () {
@@ -308,6 +450,25 @@ void main() {
308
450
configuration.directories.map ((d) => d.toJson ()).toList (),
309
451
equals (expected),
310
452
);
453
+ expect (
454
+ configuration.endpoints,
455
+ equals ({
456
+ '/' : [
457
+ isA <RouteFile >().having (
458
+ (r) => r.path,
459
+ 'path' ,
460
+ '../routes/index.dart' ,
461
+ )
462
+ ],
463
+ '/<id>/api' : [
464
+ isA <RouteFile >().having (
465
+ (r) => r.path,
466
+ 'path' ,
467
+ '../routes/[id]/api/index.dart' ,
468
+ )
469
+ ],
470
+ }),
471
+ );
311
472
});
312
473
313
474
test ('supports /[id]/api/test.dart' , () {
@@ -347,6 +508,25 @@ void main() {
347
508
configuration.directories.map ((d) => d.toJson ()).toList (),
348
509
equals (expected),
349
510
);
511
+ expect (
512
+ configuration.endpoints,
513
+ equals ({
514
+ '/' : [
515
+ isA <RouteFile >().having (
516
+ (r) => r.path,
517
+ 'path' ,
518
+ '../routes/index.dart' ,
519
+ )
520
+ ],
521
+ '/<id>/api/test' : [
522
+ isA <RouteFile >().having (
523
+ (r) => r.path,
524
+ 'path' ,
525
+ '../routes/[id]/api/test.dart' ,
526
+ )
527
+ ],
528
+ }),
529
+ );
350
530
});
351
531
352
532
test ('supports /[id]/api/[name]/index.dart' , () {
@@ -388,6 +568,25 @@ void main() {
388
568
configuration.directories.map ((d) => d.toJson ()).toList (),
389
569
equals (expected),
390
570
);
571
+ expect (
572
+ configuration.endpoints,
573
+ equals ({
574
+ '/' : [
575
+ isA <RouteFile >().having (
576
+ (r) => r.path,
577
+ 'path' ,
578
+ '../routes/index.dart' ,
579
+ )
580
+ ],
581
+ '/<id>/api/<name>' : [
582
+ isA <RouteFile >().having (
583
+ (r) => r.path,
584
+ 'path' ,
585
+ '../routes/[id]/api/[name]/index.dart' ,
586
+ )
587
+ ],
588
+ }),
589
+ );
391
590
});
392
591
393
592
test ('supports /[id]/api/[name]/test.dart' , () {
@@ -429,6 +628,25 @@ void main() {
429
628
configuration.directories.map ((d) => d.toJson ()).toList (),
430
629
equals (expected),
431
630
);
631
+ expect (
632
+ configuration.endpoints,
633
+ equals ({
634
+ '/' : [
635
+ isA <RouteFile >().having (
636
+ (r) => r.path,
637
+ 'path' ,
638
+ '../routes/index.dart' ,
639
+ )
640
+ ],
641
+ '/<id>/api/<name>/test' : [
642
+ isA <RouteFile >().having (
643
+ (r) => r.path,
644
+ 'path' ,
645
+ '../routes/[id]/api/[name]/test.dart' ,
646
+ )
647
+ ],
648
+ }),
649
+ );
432
650
});
433
651
});
434
652
}
0 commit comments