From bfaca3df319259350198098ba17b3ed312221fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Wed, 3 Jul 2024 10:53:05 +0200 Subject: [PATCH 1/2] fix: properly convert projectId to string in config --- src/config/tolgeerc.ts | 4 ++-- .../nestedKeysProject/tolgee.config.flat.json | 1 + .../validTolgeeRc/withProjectIdString.json | 4 ++++ src/test/unit/config.test.ts | 10 ++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/test/__fixtures__/validTolgeeRc/withProjectIdString.json diff --git a/src/config/tolgeerc.ts b/src/config/tolgeerc.ts index 629f6a3..434cdc4 100644 --- a/src/config/tolgeerc.ts +++ b/src/config/tolgeerc.ts @@ -27,8 +27,8 @@ function parseConfig(input: Schema, configDir: string): Schema { } if (rc.projectId !== undefined) { - const projectId = Number(rc.projectId); // Number("") returns 0 - if (!Number.isInteger(projectId) || projectId <= 0) { + rc.projectId = Number(rc.projectId); // Number("") returns 0 + if (!Number.isInteger(rc.projectId) || rc.projectId <= 0) { throw new Error( 'Invalid config: projectId should be an integer representing your project Id' ); diff --git a/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json b/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json index eb2c9eb..93ac73d 100644 --- a/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json +++ b/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json @@ -3,6 +3,7 @@ "pull": { "delimiter": null }, + "projectId": "376", "push": { "files": [ { diff --git a/src/test/__fixtures__/validTolgeeRc/withProjectIdString.json b/src/test/__fixtures__/validTolgeeRc/withProjectIdString.json new file mode 100644 index 0000000..a9345a5 --- /dev/null +++ b/src/test/__fixtures__/validTolgeeRc/withProjectIdString.json @@ -0,0 +1,4 @@ +{ + "$schema": "../../../../schema.json", + "projectId": "1337" +} diff --git a/src/test/unit/config.test.ts b/src/test/unit/config.test.ts index 0794f36..74cd2e1 100644 --- a/src/test/unit/config.test.ts +++ b/src/test/unit/config.test.ts @@ -81,4 +81,14 @@ describe('.tolgeerc', () => { expect(path).toContain('/validTolgeeRc/'); }); }); + + it('converts projectId to number', async () => { + const path = fileURLToPath( + new URL('./validTolgeeRc/withProjectIdString.json', FIXTURES_PATH) + ); + + const cfg = (await loadTolgeeRc(path))!; + + expect(cfg.projectId).toBe(1337); + }); }); From ad4e6a32c138d06ab5e890c4f87719ce5ef5628f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Wed, 3 Jul 2024 11:05:59 +0200 Subject: [PATCH 2/2] fix: properly convert projectId to string in config --- src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json b/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json index 93ac73d..eb2c9eb 100644 --- a/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json +++ b/src/test/__fixtures__/nestedKeysProject/tolgee.config.flat.json @@ -3,7 +3,6 @@ "pull": { "delimiter": null }, - "projectId": "376", "push": { "files": [ {