Skip to content

Commit

Permalink
Add new output property bookProvider (#15)
Browse files Browse the repository at this point in the history
* Pass through book provider property

* Updated documentation

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
katydecorah and actions-user authored May 25, 2024
1 parent 5da2cb9 commit bd3a8dc
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ information.
"publisher": "Macmillan",
"publishedDate": "2014-02-04",
"language": "en",
"isbn": "9780374104092"
"isbn": "9780374104092",
"bookProvider": "Google Books"
}
```

Expand Down Expand Up @@ -146,7 +147,8 @@ information.
"publisher": "Farrar, Straus and Giroux",
"publishedDate": "2014",
"language": "en",
"isbn": "9780374104092"
"isbn": "9780374104092",
"bookProvider": "Open Library"
}
```

Expand Down
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property {string | undefined} [language] - The language of the book.
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
* @property {string} [link] - The link of the book.
* @property {string} bookProvider - The provider of the book information.
*/
/**
* @typedef {import('./provider-resolvers.js').Providers} Providers
Expand Down Expand Up @@ -93,6 +94,10 @@ export type Book = {
* - The link of the book.
*/
link?: string;
/**
* - The provider of the book information.
*/
bookProvider: string;
};
export type Providers = import('./provider-resolvers.js').Providers;
export type AxiosRequestConfig = import('axios').AxiosRequestConfig;
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
* @property {string | undefined} [language] - The language of the book.
* @property {string | undefined} [thumbnail] - The thumbnail image link of the book.
* @property {string} [link] - The link of the book.
* @property {string} bookProvider - The provider of the book information.
*/

