Skip to content

Commit

Permalink
test(caa upload): add tests for Amazon audiobooks
Browse files Browse the repository at this point in the history
  • Loading branch information
kellnerd authored and ROpdebee committed Oct 19, 2021
1 parent af5a998 commit 8e3f91d
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mb_enhanced_cover_art_uploads/providers/amazon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class AmazonProvider extends CoverArtProvider {
if (!covers.length) {
// Handle physical audiobooks, the above extractors fail for those.
LOGGER.warn('Found no release images, trying to find an Amazon (audio)book gallery…');
covers = this.extractFromEmbeddedJSGallery(pageContent) ?? [];
covers = this.extractFromEmbeddedJSGallery(pageContent) ?? /* istanbul ignore next: Should never happen */[];
}

// Filter out placeholder images.
Expand Down
37 changes: 37 additions & 0 deletions tests/mb_enhanced_cover_art_uploads/providers/amazon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,34 @@ describe('amazon provider', () => {
expect(covers).toBeEmpty();
});

it('grabs all images for physical audiobooks from the embedded JS', async () => {
const covers = await provider.findImages(new URL('https://www.amazon.com/dp/0563504196'));

expect(covers).toBeArrayOfSize(2);
expect(covers[0].url.pathname).toContain('91OEsuYoClL');
expect(covers[0].types).toBeUndefined();
expect(covers[1].url.pathname).toContain('91NVbKDHCWL');
expect(covers[1].types).toBeUndefined();
});

it('fails to grab audiobook images if JSON cannot be extracted', () => {
const covers = provider.extractFromEmbeddedJSGallery('');

expect(covers).toBeUndefined();
});

it('fails to grab audiobook images if JSON cannot be parsed', () => {
const covers = provider.extractFromEmbeddedJSGallery("'imageGalleryData' : invalid,");

expect(covers).toBeUndefined();
});

it('fails to grab audiobook images if JSON is invalid type', () => {
const covers = provider.extractFromEmbeddedJSGallery("'imageGalleryData' : 123,");

expect(covers).toBeUndefined();
});

it.each`
url | desc
${'https://www.amazon.com/dp/B07R92TVWN'} | ${'dp URLs'}
Expand All @@ -99,6 +127,15 @@ describe('amazon provider', () => {
expect(covers[0].comment).toBeUndefined();
});

it('grabs the only image for Audible audiobooks', async () => {
const covers = await provider.findImages(new URL('https://www.amazon.com/dp/B017WJ5PR4'));

expect(covers).toBeArrayOfSize(1);
expect(covers[0].url.pathname).toContain('51g7fkELjaL');
expect(covers[0].types).toStrictEqual([ArtworkTypeIDs.Front]);
expect(covers[0].comment).toBeUndefined();
});

it('throws on non-existent product', async () => {
pollyContext.polly.configure({
recordFailedRequests: true,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 8e3f91d

Please sign in to comment.