Skip to content

Commit

Permalink
fix(types): 🐛 product_images can be missing/undefined from Audible …
Browse files Browse the repository at this point in the history
…responses, so update the type
  • Loading branch information
djdembeck committed Sep 2, 2022
1 parent dd68538 commit 078cbd3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config/typing/audible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface AudibleProduct {
language: string
merchandising_summary: string
narrators?: NarratorOnBook[]
product_images: { [key: string]: string }
product_images?: { [key: string]: string }
program_participation?: string
publication_name?: string
publisher_name: string
Expand Down
1 change: 1 addition & 0 deletions src/helpers/books/audible/ApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class ApiHelper {

getHighResImage() {
if (!this.inputJson) throw new Error(`No input data`)
if (!this.inputJson.product_images) return ''
return this.inputJson.product_images[1024]
? this.inputJson.product_images[1024].replace('_SL1024_.', '')
: this.inputJson.product_images[500]?.replace('_SL500_.', '') || ''
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/books/audible/ApiHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('ApiHelper edge cases should', () => {
})

test('get backup lower res image', () => {
helper.inputJson!.product_images[1024] = ''
helper.inputJson!.product_images![1024] = ''
expect(helper.getHighResImage()).toBe('https://m.media-amazon.com/images/I/51OIn2FgdtL.jpg')
})

Expand Down

0 comments on commit 078cbd3

Please sign in to comment.