|
| 1 | +import 'package:json_api/document.dart'; |
| 2 | +import 'package:test/test.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('Meta members', () { |
| 6 | + test('should be parsed correctly', () { |
| 7 | + final meta = { |
| 8 | + "bool": true, |
| 9 | + "array": [1, 2, 3], |
| 10 | + "string": "foo" |
| 11 | + }; |
| 12 | + final json = { |
| 13 | + "links": { |
| 14 | + "self": "http://example.com/articles", |
| 15 | + "next": "http://example.com/articles?page=2", |
| 16 | + "last": "http://example.com/articles?page=10" |
| 17 | + }, |
| 18 | + "meta": meta, |
| 19 | + "data": [ |
| 20 | + { |
| 21 | + "type": "articles", |
| 22 | + "id": "1", |
| 23 | + "attributes": {"title": "JSON:API paints my bikeshed!"}, |
| 24 | + "meta": meta, |
| 25 | + "relationships": { |
| 26 | + "author": { |
| 27 | + "links": { |
| 28 | + "self": "http://example.com/articles/1/relationships/author", |
| 29 | + "related": "http://example.com/articles/1/author" |
| 30 | + }, |
| 31 | + "data": {"type": "people", "id": "9"} |
| 32 | + }, |
| 33 | + "comments": { |
| 34 | + "links": { |
| 35 | + "self": |
| 36 | + "http://example.com/articles/1/relationships/comments", |
| 37 | + "related": "http://example.com/articles/1/comments" |
| 38 | + }, |
| 39 | + "data": [ |
| 40 | + { |
| 41 | + "type": "comments", |
| 42 | + "id": "5", |
| 43 | + "meta": meta, |
| 44 | + }, |
| 45 | + {"type": "comments", "id": "12"} |
| 46 | + ] |
| 47 | + } |
| 48 | + }, |
| 49 | + "links": {"self": "http://example.com/articles/1"} |
| 50 | + } |
| 51 | + ], |
| 52 | + "included": [ |
| 53 | + { |
| 54 | + "type": "people", |
| 55 | + "id": "9", |
| 56 | + "attributes": { |
| 57 | + "firstName": "Dan", |
| 58 | + "lastName": "Gebhardt", |
| 59 | + "twitter": "dgeb" |
| 60 | + }, |
| 61 | + "links": {"self": "http://example.com/people/9"} |
| 62 | + }, |
| 63 | + { |
| 64 | + "type": "comments", |
| 65 | + "id": "5", |
| 66 | + "attributes": {"body": "First!"}, |
| 67 | + "relationships": { |
| 68 | + "author": { |
| 69 | + "data": {"type": "people", "id": "2"} |
| 70 | + } |
| 71 | + }, |
| 72 | + "links": {"self": "http://example.com/comments/5"} |
| 73 | + }, |
| 74 | + { |
| 75 | + "type": "comments", |
| 76 | + "id": "12", |
| 77 | + "attributes": {"body": "I like XML better"}, |
| 78 | + "relationships": { |
| 79 | + "author": { |
| 80 | + "data": {"type": "people", "id": "9"} |
| 81 | + } |
| 82 | + }, |
| 83 | + "links": {"self": "http://example.com/comments/12"} |
| 84 | + } |
| 85 | + ] |
| 86 | + }; |
| 87 | + |
| 88 | + final doc = Document.decodeJson(json, ResourceCollectionData.decodeJson); |
| 89 | + expect(doc.meta["bool"], true); |
| 90 | + expect(doc.data.collection.first.meta, meta); |
| 91 | + expect( |
| 92 | + (doc.data.collection.first.relationships['comments'] as ToMany) |
| 93 | + .linkage |
| 94 | + .first |
| 95 | + .meta, |
| 96 | + meta); |
| 97 | + }); |
| 98 | + }); |
| 99 | +} |
0 commit comments