Repository: ROpdebee/mb-userscripts
Pull request #385 (2022-01-24 12:32:25)

fix(ecau): ignore Qobuz goodies without URL
Cf. #335 

codecov[bot]: # [Codecov](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck) Report
> Merging [#385](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck) (44340d4) into [main](https://codecov.io/gh/ROpdebee/mb-userscripts/commit/0caf10c93680bf0ca08b547e6234b8a0f8547a66?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck) (0caf10c) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385/graphs/tree.svg?width=650&height=150&src=pr&token=CjulzlICM8&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck)](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck)

```diff
@@            Coverage Diff            @@
##              main      #385   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           41        41           
  Lines          906       908    +2     
  Branches       158       158           
=========================================
+ Hits           906       908    +2     
```


| [Impacted Files](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck) | Coverage Δ | |
|---|---|---|
| [...c/mb\_enhanced\_cover\_art\_uploads/providers/qobuz.ts](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck#diff-c3JjL21iX2VuaGFuY2VkX2NvdmVyX2FydF91cGxvYWRzL3Byb3ZpZGVycy9xb2J1ei50cw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck). Last update [0caf10c...44340d4](https://codecov.io/gh/ROpdebee/mb-userscripts/pull/385?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Ruben+Opdebeeck).


Patch:
diff --git a/src/mb_enhanced_cover_art_uploads/providers/qobuz.ts b/src/mb_enhanced_cover_art_uploads/providers/qobuz.ts
index f2d747ca..5ae7fbf2 100644
--- a/src/mb_enhanced_cover_art_uploads/providers/qobuz.ts
+++ b/src/mb_enhanced_cover_art_uploads/providers/qobuz.ts
@@ -12,8 +12,8 @@ interface Goodie {
     file_format_id: number;
     name: string;
     description: string;
-    url: string;
-    original_url: string;
+    url: string | null;
+    original_url: string | null;
 }
 
 // Incomplete, only what we need
@@ -77,14 +77,18 @@ export class QobuzProvider extends CoverArtProvider {
         return metadata;
     }
 
-    static extractGoodies(goodie: Goodie): CoverArt {
-        // Livret Numérique = Digital Booklet
-        const isBooklet = goodie.name.toLowerCase() === 'livret numérique';
-        return {
-            url: new URL(goodie.original_url),
-            types: isBooklet ? [ArtworkTypeIDs.Booklet] : [],
-            comment: isBooklet ? 'Qobuz booklet' : goodie.name,
-        };
+    static extractGoodies(goodies: Goodie[]): CoverArt[] {
+        return goodies
+            .filter((goodie) => !!goodie.original_url)
+            .map((goodie) => {
+                // Livret Numérique = Digital Booklet
+                const isBooklet = goodie.name.toLowerCase() === 'livret numérique';
+                return {
+                    url: new URL(goodie.original_url!),
+                    types: isBooklet ? [ArtworkTypeIDs.Booklet] : [],
+                    comment: isBooklet ? 'Qobuz booklet' : goodie.name,
+                };
+            });
     }
 
     async findImages(url: URL): Promise<CoverArt[]> {
@@ -121,7 +125,7 @@ export class QobuzProvider extends CoverArtProvider {
             throw err;
         }
 
-        const goodies = (metadata.goodies ?? []).map(QobuzProvider.extractGoodies);
+        const goodies = QobuzProvider.extractGoodies(metadata.goodies ?? []);
         const coverUrl = metadata.image.large.replace(/_\d+\.([a-zA-Z0-9]+)$/, '_org.$1');
         return [
             {


Test patch:
diff --git a/tests/unit/mb_enhanced_cover_art_uploads/providers/qobuz.test.ts b/tests/unit/mb_enhanced_cover_art_uploads/providers/qobuz.test.ts
index 89e4c1e5..cf772529 100644
--- a/tests/unit/mb_enhanced_cover_art_uploads/providers/qobuz.test.ts
+++ b/tests/unit/mb_enhanced_cover_art_uploads/providers/qobuz.test.ts
@@ -121,16 +121,16 @@ describe('qobuz provider', () => {
 
     describe('extracting goodies', () => {
         it('sets booklet type if goodie is a booklet', () => {
-            const cover = QobuzProvider.extractGoodies({
+            const covers = QobuzProvider.extractGoodies([{
                 original_url: 'https://example.com/original_url',
                 url: 'https://example.com/url',
                 name: 'Livret Numérique',
                 id: 123,
                 file_format_id: 456,
                 description: 'test',
-            });
+            }]);
 
-            expect(cover).toMatchCoverArt({
+            expect(covers[0]).toMatchCoverArt({
                 urlPart: /^https:\/\/example\.com\/original_url$/,
                 types: [ArtworkTypeIDs.Booklet],
                 comment: 'Qobuz booklet',
@@ -138,21 +138,41 @@ describe('qobuz provider', () => {
         });
 
         it('sets no type if goodie is not a booklet', () => {
-            const cover = QobuzProvider.extractGoodies({
+            const covers = QobuzProvider.extractGoodies([{
                 original_url: 'https://example.com/original_url',
                 url: 'https://example.com/url',
                 name: 'not a booklet',
                 id: 123,
                 file_format_id: 456,
                 description: 'test',
-            });
+            }]);
 
-            expect(cover).toMatchCoverArt({
+            expect(covers[0]).toMatchCoverArt({
                 urlPart: /^https:\/\/example\.com\/original_url$/,
                 types: [],
                 comment: 'not a booklet',
             });
         });
+
+        it('ignores goodie if URL is not set', () => {
+            const covers = QobuzProvider.extractGoodies([{
+                id: 111512,
+                file_format_id: 52,
+                name: 'Clip vidéo',
+                description: 'Evrika (B)',
+                url: null,
+                original_url: null,
+            }, {
+                id: 111513,
+                file_format_id: 21,
+                name: 'Livret Numérique',
+                description: 'Pink Floyd - The Endless River',
+                url: 'https://example.com/url',
+                original_url: 'https://example.com/original_url',
+            }]);
+
+            expect(covers).toBeArrayOfSize(1);
+        });
     });
 
     describe('constructing cover URL from ID', () => {