Skip to content

Commit

Permalink
feat(status): Added status on translation values
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiky committed Dec 22, 2023
1 parent a4beaac commit 83becbd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions postman-collection/Lokapp API.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"first_translation_key\",\n \"group_id\": 1,\n \"is_plural\": false\n}",
"raw": "{\n \"name\": \"first_translation_key\",\n \"groupId\": 1,\n \"isPlural\": false\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -944,7 +944,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"edited_translation_key\",\n \"group_id\": 1,\n \"is_plural\": false\n}",
"raw": "{\n \"name\": \"edited_translation_key\",\n \"groupId\": 1,\n \"isPlural\": false\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -992,7 +992,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Content of the translation value\",\n \"language_id\": 1,\n \"quantity_string\": null\n}",
"raw": "{\n \"name\": \"Content of the translation value\",\n \"languageId\": 1,\n \"quantityString\": null\n}",
"options": {
"raw": {
"language": "json"
Expand Down
7 changes: 7 additions & 0 deletions src/translation/translation_status.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum TranslationStatus {
MODIFIED = "modified",
VALIDATED = "validated",
INVALIDATED = "invalidated"
}

export default TranslationStatus;
7 changes: 6 additions & 1 deletion src/translation/translation_value.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Language from "../languages/language.entity";
import {Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, Unique, UpdateDateColumn} from "typeorm";
import TranslationKey from "./translation_key.entity";
import {PostgresUniqueKeys} from "../data/database/postgres-unique-keys.enum";
import TranslationStatus from "./translation_status.enum";

export const TranslationValuesTableName: string = "translation_values";

Expand Down Expand Up @@ -46,4 +47,8 @@ export default class TranslationValue {
@JoinColumn({name: "languageId"})
@ApiHideProperty()
public language: Language;
}

@Column({default: TranslationStatus.MODIFIED, nullable: false})
@ApiProperty()
public status: TranslationStatus;
}
14 changes: 14 additions & 0 deletions tests/translation-values/translation-values.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TestsHelpers from "../helpers/tests.helpers";
import * as request from "supertest";
import CreateValueDto from "../../src/translation/dto/create-value.dto";
import Role from "../../src/roles/role.enum";
import TranslationStatus from "../../src/translation/translation_status.enum";

describe("Translations values E2E", () => {
let app: INestApplication;
Expand Down Expand Up @@ -230,13 +231,21 @@ describe("Translations values E2E", () => {
.set("mocked_user_id", TestsHelpers.MOCKED_USER_ID_1)
.send({name: "Content of the translation value", languageId: populatedLanguages[0].id, quantityString: null});
expect(createResp.status).toEqual(201);
expect(createResp.body.name).toEqual("Content of the translation value");
expect(createResp.body.keyId).toEqual(populatedTranslationKeys[0].id);
expect(createResp.body.languageId).toEqual(populatedLanguages[0].id);
expect(createResp.body.status).toEqual(TranslationStatus.MODIFIED);

const createWithoutQuantityResp = await request(app.getHttpServer())
.post(`/projects/${populatedProjects[0].id}/translations/${populatedTranslationKeys[0].id}/values`)
.auth("mocked.jwt", {type: "bearer"})
.set("mocked_user_id", TestsHelpers.MOCKED_USER_ID_1)
.send({name: "Content of the translation value", languageId: populatedLanguages[1].id});
expect(createWithoutQuantityResp.status).toEqual(201);
expect(createResp.body.name).toEqual("Content of the translation value");
expect(createResp.body.keyId).toEqual(populatedTranslationKeys[0].id);
expect(createResp.body.languageId).toEqual(populatedLanguages[1].id);
expect(createResp.body.status).toEqual(TranslationStatus.MODIFIED);

const values = await findTranslationValues(populatedTranslationKeys[0].id);
expect(values.length).toEqual(2);
Expand Down Expand Up @@ -269,6 +278,11 @@ describe("Translations values E2E", () => {
.set("mocked_user_id", TestsHelpers.MOCKED_USER_ID_1)
.send({name: "Content of the translation value", languageId: populatedLanguages[0].id, quantityString: QuantityString.OTHER});
expect(createResp.status).toEqual(201);
expect(createResp.body.name).toEqual("Content of the translation value");
expect(createResp.body.keyId).toEqual(populatedTranslationKeys[0].id);
expect(createResp.body.languageId).toEqual(populatedLanguages[0].id);
expect(createResp.body.quantityString).toEqual(QuantityString.OTHER);
expect(createResp.body.status).toEqual(TranslationStatus.MODIFIED);

const values = await findTranslationValues(createdKey.id);
expect(values.length).toEqual(1);
Expand Down

0 comments on commit 83becbd

Please sign in to comment.