-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbook_finder_test.dart
More file actions
172 lines (152 loc) · 5.92 KB
/
Copy pathbook_finder_test.dart
File metadata and controls
172 lines (152 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import 'package:books_finder/src/books_finder_base.dart';
import 'package:test/test.dart';
void main() {
test('Get books', () async {
final List<Book> books = await queryBooks(
'twilight',
maxResults: 3,
printType: PrintType.books,
orderBy: OrderBy.relevance,
);
expect(books.length, 3);
});
test('Get book with special id', () async {
final Book book = await getSpecificBook('eI0TEAAAQBAJ');
expect(book.info.title, 'Twilight, Say Cheese!');
expect(book.info.publisher, 'Simon and Schuster');
expect(book.info.publishedDate, DateTime(2021, 02, 09));
expect(book.info.rawPublishedDate, '2021-02-09');
expect(book.info.authors.length, 1);
expect(book.info.authors.first, 'Daisy Sunshine');
expect(book.info.categories.length, 4);
expect(book.info.categories.first,
'Juvenile Fiction / Animals / Dragons, Unicorns & Mythical');
expect(book.info.pageCount, 112);
expect(book.info.language, 'en');
expect(book.info.description.isNotEmpty, true);
expect(book.info.maturityRating, 'NOT_MATURE');
expect(book.info.contentVersion, '0.0.1.0.preview.0');
expect(book.info.industryIdentifiers.first.type, 'ISBN_10');
expect(book.info.industryIdentifiers.first.identifier, '1534461655');
});
test('Get magazines', () async {
final List<Book> magazines = await queryBooks(
'New York Magazine',
maxResults: 3,
printType: PrintType.magazines,
orderBy: OrderBy.relevance,
);
expect(magazines.length, 3);
expect(magazines.first.info.industryIdentifiers.length, 0);
});
test('Get magazine with special id', () async {
final Book book = await getSpecificBook('OugCAAAAMBAJ');
expect(book.info.title, 'New York Magazine');
expect(book.info.publisher, 'New York Media, LLC');
expect(book.info.publishedDate, DateTime(1997, 06, 02));
expect(book.info.rawPublishedDate, '1997-06-02');
expect(book.info.authors.length, 1);
expect(book.info.authors.first, 'New York Media, LLC');
expect(book.info.categories.length, 0);
expect(book.info.pageCount, 142);
expect(book.info.language, 'en');
expect(book.info.description.isNotEmpty, true);
expect(book.info.maturityRating, 'NOT_MATURE');
expect(book.info.contentVersion, '0.0.2.0.preview.1');
expect(book.info.industryIdentifiers.length, 1);
expect(book.info.industryIdentifiers.first.type, 'ISSN');
expect(book.info.industryIdentifiers.first.identifier, '00287369');
});
test('Get toJson', () async {
final Book book = await getSpecificBook('OugCAAAAMBAJ');
Map<String, dynamic> json = book.info.toJson();
expect(json['title'], 'New York Magazine');
expect(json['publisher'], 'New York Media, LLC');
expect(json['publishedDate'], DateTime(1997, 06, 02));
expect(json['rawPublishedDate'], '1997-06-02');
expect(json['authors'].length, 1);
expect(json['authors'].first, 'New York Media, LLC');
// Cast List<T> to List<String>
List<String> categories = json['categories'];
expect(json['categories'], []);
expect(categories.length, 0);
expect(json['pageCount'], 142);
expect(json['language'], 'en');
expect(json['description'].isNotEmpty, true);
expect(json['maturityRating'], 'NOT_MATURE');
expect(json['contentVersion'], '0.0.2.0.preview.1');
List<Map<String, dynamic>> industryIdentifiers =
json['industryIdentifiers'];
expect(industryIdentifiers.length, 1);
expect(industryIdentifiers.first['type'], 'ISSN');
expect(industryIdentifiers.first['identifier'], '00287369');
});
test('Get book with subtitle', () async {
final Book book = await getSpecificBook('aieWBrFeRtUC');
expect(book.info.title, 'Prototyping');
expect(book.info.subtitle, 'A Practitioner\'s Guide');
expect(book.info.publisher, 'Rosenfeld Media');
expect(book.info.publishedDate, DateTime(2009));
expect(book.info.rawPublishedDate, '2009');
expect(book.info.authors.length, 1);
expect(book.info.authors.first, 'Todd Zaki Warfel');
expect(book.info.categories.length, 3);
expect(book.info.categories.first, 'Computers / User Interfaces');
expect(book.info.pageCount, 197);
expect(book.info.language, 'en');
expect(book.info.description.isNotEmpty, true);
expect(book.info.maturityRating, 'NOT_MATURE');
expect(book.info.contentVersion, '0.1.5.0.preview.3');
expect(book.info.industryIdentifiers.first.type, 'ISBN_10');
expect(book.info.industryIdentifiers.first.identifier, '1933820217');
});
test('Test QueryTypes', () async {
/// .intitle
List<Book> books = await queryBooks(
'harry potter and the philosopher\'s stone',
queryType: QueryType.intitle,
maxResults: 1,
printType: PrintType.books,
orderBy: OrderBy.relevance,
);
expect(books.first.info.title.toLowerCase(),
"harry potter and the sorcerers stone");
/// .inauthor
books = await queryBooks(
'J. K. Rowling',
queryType: QueryType.inauthor,
maxResults: 1,
printType: PrintType.books,
orderBy: OrderBy.relevance,
);
if (books.isNotEmpty && books.first.info.authors.isNotEmpty) {
expect(books.first.info.authors.first.toLowerCase(), "j. k. rowling");
}
/// .inpublisher
books = await queryBooks(
'Scholastic inc',
queryType: QueryType.inauthor,
maxResults: 1,
printType: PrintType.books,
orderBy: OrderBy.relevance,
);
if (books.isNotEmpty) {
expect(books.first.info.publisher.toLowerCase(), "cartwheel books");
}
/// .isbn
books = await queryBooks(
'9781408855959',
queryType: QueryType.isbn,
maxResults: 1,
printType: PrintType.books,
orderBy: OrderBy.relevance,
);
if (books.isNotEmpty) {
for (IndustryIdentifier id in books.first.info.industryIdentifiers) {
if (id.type == 'ISBN_13') {
assert(id.identifier == '9781408855959');
}
}
}
});
}