Skip to content
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
1 change: 1 addition & 0 deletions packages/spacecat-shared-data-access/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export interface DataAccess {
getSitesWithLatestAudit: (
auditType: string,
sortAuditsAscending?: boolean,
deliveryType?: string,
) => Promise<Site[]>;
getSiteByBaseURL: (
baseUrl: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const getSites = async (dynamoClient, config) => {
* specified delivery type.
*/
export const getSitesByDeliveryType = async (dynamoClient, config, deliveryType) => {
if (deliveryType === 'all') {
return getSites(dynamoClient, config);
}

const dynamoItems = await dynamoClient.query({
TableName: config.tableNameSites,
IndexName: config.indexNameAllSitesByDeliveryType,
Expand Down Expand Up @@ -87,6 +91,9 @@ export const getSitesToAudit = async (dynamoClient, config) => {
* @param {Logger} log - The logger.
* @param {string} auditType - The type of audits to retrieve for the sites.
* @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
* ascending order.
* @param {string} [deliveryType=DEFAULT_DELIVERY_TYPE] - The delivery type of the sites
* to retrieve.
* @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of sites with their
* latest audit.
*/
Expand All @@ -96,9 +103,10 @@ export const getSitesWithLatestAudit = async (
log,
auditType,
sortAuditsAscending = true,
deliveryType = 'all',
) => {
const [sites, latestAudits] = await Promise.all([
getSites(dynamoClient, config),
getSitesByDeliveryType(dynamoClient, config, deliveryType),
getLatestAudits(dynamoClient, config, log, auditType, sortAuditsAscending),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ export const siteFunctions = (dynamoClient, config, log) => ({
dynamoClient,
config,
),
getSitesWithLatestAudit: (auditType, sortAuditsAscending) => getSitesWithLatestAudit(
getSitesWithLatestAudit: (
auditType,
sortAuditsAscending,
deliveryType,
) => getSitesWithLatestAudit(
dynamoClient,
config,
log,
auditType,
sortAuditsAscending,
deliveryType,
),
getSiteByBaseURL: (baseUrl) => getSiteByBaseURL(
dynamoClient,
Expand Down
19 changes: 19 additions & 0 deletions packages/spacecat-shared-data-access/test/it/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ describe('DynamoDB Integration Test', async () => {
});
});

it('gets sites with latest audit of delivery type', async () => {
const sites = await dataAccess.getSitesWithLatestAudit(AUDIT_TYPE_LHS_MOBILE, true, 'aem_cs');

expect(sites.length).to.equal(NUMBER_OF_SITES / 2);

sites.forEach((site) => {
checkSite(site);
expect(site.getDeliveryType()).to.equal('aem_cs');
expect(site.getAudits()).to.be.an('array');

site.getAudits().forEach((audit) => {
expect(audit.getAuditType()).to.equal(AUDIT_TYPE_LHS_MOBILE);
expect(Object.keys(audit.getScores())).to.have.members(
['performance', 'seo', 'accessibility', 'best-practices'],
);
});
});
});

it('gets site by baseURL', async () => {
const site = await dataAccess.getSiteByBaseURL('https://example1.com');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ describe('Site Access Pattern Tests', () => {
expect(mockDynamoClient.query.called).to.be.true;
});

it('calls getSitesWithLatestAudit of delivery type and returns an array', async () => {
const result = await exportedFunctions.getSitesWithLatestAudit('lhs-mobile', true, 'aem_edge');
expect(result).to.be.an('array');
expect(mockDynamoClient.query.called).to.be.true;
});

it('calls getSitesWithLatestAudit and handles latestAudits', async () => {
const mockSiteData = [{
id: 'site1',
Expand Down