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
4 changes: 4 additions & 0 deletions packages/spacecat-shared-data-access/docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"AttributeName": "isLive",
"AttributeType": "B"
},
{
"AttributeName": "isLiveToggledAt",
"AttributeType": "S"
},
{
"AttributeName": "deliveryType",
"AttributeType": "S"
Expand Down
2 changes: 2 additions & 0 deletions packages/spacecat-shared-data-access/src/dto/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const SiteDto = {
gitHubURL: site.getGitHubURL() || '',
imsOrgId: site.getImsOrgId() || '',
isLive: site.isLive(),
isLiveToggledAt: site.getIsLiveToggledAt(),
createdAt: site.getCreatedAt(),
updatedAt: site.getUpdatedAt(),
GSI1PK: 'ALL_SITES',
Expand All @@ -48,6 +49,7 @@ export const SiteDto = {
gitHubURL: dynamoItem.gitHubURL,
imsOrgId: dynamoItem.imsOrgId,
isLive: dynamoItem.isLive,
isLiveToggledAt: dynamoItem.isLiveToggledAt,
createdAt: dynamoItem.createdAt,
updatedAt: dynamoItem.updatedAt,
auditConfig: dynamoItem.auditConfig,
Expand Down
6 changes: 6 additions & 0 deletions packages/spacecat-shared-data-access/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ export interface Site {
*/
isLive: () => boolean;

/**
* The timestamp when the site was last toggled to live or non-live.
* @returns {string} The timestamp when the site was last toggled to live or non-live.
*/
getIsLiveToggledAt: () => string;

/**
* Updates the list of audits for the site.
* @param {Audit[]} audits The new list of audits.
Expand Down
2 changes: 2 additions & 0 deletions packages/spacecat-shared-data-access/src/models/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Site = (data = {}) => {
self.getGitHubURL = () => self.state.gitHubURL;
self.getImsOrgId = () => self.state.imsOrgId;
self.isLive = () => self.state.isLive;
self.getIsLiveToggledAt = () => self.state.isLiveToggledAt;

// TODO: updating the baseURL is not supported yet, it will require a transact write
// on dynamodb (put then delete) since baseURL is part of the primary key, something like:
Expand Down Expand Up @@ -143,6 +144,7 @@ const Site = (data = {}) => {
*/
self.toggleLive = () => {
self.state.isLive = !self.state.isLive;
self.state.isLiveToggledAt = new Date().toISOString();
return self;
};

Expand Down
3 changes: 3 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 @@ -37,6 +37,7 @@ function checkSite(site) {
expect(isIsoDate(site.getUpdatedAt())).to.be.true;
expect(site.getAudits()).to.be.an('array');
expect(site.isLive()).to.be.a('boolean');
expect(isIsoDate(site.getIsLiveToggledAt())).to.be.true;

const auditConfig = site.getAuditConfig();
expect(auditConfig).to.be.an('object');
Expand Down Expand Up @@ -192,6 +193,8 @@ describe('DynamoDB Integration Test', async () => {
baseURL: 'https://newexample.com',
gitHubURL: 'https://github.com/some-org/test-repo',
imsOrgId: 'newOrg123',
isLive: true,
isLiveToggledAt: new Date().toISOString(),
audits: [],
auditConfig: {
auditsDisabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export default async function generateSampleData(
gitHubURL: `https://github.com/org-${i}/test-repo`,
imsOrgId: `${i}-1234@AdobeOrg`,
isLive: true,
isLiveToggledAt: nowIso,
GSI1PK: config.pkAllSites,
createdAt: nowIso,
updatedAt: nowIso,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/* eslint-env mocha */

import { isIsoDate } from '@adobe/spacecat-shared-utils';
import { expect } from 'chai';
import { createSite } from '../../../src/models/site.js';
import { sleep } from '../util.js';
Expand Down Expand Up @@ -167,6 +168,7 @@ describe('Site Model Tests', () => {
site.toggleLive();

expect(site.isLive()).to.be.true;
expect(isIsoDate(site.getIsLiveToggledAt())).to.be.true;
});
});

Expand Down