@@ -4,13 +4,38 @@ import 'package:test/test.dart';
4
4
void main () {
5
5
test ('uri generation' , () {
6
6
final d = StandardUriDesign .pathOnly;
7
+ expect (d.base .path, equals ('/' ));
7
8
expect (d.collection ('books' ).toString (), '/books' );
8
9
expect (d.resource ('books' , '42' ).toString (), '/books/42' );
9
10
expect (d.related ('books' , '42' , 'author' ).toString (), '/books/42/author' );
10
11
expect (d.relationship ('books' , '42' , 'author' ).toString (),
11
12
'/books/42/relationships/author' );
12
13
});
13
14
15
+ test ('uri generation with base, trailing slash' , () {
16
+ final d = StandardUriDesign (Uri .parse ('https://example.com/api/' ));
17
+ expect (d.base .path, equals ('/api/' ));
18
+ expect (d.collection ('books' ).toString (), 'https://example.com/api/books' );
19
+ expect (d.resource ('books' , '42' ).toString (),
20
+ 'https://example.com/api/books/42' );
21
+ expect (d.related ('books' , '42' , 'author' ).toString (),
22
+ 'https://example.com/api/books/42/author' );
23
+ expect (d.relationship ('books' , '42' , 'author' ).toString (),
24
+ 'https://example.com/api/books/42/relationships/author' );
25
+ });
26
+
27
+ test ('uri generation with base, no trailing slash' , () {
28
+ final d = StandardUriDesign (Uri .parse ('https://example.com/api' ));
29
+ expect (d.base .path, equals ('/api/' ));
30
+ expect (d.collection ('books' ).toString (), 'https://example.com/api/books' );
31
+ expect (d.resource ('books' , '42' ).toString (),
32
+ 'https://example.com/api/books/42' );
33
+ expect (d.related ('books' , '42' , 'author' ).toString (),
34
+ 'https://example.com/api/books/42/author' );
35
+ expect (d.relationship ('books' , '42' , 'author' ).toString (),
36
+ 'https://example.com/api/books/42/relationships/author' );
37
+ });
38
+
14
39
test ('Authority is retained if exists in base' , () {
15
40
final d = StandardUriDesign (Uri .parse ('https://example.com:8080' ));
16
41
expect (d.collection ('books' ).toString (), 'https://example.com:8080/books' );
@@ -110,5 +135,39 @@ void main() {
110
135
expect (d.matchTarget (Uri .parse ('https://example.com:8080/foo/books' )),
111
136
isNull);
112
137
});
138
+
139
+ test ('Authority and path, trailing slash' , () {
140
+ final d = StandardUriDesign (Uri .parse ('https://example.com:8080/api/' ));
141
+ expect (d.matchTarget (Uri .parse ('https://example.com:8080/api/books' )),
142
+ isA <Target >().having ((it) => it.type, 'type' , equals ('books' )));
143
+ expect (
144
+ d.matchTarget (Uri .parse ('https://example.com:8080/api/books/42' )),
145
+ isA <ResourceTarget >()
146
+ .having ((it) => it.type, 'type' , equals ('books' ))
147
+ .having ((it) => it.id, 'id' , equals ('42' )));
148
+ expect (
149
+ d.matchTarget (
150
+ Uri .parse ('https://example.com:8080/api/books/42/authors' )),
151
+ isA <RelatedTarget >()
152
+ .having ((it) => it.type, 'type' , equals ('books' ))
153
+ .having ((it) => it.id, 'id' , equals ('42' ))
154
+ .having (
155
+ (it) => it.relationship, 'relationship' , equals ('authors' )));
156
+ expect (
157
+ d.matchTarget (Uri .parse (
158
+ 'https://example.com:8080/api/books/42/relationships/authors' )),
159
+ isA <RelationshipTarget >()
160
+ .having ((it) => it.type, 'type' , equals ('books' ))
161
+ .having ((it) => it.id, 'id' , equals ('42' ))
162
+ .having (
163
+ (it) => it.relationship, 'relationship' , equals ('authors' )));
164
+
165
+ expect (
166
+ d.matchTarget (Uri .parse ('https://example.com:8080/a/b/c/d' )), isNull);
167
+ expect (d.matchTarget (Uri .parse ('http://example.com:8080/books' )), isNull);
168
+ expect (d.matchTarget (Uri .parse ('https://foo.net:8080/books' )), isNull);
169
+ expect (d.matchTarget (Uri .parse ('https://example.com:8080/foo/books' )),
170
+ isNull);
171
+ });
113
172
});
114
173
}
0 commit comments