Skip to content

Commit 11d780a

Browse files
test: mock openlibrary.org
1 parent f760b29 commit 11d780a

File tree

13 files changed

+11574
-174
lines changed

13 files changed

+11574
-174
lines changed

api/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"myclabs/php-enum": "^1.8",
1414
"nelmio/cors-bundle": "^2.4",
1515
"runtime/frankenphp-symfony": "^0.2.0",
16+
"seld/jsonlint": "^1.10",
1617
"symfony/asset": "7.0.*",
1718
"symfony/clock": "7.0.*",
1819
"symfony/console": "7.0.*",

api/composer.lock

Lines changed: 65 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/Command/BooksImportCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Symfony\Component\Console\Style\SymfonyStyle;
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\Serializer\Encoder\DecoderInterface;
16+
use Symfony\Component\Serializer\Encoder\JsonEncode;
1617
use Symfony\Component\Serializer\SerializerInterface;
1718
use Symfony\Contracts\HttpClient\HttpClientInterface;
1819

@@ -83,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8384

8485
$io->progressFinish();
8586

86-
$output->write($this->serializer->serialize($data, 'json'));
87+
$output->write($this->serializer->serialize($data, 'json', [JsonEncode::OPTIONS => JSON_PRETTY_PRINT]));
8788

8889
return Command::SUCCESS;
8990
}