/**
Expand Down
1 change: 1 addition & 0 deletions src/providers/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export async function standardize(book, id, isbn) {
publishedDate: book.publishedDate,
language: book.language,
isbn,
bookProvider: "Google Books",
};

return standardBook;
Expand Down
1 change: 1 addition & 0 deletions src/providers/isbndb.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,6 @@ function standardize(book, isbn) {
publishedDate: book.date_published,
language: book.language,
isbn,
bookProvider: "ISBNdb",
};
}
1 change: 1 addition & 0 deletions src/providers/open-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export async function standardize(book, isbn) {
publishedDate: book.publish_date,
language: formatLanguage(book.languages),
isbn,
bookProvider: "Open Library",
};

return standardBook;
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/end-to-end.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`End to end Annihilation { name: 'default', providers: [] } 1`] = `
"authors": [
"Jeff VanderMeer",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
"Fiction / General",
Expand Down Expand Up @@ -34,6 +35,7 @@ exports[`End to end Annihilation { name: 'google', providers: [Array] } 1`] = `
"authors": [
"Jeff VanderMeer",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
"Fiction / General",
Expand Down Expand Up @@ -63,6 +65,7 @@ exports[`End to end Annihilation { name: 'openlibrary', providers: [Array] } 1`]
"authors": [
"Jeff VanderMeer",
],
"bookProvider": "Open Library",
"categories": [
"Nebula Award Winner",
"award:nebula_award=novel",
Expand Down Expand Up @@ -125,6 +128,7 @@ exports[`End to end Fantastic Mr. Fox { name: 'default', providers: [] } 1`] = `
"authors": [
"Roald Dahl",
],
"bookProvider": "Google Books",
"categories": [
"Juvenile Fiction",
"Juvenile Fiction / Animals / Foxes",
Expand All @@ -148,6 +152,7 @@ exports[`End to end Fantastic Mr. Fox { name: 'google', providers: [Array] } 1`]
"authors": [
"Roald Dahl",
],
"bookProvider": "Google Books",
"categories": [
"Juvenile Fiction",
"Juvenile Fiction / Animals / Foxes",
Expand All @@ -171,6 +176,7 @@ exports[`End to end Fantastic Mr. Fox { name: 'openlibrary', providers: [Array]
"authors": [
"Roald Dahl",
],
"bookProvider": "Open Library",
"categories": [
"Animals",
"Hunger",
Expand Down Expand Up @@ -226,6 +232,7 @@ exports[`End to end Transcendent Kingdom { name: 'default', providers: [] } 1`]
"authors": [
"Yaa Gyasi",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
"Fiction / Literary",
Expand All @@ -252,6 +259,7 @@ exports[`End to end Transcendent Kingdom { name: 'google', providers: [Array] }
"authors": [
"Yaa Gyasi",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
"Fiction / Literary",
Expand All @@ -278,6 +286,7 @@ exports[`End to end Transcendent Kingdom { name: 'openlibrary', providers: [Arra
"authors": [
"Yaa Gyasi",
],
"bookProvider": "Open Library",
"categories": [
"American literature",
"nyt:combined-print-and-e-book-fiction=2020-09-20",
Expand Down
4 changes: 4 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe("ISBN Resolver API", () => {
"authors": [
"Jeff VanderMeer",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
],
Expand Down Expand Up @@ -80,6 +81,7 @@ describe("ISBN Resolver API", () => {
expect(book).toMatchInlineSnapshot(`
{
"authors": [],
"bookProvider": "Open Library",
"categories": [],
"description": "",
"isbn": "9780374104092",
Expand Down Expand Up @@ -146,6 +148,7 @@ describe("ISBN Resolver API", () => {
"authors": [
"Aswin Pranam",
],
"bookProvider": "ISBNdb",
"categories": undefined,
"description": undefined,
"isbn": "9780374104092",
Expand Down Expand Up @@ -237,6 +240,7 @@ describe("ISBN Resolver API", () => {
"authors": [
"Jeff VanderMeer",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
],
Expand Down
4 changes: 4 additions & 0 deletions test/providers/google.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe("resolveGoogle", () => {
"authors": [
"Test Author",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
"Fiction / General",
Expand Down Expand Up @@ -150,6 +151,7 @@ describe("resolveGoogle", () => {
"authors": [
"Test Author",
],
"bookProvider": "Google Books",
"categories": [
"Fiction",
"Fiction / General",
Expand Down Expand Up @@ -217,6 +219,7 @@ describe("resolveGoogle", () => {
"authors": [
"Test Author",
],
"bookProvider": "Google Books",
"categories": [],
"description": undefined,
"isbn": "1234567890",
Expand Down Expand Up @@ -258,6 +261,7 @@ describe("resolveGoogle", () => {
"authors": [
"Test Author",
],
"bookProvider": "Google Books",
"categories": [],
"description": undefined,
"isbn": "1234567890",
Expand Down
1 change: 1 addition & 0 deletions test/providers/isbndb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe("resolveIsbnDb", () => {
"authors": [
"Test Author",
],
"bookProvider": "ISBNdb",
"categories": [
"Test subject",
],
Expand Down
10 changes: 6 additions & 4 deletions test/providers/open-library.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe("resolveOpenLibrary", () => {
"authors": [
"Roald Dahl",
],
"bookProvider": "Open Library",
"categories": [
"Animals",
"Hunger",
Expand Down Expand Up @@ -109,6 +110,7 @@ describe("resolveOpenLibrary", () => {
expect(book).toMatchInlineSnapshot(`
{
"authors": [],
"bookProvider": "Open Library",
"categories": [],
"description": "",
"isbn": "9780374104092",
Expand All @@ -133,7 +135,7 @@ describe("resolveOpenLibrary", () => {
});

await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow(
`No books found with ISBN: ${isbn}`,
`No books found with ISBN: ${isbn}`
);
});

Expand All @@ -146,7 +148,7 @@ describe("resolveOpenLibrary", () => {
});

await expect(resolveOpenLibrary(isbn, {})).rejects.toThrow(
"Wrong response code: 404",
"Wrong response code: 404"
);
});
});
Expand Down Expand Up @@ -188,7 +190,7 @@ describe("getAuthors", () => {
axios.get.mockResolvedValueOnce({ status: 404 });

await expect(getAuthors(rawAuthors)).rejects.toThrow(
"Unable to get author /authors/OL1A: 404",
"Unable to get author /authors/OL1A: 404"
);
});
});
Expand Down Expand Up @@ -265,7 +267,7 @@ describe("getWorks", () => {
axios.get.mockResolvedValueOnce({ status: 404 });

await expect(getWorks({ works })).rejects.toThrow(
"Unable to get /works/OL1A: 404",
"Unable to get /works/OL1A: 404"
);
});
});

0 comments on commit bd3a8dc

Please sign in to comment.