@@ -65,6 +65,8 @@ void main() {
6565 });
6666 }, tags: ['vm-only' ]);
6767
68+ ///
69+
6870 group ('deleteResource()' , () {
6971 test ('200 with a meta document' , () async {
7072 final doc = MetaDocument ({"test" : "test" });
@@ -106,49 +108,7 @@ void main() {
106108 });
107109 }, tags: ['vm-only' ]);
108110
109- group ('fetchRelationship()' , () {
110- test ('200 with a document' , () async {
111- final doc = DataDocument .fromResource (appleResource);
112-
113- server.listen ((rq) {
114- expect (rq.method, 'GET' );
115- expect (rq.headers['foo' ], ['bar' ]);
116- expect (rq.uri.path, '/fetch' );
117- expect (rq.headers.host, 'localhost' );
118- expect (rq.headers.port, 4041 );
119- rq.response.headers.contentType = ContentType .parse (Document .mediaType);
120- rq.response.write (json.encode (doc));
121- rq.response.close ();
122- });
123-
124- final result =
125- await client.fetchRelationship ('/fetch' , headers: {'foo' : 'bar' });
126- expectSame (doc, result.document);
127- expect ((result.document as DataDocument ).data,
128- TypeMatcher <IdentifierData >());
129-
130- expect (result.status, HttpStatus .ok);
131- }, tags: ['vm-only' ]);
132-
133- test ('404 without a document' , () async {
134- server.listen ((rq) {
135- rq.response.statusCode = HttpStatus .notFound;
136- rq.response.headers.contentType = ContentType .parse (Document .mediaType);
137- rq.response.close ();
138- });
139- final result = await client.fetchRelationship ('/fetch' );
140- expect (result.document, isNull);
141- expect (result.status, HttpStatus .notFound);
142- });
143-
144- test ('invalid Content-Type' , () async {
145- server.listen ((rq) {
146- rq.response.close ();
147- });
148- expect (() async => await client.fetchRelationship ('/fetch' ),
149- throwsA (TypeMatcher <InvalidContentTypeException >()));
150- });
151- }, tags: ['vm-only' ]);
111+ ///
152112
153113 group ('createResource()' , () {
154114 test ('201 created' , () async {
@@ -199,7 +159,9 @@ void main() {
199159 });
200160 }, tags: ['vm-only' ]);
201161
202- group ('update resource' , () {
162+ ///
163+
164+ group ('updateResource()' , () {
203165 test ('200 ok' , () async {
204166 server.listen ((rq) async {
205167 expect (rq.method, 'PATCH' );
@@ -247,4 +209,163 @@ void main() {
247209 throwsA (TypeMatcher <InvalidContentTypeException >()));
248210 });
249211 }, tags: ['vm-only' ]);
212+
213+ ///
214+
215+ group ('fetchRelationship()' , () {
216+ test ('200 with a document' , () async {
217+ final doc = DataDocument .fromResource (appleResource);
218+
219+ server.listen ((rq) {
220+ expect (rq.method, 'GET' );
221+ expect (rq.headers['foo' ], ['bar' ]);
222+ expect (rq.uri.path, '/fetch' );
223+ expect (rq.headers.host, 'localhost' );
224+ expect (rq.headers.port, 4041 );
225+ rq.response.headers.contentType = ContentType .parse (Document .mediaType);
226+ rq.response.write (json.encode (doc));
227+ rq.response.close ();
228+ });
229+
230+ final result =
231+ await client.fetchRelationship ('/fetch' , headers: {'foo' : 'bar' });
232+ expectSame (doc, result.document);
233+ expect ((result.document as DataDocument ).data,
234+ TypeMatcher <IdentifierData >());
235+
236+ expect (result.status, HttpStatus .ok);
237+ }, tags: ['vm-only' ]);
238+
239+ test ('404 without a document' , () async {
240+ server.listen ((rq) {
241+ rq.response.statusCode = HttpStatus .notFound;
242+ rq.response.headers.contentType = ContentType .parse (Document .mediaType);
243+ rq.response.close ();
244+ });
245+ final result = await client.fetchRelationship ('/fetch' );
246+ expect (result.document, isNull);
247+ expect (result.status, HttpStatus .notFound);
248+ });
249+
250+ test ('invalid Content-Type' , () async {
251+ server.listen ((rq) {
252+ rq.response.close ();
253+ });
254+ expect (() async => await client.fetchRelationship ('/fetch' ),
255+ throwsA (TypeMatcher <InvalidContentTypeException >()));
256+ });
257+ }, tags: ['vm-only' ]);
258+
259+ ///
260+
261+ group ('setToOne()' , () {
262+ final identifier = Identifier ('apples' , '42' );
263+
264+ test ('200' , () async {
265+ server.listen ((rq) async {
266+ expect (rq.method, 'PATCH' );
267+ expect (rq.headers['foo' ], ['bar' ]);
268+ expect (rq.uri.path, '/update' );
269+ expect (rq.headers.host, 'localhost' );
270+ expect (rq.headers.port, 4041 );
271+ final doc = Document .fromJson (json.decode (await utf8.decodeStream (rq)));
272+ expect (doc, TypeMatcher <DataDocument >());
273+ expect ((doc as DataDocument ).data, TypeMatcher <IdentifierData >());
274+ expect ((doc as DataDocument ).data.identifies (Resource ('apples' , '42' )),
275+ true );
276+
277+ rq.response.headers.contentType = ContentType .parse (Document .mediaType);
278+ rq.response.close ();
279+ });
280+
281+ final result = await client
282+ .setToOne ('/update' , identifier, headers: {'foo' : 'bar' });
283+
284+ expect (result.status, HttpStatus .ok);
285+ }, tags: ['vm-only' ]);
286+
287+ test ('invalid Content-Type' , () async {
288+ server.listen ((rq) {
289+ rq.response.close ();
290+ });
291+ expect (() async => await client.setToOne ('/update' , identifier),
292+ throwsA (TypeMatcher <InvalidContentTypeException >()));
293+ });
294+ }, tags: ['vm-only' ]);
295+
296+ ///
297+
298+ group ('deleteToOne()' , () {
299+
300+ test ('200' , () async {
301+ server.listen ((rq) async {
302+ expect (rq.method, 'PATCH' );
303+ expect (rq.headers['foo' ], ['bar' ]);
304+ expect (rq.uri.path, '/update' );
305+ expect (rq.headers.host, 'localhost' );
306+ expect (rq.headers.port, 4041 );
307+ final doc = Document .fromJson (json.decode (await utf8.decodeStream (rq)));
308+ expect (doc, TypeMatcher <DataDocument >());
309+ expect ((doc as DataDocument ).data, TypeMatcher <NullData >());
310+
311+ rq.response.headers.contentType = ContentType .parse (Document .mediaType);
312+ rq.response.close ();
313+ });
314+
315+ final result = await client
316+ .deleteToOne ('/update' , headers: {'foo' : 'bar' });
317+
318+ expect (result.status, HttpStatus .ok);
319+ }, tags: ['vm-only' ]);
320+
321+ test ('invalid Content-Type' , () async {
322+ server.listen ((rq) {
323+ rq.response.close ();
324+ });
325+ expect (() async => await client.deleteToOne ('/update' ),
326+ throwsA (TypeMatcher <InvalidContentTypeException >()));
327+ });
328+ }, tags: ['vm-only' ]);
329+
330+ ///
331+
332+ group ('setToMany()' , () {
333+ final apple1 = Identifier ('apples' , '1' );
334+ final apple2 = Identifier ('apples' , '2' );
335+
336+ test ('200' , () async {
337+ server.listen ((rq) async {
338+ expect (rq.method, 'PATCH' );
339+ expect (rq.headers['foo' ], ['bar' ]);
340+ expect (rq.uri.path, '/update' );
341+ expect (rq.headers.host, 'localhost' );
342+ expect (rq.headers.port, 4041 );
343+ final doc = Document .fromJson (json.decode (await utf8.decodeStream (rq)));
344+ expect (doc, TypeMatcher <DataDocument >());
345+ expect ((doc as DataDocument ).data, TypeMatcher <IdentifierListData >());
346+ expect ((doc as DataDocument ).data.identifies (Resource ('apples' , '1' )),
347+ true );
348+ expect ((doc as DataDocument ).data.identifies (Resource ('apples' , '2' )),
349+ true );
350+
351+ rq.response.headers.contentType = ContentType .parse (Document .mediaType);
352+ rq.response.close ();
353+ });
354+
355+ final result = await client
356+ .setToMany ('/update' , [apple1, apple2], headers: {'foo' : 'bar' });
357+
358+ expect (result.status, HttpStatus .ok);
359+ }, tags: ['vm-only' ]);
360+
361+ test ('invalid Content-Type' , () async {
362+ server.listen ((rq) {
363+ rq.response.close ();
364+ });
365+ expect (() async => await client.setToMany ('/update' , [apple1, apple2]),
366+ throwsA (TypeMatcher <InvalidContentTypeException >()));
367+ });
368+ }, tags: ['vm-only' ]);
369+
370+
250371}
0 commit comments