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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class GeoExperiment extends BaseModel {
DEPLOYMENT_DONE: 'deployment_done',
POST_ANALYSIS_STARTED: 'post_analysis_started',
POST_ANALYSIS_DONE: 'post_analysis_done',
IMPACT_MEASUREMENT_STARTED: 'impact_measurement_started',
IMPACT_MEASUREMENT_DONE: 'impact_measurement_done',
};

/**
Expand All @@ -54,10 +56,11 @@ class GeoExperiment extends BaseModel {
* Well-known keys used within a GeoExperiment's metadata object.
* Centralised here so all consumers reference the same key names.
*
* @type {{ SCHEDULE_CONFIG: string }}
* @type {{ SCHEDULE_CONFIG: string, IMPACT_MEASUREMENT_TASK_ID: string }}
*/
static METADATA_KEYS = {
SCHEDULE_CONFIG: 'scheduleConfig',
IMPACT_MEASUREMENT_TASK_ID: 'impactMeasurementTaskId',
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const schema = new SchemaBuilder(GeoExperiment, GeoExperimentCollection)
type: 'any',
validate: (value) => !value || isObject(value),
})
.addAttribute('insightsLocation', {
type: 'string',
validate: (value) => !value || hasText(value),
})
.addAttribute('error', {
type: 'any',
validate: (value) => !value || isObject(value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface GeoExperiment extends BaseModel {
getStartTime(): string | undefined;
getEndTime(): string | undefined;
getMetadata(): object | undefined;
getInsightsLocation(): string | undefined;
getError(): object | undefined;
getUpdatedBy(): string;

Expand All @@ -53,6 +54,7 @@ export interface GeoExperiment extends BaseModel {
setStartTime(startTime?: string): GeoExperiment;
setEndTime(endTime?: string): GeoExperiment;
setMetadata(metadata?: object): GeoExperiment;
setInsightsLocation(insightsLocation?: string): GeoExperiment;
setError(error?: object): GeoExperiment;
setUpdatedBy(updatedBy: string): GeoExperiment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('GeoExperimentModel', () => {
promptsCount: 5,
promptsLocation: 'geo-experiments/site-123/exp-456-prompts.json',
metadata: { deployType: 'edge' },
insightsLocation: 'geo-experiments/site-123/exp-456-insights.json',
error: { message: 'none' },
updatedBy: 'spacecat-api-service',
};
Expand Down Expand Up @@ -74,7 +75,10 @@ describe('GeoExperimentModel', () => {
});

it('exposes METADATA_KEYS constant', () => {
expect(GeoExperiment.METADATA_KEYS).to.deep.equal({ SCHEDULE_CONFIG: 'scheduleConfig' });
expect(GeoExperiment.METADATA_KEYS).to.deep.equal({
SCHEDULE_CONFIG: 'scheduleConfig',
IMPACT_MEASUREMENT_TASK_ID: 'impactMeasurementTaskId',
});
});

it('exposes SCHEDULE_CONFIG_KEYS constant', () => {
Expand Down Expand Up @@ -120,6 +124,15 @@ describe('GeoExperimentModel', () => {
expect(instance.getPhase()).to.equal(GeoExperiment.PHASES.DEPLOYMENT_DONE);
instance.setPhase(GeoExperiment.PHASES.POST_ANALYSIS_STARTED);
expect(instance.getPhase()).to.equal(GeoExperiment.PHASES.POST_ANALYSIS_STARTED);
instance.setPhase(GeoExperiment.PHASES.IMPACT_MEASUREMENT_STARTED);
expect(instance.getPhase()).to.equal(GeoExperiment.PHASES.IMPACT_MEASUREMENT_STARTED);
instance.setPhase(GeoExperiment.PHASES.IMPACT_MEASUREMENT_DONE);
expect(instance.getPhase()).to.equal(GeoExperiment.PHASES.IMPACT_MEASUREMENT_DONE);
});

it('exposes the impact-measurement phases', () => {
expect(GeoExperiment.PHASES.IMPACT_MEASUREMENT_STARTED).to.equal('impact_measurement_started');
expect(GeoExperiment.PHASES.IMPACT_MEASUREMENT_DONE).to.equal('impact_measurement_done');
});

it('gets and sets promptsLocation', () => {
Expand Down Expand Up @@ -167,6 +180,12 @@ describe('GeoExperimentModel', () => {
expect(instance.getError()).to.deep.equal({ message: 'failed' });
});

it('gets and sets insightsLocation', () => {
expect(instance.getInsightsLocation()).to.equal('geo-experiments/site-123/exp-456-insights.json');
instance.setInsightsLocation('geo-experiments/site-123/exp-789-insights.json');
expect(instance.getInsightsLocation()).to.equal('geo-experiments/site-123/exp-789-insights.json');
});

it('gets and sets updatedBy', () => {
expect(instance.getUpdatedBy()).to.equal('spacecat-api-service');
instance.setUpdatedBy('spacecat-audit-worker');
Expand Down
Loading