Skip to content

Commit

Permalink
feat: data model for organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Jan 16, 2024
1 parent 16beacd commit 94000f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ export const getSiteByBaseURLWithLatestAudit = async (
export const getSitesByOrganizationId = async (
dynamoClient,
config,
log,
organizationId,
) => {
const dynamoItems = await dynamoClient.query({
Expand All @@ -263,7 +262,7 @@ export const getSitesByOrganizationId = async (
Limit: 1,
});

return dynamoItems.length > 0 ? SiteDto.fromDynamoItem(dynamoItems[0]) : null;
return dynamoItems.map((dynamoItem) => SiteDto.fromDynamoItem(dynamoItem));
};

/**
Expand Down
15 changes: 14 additions & 1 deletion packages/spacecat-shared-data-access/test/it/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const TEST_DA_CONFIG = {
tableNameOrganizations: 'spacecat-services-organizations',
tableNameSites: 'spacecat-services-sites',
indexNameAllSites: 'spacecat-services-all-sites',
indexNameAllSitesOrganizations: 'spacecat-all-sites-organizations',
indexNameAllSitesOrganizations: 'spacecat-services-all-sites-organizations',
indexNameAllOrganizations: 'spacecat-services-all-organizations',
indexNameAllSitesByDeliveryType: 'spacecat-services-all-sites-by-delivery-type',
indexNameAllLatestAuditScores: 'spacecat-services-all-latest-audit-scores',
Expand Down Expand Up @@ -163,6 +163,19 @@ describe('DynamoDB Integration Test', async () => {
});
});

it('gets sites by organizationId', async () => {
const organizations = await dataAccess.getOrganizations();
const sites = await dataAccess.getSitesByOrganizationId(organizations[0].getId());

expect(sites.length).to.be.lessThanOrEqual(Math.trunc(NUMBER_OF_SITES / NUMBER_OF_ORGANIZATIONS)
+ (NUMBER_OF_SITES % NUMBER_OF_ORGANIZATIONS));

sites.forEach((site) => {
checkSite(site);
expect(site.getOrganizationId()).to.be.equal(organizations[0].getId());
});
});

it('gets sites to audit', async () => {
const sites = await dataAccess.getSitesToAudit();

Expand Down

0 comments on commit 94000f6

Please sign in to comment.