Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calling all wrong args #520

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading