From 35ce4c335df900bfe60d3eb3a48f8d2cebee6876 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= <djaeggi@adobe.com>
Date: Tue, 31 Dec 2024 19:07:32 +0100
Subject: [PATCH] fix: calling all wrong args

---
 .../src/v2/models/site/site.collection.js             |  4 ++--
 .../test/it/site/site.test.js                         | 11 +++++++++++
 .../test/unit/v2/models/site/site.collection.test.js  |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/packages/spacecat-shared-data-access/src/v2/models/site/site.collection.js b/packages/spacecat-shared-data-access/src/v2/models/site/site.collection.js
index 274c73ea..44745966 100755
--- a/packages/spacecat-shared-data-access/src/v2/models/site/site.collection.js
+++ b/packages/spacecat-shared-data-access/src/v2/models/site/site.collection.js
@@ -26,7 +26,7 @@ import Site from './site.model.js';
  */
 class SiteCollection extends BaseCollection {
   async allSitesToAudit() {
-    return (await this.all({ attributes: ['siteId'] })).map((site) => site.getId());
+    return (await this.all({}, { attributes: ['siteId'] })).map((site) => site.getId());
   }
 
   async allWithLatestAudit(auditType, order = 'asc', deliveryType = null) {
@@ -43,7 +43,7 @@ class SiteCollection extends BaseCollection {
 
     const [sites, latestAudits] = await Promise.all([
       sitesQuery,
-      latestAuditCollection.all([auditType], { order }),
+      latestAuditCollection.all({ auditType }, { order }),
     ]);
 
     const sitesMap = new Map(sites.map((site) => [site.getId(), site]));
diff --git a/packages/spacecat-shared-data-access/test/it/site/site.test.js b/packages/spacecat-shared-data-access/test/it/site/site.test.js
index 12bbedef..e79c8ed1 100644
--- a/packages/spacecat-shared-data-access/test/it/site/site.test.js
+++ b/packages/spacecat-shared-data-access/test/it/site/site.test.js
@@ -210,6 +210,13 @@ describe('Site IT', async () => {
     expect(audit.getAuditType()).to.equal('cwv');
   });
 
+  it('returns null for latest audit for a site by type if not found', async () => {
+    const site = await Site.findById(sampleData.sites[1].getId());
+    const audit = await site.getLatestAuditByAuditType('does not exist');
+
+    expect(audit).to.be.null;
+  });
+
   it('gets all latest audits for a site', async () => {
     const site = await Site.findById(sampleData.sites[1].getId());
     const audits = await site.getLatestAudits();
@@ -250,6 +257,10 @@ describe('Site IT', async () => {
       expect(audit).to.be.an('object');
       expect(audit.getSiteId()).to.equal(site.getId());
       expect(audit.getAuditType()).to.equal('cwv');
+
+      const nonExistingAudit = await site.getLatestAuditByAuditType('does not exist');
+
+      expect(nonExistingAudit).to.be.null;
     }
   });
 
diff --git a/packages/spacecat-shared-data-access/test/unit/v2/models/site/site.collection.test.js b/packages/spacecat-shared-data-access/test/unit/v2/models/site/site.collection.test.js
index 51fcc2ee..acfeac41 100755
--- a/packages/spacecat-shared-data-access/test/unit/v2/models/site/site.collection.test.js
+++ b/packages/spacecat-shared-data-access/test/unit/v2/models/site/site.collection.test.js
@@ -65,7 +65,7 @@ describe('SiteCollection', () => {
       const result = await instance.allSitesToAudit();
 
       expect(result).to.deep.equal(['s12345']);
-      expect(instance.all).to.have.been.calledOnceWithExactly({ attributes: ['siteId'] });
+      expect(instance.all).to.have.been.calledOnceWithExactly({}, { attributes: ['siteId'] });
     });
   });