Skip to content

Commit

Permalink
Merge pull request #3115 from ONSdigital/EAR-2414-created-date-incorr…
Browse files Browse the repository at this point in the history
…ectly-showing-modified-date

EAR-2414 - Created date incorrectly showing modified date
  • Loading branch information
sudeepkunhis authored May 23, 2024
2 parents 774b063 + 098dfde commit d83076a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cloudbuild-author-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ steps:
exit $(( 1 - $result ))
id: unit_tests
entrypoint: /bin/ash
timeout: 1200s
timeout: 1800s
options:
machineType: E2_HIGHCPU_8
13 changes: 13 additions & 0 deletions eq-author-api/db/baseQuestionnaireSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ const baseQuestionnaireFields = {
locked,
};

const saveQuestionnaireFields = {
id,
isPublic,
title,
type,
shortTitle,
publishStatus,
introduction,
editors,
locked,
};

module.exports = {
baseQuestionnaireFields,
...baseQuestionnaireFields,
saveQuestionnaireFields,
};
18 changes: 14 additions & 4 deletions eq-author-api/db/datastore/datastore-firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const { logger } = require("../../utils/logger");
const { pick } = require("lodash/fp");
const { omit } = require("lodash");
const { removeEmpty } = require("../../utils/removeEmpty");
const { baseQuestionnaireFields } = require("../baseQuestionnaireSchema");
const {
baseQuestionnaireFields,
saveQuestionnaireFields,
} = require("../baseQuestionnaireSchema");
const {
questionnaireCreationEvent,
historyCreationForImport,
Expand Down Expand Up @@ -32,6 +35,14 @@ const BASE_FIELDS = [

const justListFields = pick(BASE_FIELDS);

const SAVE_FIELDS = [
...Object.keys(saveQuestionnaireFields),
"updatedAt",
"history",
];

const justListSaveFields = pick(SAVE_FIELDS);

const saveSections = (parentDoc, sections) =>
Promise.all(
sections.map((section, position) =>
Expand Down Expand Up @@ -271,8 +282,7 @@ const saveQuestionnaire = async (changedQuestionnaire) => {
"Unable to save questionnaire; cannot find required field: ID (from saveQuestionnaire)"
);
}
const createdAt = new Date();
const updatedAt = createdAt;
const updatedAt = new Date();

const originalQuestionnaire = await getQuestionnaire(id);

Expand All @@ -297,7 +307,7 @@ const saveQuestionnaire = async (changedQuestionnaire) => {

const baseDoc = db.collection("questionnaires").doc(id);
await baseDoc.update({
...justListFields(updatedQuestionnaire),
...justListSaveFields(updatedQuestionnaire),
updatedAt,
});

Expand Down
10 changes: 10 additions & 0 deletions eq-author-api/db/datastore/datastore-firestore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ describe("Firestore Datastore", () => {
});
expect(updatedAt !== savedQuestionnaire.updatedAt).toBeTruthy();
});

it("Should not update the 'createdAt' property", async () => {
const createdAt = questionnaire.createdAt;
const savedQuestionnaire = await saveQuestionnaire({
id: "123",
title: "Updated questionnaire title",
...questionnaire,
});
expect(createdAt === savedQuestionnaire.createdAt).toBeTruthy();
});
});

describe("Getting a list of questionnaires", () => {
Expand Down

0 comments on commit d83076a

Please sign in to comment.