pwa/playwright.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { defineConfig, devices } from "@playwright/test";
1010
* See https://playwright.dev/docs/test-configuration.
1111
*/
1212
export default defineConfig({
13-
timeout: 5 * 60 * 1000,
13+
timeout: 45000,
14+
expect: {
15+
timeout: 10000,
16+
},
1417
testDir: "./tests",
1518
/* Run tests in files in parallel */
1619
fullyParallel: true,

pwa/tests/admin/pages/AbstractPage.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,25 @@ export abstract class AbstractPage {
1414

1515
return this.page;
1616
}
17+
18+
protected async registerMock() {
19+
await this.page.route(/^https:\/\/openlibrary\.org\/books\/(.+)\.json$/, (route) => route.fulfill({
20+
path: "tests/mocks/openlibrary.org/books/OL2055137M.json"
21+
}));
22+
await this.page.route(/^https:\/\/openlibrary\.org\/works\/(.+)\.json$/, (route) => route.fulfill({
23+
path: "tests/mocks/openlibrary.org/works/OL1963268W.json"
24+
}));
25+
await this.page.route("https://openlibrary.org/search.json?q=Foundation%20Isaac%20Asimov&limit=10", (route) => route.fulfill({
26+
path: "tests/mocks/openlibrary.org/search/Foundation-Isaac-Asimov.json"
27+
}));
28+
await this.page.route("https://openlibrary.org/search.json?q=Eon%20Greg%20Bear&limit=10", (route) => route.fulfill({
29+
path: "tests/mocks/openlibrary.org/search/Eon-Greg-Bear.json"
30+
}));
31+
await this.page.route("https://openlibrary.org/search.json?q=Hyperion%20Dan%20Simmons&limit=10", (route) => route.fulfill({
32+
path: "tests/mocks/openlibrary.org/search/Hyperion-Dan-Simmons.json"
33+
}));
34+
await this.page.route(/^https:\/\/covers\.openlibrary.org\/b\/id\/(.+)\.jpg$/, (route) => route.fulfill({
35+
path: "tests/mocks/covers.openlibrary.org/b/id/4066031-M.jpg",
36+
}));
37+
}
1738
}

pwa/tests/admin/pages/BookPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface FiltersProps {
88

99
export class BookPage extends AbstractPage {
1010
public async gotoList() {
11+
await this.registerMock();
12+
1113
await this.page.goto("/admin");
1214
await this.login();
1315
await this.page.waitForURL(/\/admin#\/admin/);
-6.96 KB
Binary file not shown.
Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
{
2-
"publishers": [
3-
"Doubleday"
4-
],
5-
"number_of_pages": 481,
6-
"covers": [
7-
4066031,
8-
238840
9-
],
10-
"physical_format": "Hardcover",
11-
"lc_classifications": [
12-
"PS3569.I47292 H97 1989",
13-
"PS3569.I47292H97"
14-
],
15-
"url": [
16-
"http://www.loc.gov/catdir/samples/random043/88033407.html",
17-
"http://www.loc.gov/catdir/description/random047/88033407.html"
18-
],
19-
"key": "/books/OL2055137M",
20-
"authors": [
21-
{
22-
"key": "/authors/OL235668A"
23-
}
24-
],
25-
"publish_places": [
26-
"New York"
27-
],
28-
"uri_descriptions": [
29-
"Sample text",
30-
"Publisher description"
31-
],
32-
"edition_name": "1st ed.",
33-
"pagination": "481 p. ;",
34-
"classifications": {},
35-
"source_records": [
36-
"amazon:0385249497",
37-
"marc:marc_loc_2016/BooksAll.2016.part18.utf8:175194414:820",
38-
"bwb:9780385263481"
39-
],
40-
"title": "Hyperion",
41-
"dewey_decimal_class": [
42-
"813/.54"
43-
],
44-
"notes": "\"A Foundation book.\"",
45-
"identifiers": {
46-
"librarything": [
47-
"23078"
48-
],
49-
"goodreads": [
50-
"1718945",
51-
"2093816"
52-
]
53-
},
54-
"languages": [
55-
{
56-
"key": "/languages/eng"
57-
}
58-
],
59-
"lccn": [
60-
"88033407"
61-
],
62-
"isbn_10": [
63-
"0385249497",
64-
"0385263481"
65-
],
66-
"publish_date": "1989",
67-
"publish_country": "nyu",
68-
"by_statement": "Dan Simmons.",
69-
"works": [
70-
{
71-
"key": "/works/OL1963268W"
72-
}
73-
],
74-
"type": {
75-
"key": "/type/edition"
76-
},
77-
"uris": [
78-
"http://www.loc.gov/catdir/samples/random043/88033407.html",
79-
"http://www.loc.gov/catdir/description/random047/88033407.html"
2+
"publishers": [
3+
"Doubleday"
4+
],
5+
"number_of_pages": 481,
6+
"covers": [
7+
4066031,
8+
238840
9+
],
10+
"physical_format": "Hardcover",
11+
"lc_classifications": [
12+
"PS3569.I47292 H97 1989",
13+
"PS3569.I47292H97"
14+
],
15+
"url": [
16+
"http://www.loc.gov/catdir/samples/random043/88033407.html",
17+
"http://www.loc.gov/catdir/description/random047/88033407.html"
18+
],
19+
"key": "/books/OL2055137M",
20+
"authors": [
21+
{
22+
"key": "/authors/OL235668A"
23+
}
24+
],
25+
"publish_places": [
26+
"New York"
27+
],
28+
"uri_descriptions": [
29+
"Sample text",
30+
"Publisher description"
31+
],
32+
"edition_name": "1st ed.",
33+
"pagination": "481 p. ;",
34+
"classifications": {},
35+
"source_records": [
36+
"amazon:0385249497",
37+
"marc:marc_loc_2016/BooksAll.2016.part18.utf8:175194414:820",
38+
"bwb:9780385263481"
39+
],
40+
"title": "Hyperion",
41+
"dewey_decimal_class": [
42+
"813/.54"
43+
],
44+
"notes": "\"A Foundation book.\"",
45+
"identifiers": {
46+
"librarything": [
47+
"23078"
8048
],
81-
"latest_revision": 11,
82-
"revision": 11,
83-
"created": {
84-
"type": "/type/datetime",
85-
"value": "2008-04-01T03:28:50.625462"
86-
},
87-
"last_modified": {
88-
"type": "/type/datetime",
89-
"value": "2021-09-29T01:39:35.554352"
49+
"goodreads": [
50+
"1718945",
51+
"2093816"
52+
]
53+
},
54+
"languages": [
55+
{
56+
"key": "/languages/eng"
57+
}
58+
],
59+
"lccn": [
60+
"88033407"
61+
],
62+
"isbn_10": [
63+
"0385249497",
64+
"0385263481"
65+
],
66+
"publish_date": "1989",
67+
"publish_country": "nyu",
68+
"by_statement": "Dan Simmons.",
69+
"works": [
70+
{
71+
"key": "/works/OL1963268W"
9072
}
73+
],
74+
"type": {
75+
"key": "/type/edition"
76+
},
77+
"uris": [
78+
"http://www.loc.gov/catdir/samples/random043/88033407.html",
79+
"http://www.loc.gov/catdir/description/random047/88033407.html"
80+
],
81+
"latest_revision": 11,
82+
"revision": 11,
83+
"created": {
84+
"type": "/type/datetime",
85+
"value": "2008-04-01T03:28:50.625462"
86+
},
87+
"last_modified": {
88+
"type": "/type/datetime",
89+
"value": "2021-09-29T01:39:35.554352"
90+
}
9191
}

0 commit comments

Comments
 (0)