Skip to content

Commit

Permalink
test: mock openlibrary.org
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Mar 13, 2024
1 parent 602d3cd commit 5cfa585
Show file tree
Hide file tree
Showing 13 changed files with 11,574 additions and 174 deletions.
1 change: 1 addition & 0 deletions api/composer.json
Expand Up @@ -13,6 +13,7 @@
"myclabs/php-enum": "^1.8",
"nelmio/cors-bundle": "^2.4",
"runtime/frankenphp-symfony": "^0.2.0",
"seld/jsonlint": "^1.10",
"symfony/asset": "7.0.*",
"symfony/clock": "7.0.*",
"symfony/console": "7.0.*",
Expand Down
66 changes: 65 additions & 1 deletion api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/src/Command/BooksImportCommand.php
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

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

$io->progressFinish();

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

return Command::SUCCESS;
}
Expand Down
5 changes: 4 additions & 1 deletion pwa/playwright.config.ts
Expand Up @@ -10,7 +10,10 @@ import { defineConfig, devices } from "@playwright/test";
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
timeout: 5 * 60 * 1000,
timeout: 45000,
expect: {
timeout: 10000,
},
testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: true,
Expand Down
21 changes: 21 additions & 0 deletions pwa/tests/admin/pages/AbstractPage.ts
Expand Up @@ -14,4 +14,25 @@ export abstract class AbstractPage {

return this.page;
}

protected async registerMock() {
await this.page.route(/^https:\/\/openlibrary\.org\/books\/(.+)\.json$/, (route) => route.fulfill({
path: "tests/mocks/openlibrary.org/books/OL2055137M.json"
}));
await this.page.route(/^https:\/\/openlibrary\.org\/works\/(.+)\.json$/, (route) => route.fulfill({
path: "tests/mocks/openlibrary.org/works/OL1963268W.json"
}));
await this.page.route("https://openlibrary.org/search.json?q=Foundation%20Isaac%20Asimov&limit=10", (route) => route.fulfill({
path: "tests/mocks/openlibrary.org/search/Foundation-Isaac-Asimov.json"
}));
await this.page.route("https://openlibrary.org/search.json?q=Eon%20Greg%20Bear&limit=10", (route) => route.fulfill({
path: "tests/mocks/openlibrary.org/search/Eon-Greg-Bear.json"
}));
await this.page.route("https://openlibrary.org/search.json?q=Hyperion%20Dan%20Simmons&limit=10", (route) => route.fulfill({
path: "tests/mocks/openlibrary.org/search/Hyperion-Dan-Simmons.json"
}));
await this.page.route(/^https:\/\/covers\.openlibrary.org\/b\/id\/(.+)\.jpg$/, (route) => route.fulfill({
path: "tests/mocks/covers.openlibrary.org/b/id/4066031-M.jpg",
}));
}
}
2 changes: 2 additions & 0 deletions pwa/tests/admin/pages/BookPage.ts
Expand Up @@ -8,6 +8,8 @@ interface FiltersProps {

export class BookPage extends AbstractPage {
public async gotoList() {
await this.registerMock();

await this.page.goto("/admin");
await this.login();
await this.page.waitForURL(/\/admin#\/admin/);
Expand Down
Binary file not shown.
174 changes: 87 additions & 87 deletions pwa/tests/mocks/openlibrary.org/books/OL2055137M.json
@@ -1,91 +1,91 @@
{
"publishers": [
"Doubleday"
],
"number_of_pages": 481,
"covers": [
4066031,
238840
],
"physical_format": "Hardcover",
"lc_classifications": [
"PS3569.I47292 H97 1989",
"PS3569.I47292H97"
],
"url": [
"http://www.loc.gov/catdir/samples/random043/88033407.html",
"http://www.loc.gov/catdir/description/random047/88033407.html"
],
"key": "/books/OL2055137M",
"authors": [
{
"key": "/authors/OL235668A"
}
],
"publish_places": [
"New York"
],
"uri_descriptions": [
"Sample text",
"Publisher description"
],
"edition_name": "1st ed.",
"pagination": "481 p. ;",
"classifications": {},
"source_records": [
"amazon:0385249497",
"marc:marc_loc_2016/BooksAll.2016.part18.utf8:175194414:820",
"bwb:9780385263481"
],
"title": "Hyperion",
"dewey_decimal_class": [
"813/.54"
],
"notes": "\"A Foundation book.\"",
"identifiers": {
"librarything": [
"23078"
],
"goodreads": [
"1718945",
"2093816"
]
},
"languages": [
{
"key": "/languages/eng"
}
],
"lccn": [
"88033407"
],
"isbn_10": [
"0385249497",
"0385263481"
],
"publish_date": "1989",
"publish_country": "nyu",
"by_statement": "Dan Simmons.",
"works": [
{
"key": "/works/OL1963268W"
}
],
"type": {
"key": "/type/edition"
},
"uris": [
"http://www.loc.gov/catdir/samples/random043/88033407.html",
"http://www.loc.gov/catdir/description/random047/88033407.html"
"publishers": [
"Doubleday"
],
"number_of_pages": 481,
"covers": [
4066031,
238840
],
"physical_format": "Hardcover",
"lc_classifications": [
"PS3569.I47292 H97 1989",
"PS3569.I47292H97"
],
"url": [
"http://www.loc.gov/catdir/samples/random043/88033407.html",
"http://www.loc.gov/catdir/description/random047/88033407.html"
],
"key": "/books/OL2055137M",
"authors": [
{
"key": "/authors/OL235668A"
}
],
"publish_places": [
"New York"
],
"uri_descriptions": [
"Sample text",
"Publisher description"
],
"edition_name": "1st ed.",
"pagination": "481 p. ;",
"classifications": {},
"source_records": [
"amazon:0385249497",
"marc:marc_loc_2016/BooksAll.2016.part18.utf8:175194414:820",
"bwb:9780385263481"
],
"title": "Hyperion",
"dewey_decimal_class": [
"813/.54"
],
"notes": "\"A Foundation book.\"",
"identifiers": {
"librarything": [
"23078"
],
"latest_revision": 11,
"revision": 11,
"created": {
"type": "/type/datetime",
"value": "2008-04-01T03:28:50.625462"
},
"last_modified": {
"type": "/type/datetime",
"value": "2021-09-29T01:39:35.554352"
"goodreads": [
"1718945",
"2093816"
]
},
"languages": [
{
"key": "/languages/eng"
}
],
"lccn": [
"88033407"
],
"isbn_10": [
"0385249497",
"0385263481"
],
"publish_date": "1989",
"publish_country": "nyu",
"by_statement": "Dan Simmons.",
"works": [
{
"key": "/works/OL1963268W"
}
],
"type": {
"key": "/type/edition"
},
"uris": [
"http://www.loc.gov/catdir/samples/random043/88033407.html",
"http://www.loc.gov/catdir/description/random047/88033407.html"
],
"latest_revision": 11,
"revision": 11,
"created": {
"type": "/type/datetime",
"value": "2008-04-01T03:28:50.625462"
},
"last_modified": {
"type": "/type/datetime",
"value": "2021-09-29T01:39:35.554352"
}
}

0 comments on commit 5cfa585

Please sign in to comment.