Skip to content

Commit

Permalink
Merge pull request #2500 from refugies-info/matthieu/ri-405-les-fiche…
Browse files Browse the repository at this point in the history
…s-traduites-ne-passent-pas-en-publiees

fix(server): 🐛 remove administrationName from added sections if null
  • Loading branch information
kaaloo authored Dec 13, 2024
2 parents 51e5255 + 4e9babe commit 091d9af
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
28 changes: 28 additions & 0 deletions apps/server/src/typegoose/Traductions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ const trad_avancement: RecursivePartial<TranslationContent> = {
validatorId: new ObjectId("656076dbaf8df7a3f7bceeb4"),
};

const trad_added_adminName: TranslationContent = {
//@ts-ignore
content: {
titreInformatif: "abc",
titreMarque: "def",
abstract: "tyui",
what: "WHAT",
how: { "my-uuid-v4-key": { title: "title", text: "text" } },
next: {
"my-uuid-v4-key": { title: "title", text: "text" },
"my-uuid-v4-key-2": { title: "title", text: "text" },
"my-uuid-v4-key-3": { title: "title", text: "text" },
},
},

created_at: new Date(),
validatorId: new ObjectId("656076dbaf8df7a3f7bceeb4"),
};

describe("Traductions", () => {
describe("diff", () => {
it("should return empty array", () => {
Expand Down Expand Up @@ -153,6 +172,15 @@ describe("Traductions", () => {
removed: ["content.next.my-uuid-v4-key.title", "content.next.my-uuid-v4-key.text"],
});
});
it("should not return administrationName ", () => {
const newTradAdded = JSON.parse(JSON.stringify(trad_added_adminName));
newTradAdded.content = { ...newTradAdded.content, administrationName: null };
expect(Traductions.diff(trad_added_adminName, newTradAdded)).toEqual({
modified: [],
added: [],
removed: [],
});
});
});

describe("computeFinished", () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/typegoose/Traductions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export class Traductions extends Base {
const originKeys = keys(origin);
const compareToKeys = keys(compareTo);
// ces champs devront être traduits impérativement => to review
const added = difference(compareToKeys, originKeys);
const added = difference(compareToKeys, originKeys).filter(
(key: keyof TranslationContent) => get(compareTo, key) !== null,
);
// les champs supprimés peuvent être traités automatiquement sans re-traduction
const removed = difference(originKeys, compareToKeys);

Expand Down
22 changes: 22 additions & 0 deletions migrations/1733826190794_RemoveStuckedToReview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MigrationInterface } from "mongo-migrate-ts";
import { Db } from "mongodb";

export class Migration1733826190794 implements MigrationInterface {
public async up(db: Db): Promise<void | never> {
const trads = await db.collection("traductions").find({ toReview: "content.administrationName" }).toArray();
for (const trad of trads) {
const dispositif = await db.collection("dispositifs").findOne({ _id: trad.dispositifId });
if (dispositif && dispositif.translations.fr.content.administrationName === null) {
//@ts-ignore
await db
.collection("traductions")
.updateOne(
{ _id: trad._id },
{ $pull: { toReview: "content.administrationName", toReviewCache: "content.administrationName" } },
);
}
}
}

public async down(db: Db): Promise<void | never> {}
}

0 comments on commit 091d9af

Please sign in to comment.