Skip to content

Commit

Permalink
fix: calling all wrong args (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
solaris007 authored Dec 31, 2024
1 parent 7413416 commit b727e50
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]));
Expand Down
11 changes: 11 additions & 0 deletions packages/spacecat-shared-data-access/test/it/site/site.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] });
});
});

Expand Down

0 comments on commit b727e50

Please sign in to comment.