|
| 1 | +import { fileURLToPath } from 'node:url'; |
| 2 | +import { tolgeeDataToDict } from './utils/data.js'; |
| 3 | +import { run } from './utils/run.js'; |
| 4 | +import { |
| 5 | + createPak, |
| 6 | + createProjectWithClient, |
| 7 | + deleteProject, |
| 8 | +} from './utils/api/common.js'; |
| 9 | +import { TolgeeClient } from '#cli/client/TolgeeClient.js'; |
| 10 | +import { PROJECT_1 } from './utils/api/project1.js'; |
| 11 | +import { createTmpFolderWithConfig, removeTmpFolder } from './utils/tmp.js'; |
| 12 | +import { pushFilesConfig } from './utils/pushFilesConfig.js'; |
| 13 | + |
| 14 | +const FIXTURES_PATH = new URL('../__fixtures__/', import.meta.url); |
| 15 | + |
| 16 | +const PROJECT_1_DIR = new URL('./updatedProject1/', FIXTURES_PATH); |
| 17 | + |
| 18 | +let client: TolgeeClient; |
| 19 | +let pak: string; |
| 20 | + |
| 21 | +describe('project 1', () => { |
| 22 | + beforeEach(async () => { |
| 23 | + client = await createProjectWithClient('Project 1', PROJECT_1); |
| 24 | + pak = await createPak(client); |
| 25 | + }); |
| 26 | + afterEach(async () => { |
| 27 | + await deleteProject(client); |
| 28 | + await removeTmpFolder(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('pushes updated strings to Tolgee', async () => { |
| 32 | + const out = await run([ |
| 33 | + '--api-key', |
| 34 | + pak, |
| 35 | + 'push', |
| 36 | + '--verbose', |
| 37 | + '--files-template', |
| 38 | + fileURLToPath(new URL(`./{languageTag}.json`, PROJECT_1_DIR)), |
| 39 | + ]); |
| 40 | + |
| 41 | + expect(out.code).toBe(0); |
| 42 | + |
| 43 | + const keys = await client.GET('/v2/projects/{projectId}/translations', { |
| 44 | + params: { |
| 45 | + path: { projectId: client.getProjectId() }, |
| 46 | + query: { search: 'wire' }, |
| 47 | + }, |
| 48 | + }); |
| 49 | + |
| 50 | + expect(keys.data?.page?.totalElements).toBe(2); |
| 51 | + |
| 52 | + const stored = tolgeeDataToDict(keys.data); |
| 53 | + expect(stored).toEqual({ |
| 54 | + wired: { |
| 55 | + __ns: null, |
| 56 | + en: 'Wired', |
| 57 | + fr: 'Filaire', |
| 58 | + }, |
| 59 | + wireless: { |
| 60 | + __ns: null, |
| 61 | + en: 'Wireless', |
| 62 | + fr: 'Sans-fil', |
| 63 | + }, |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('pushes only selected languages (args)', async () => { |
| 68 | + const out = await run([ |
| 69 | + '--api-key', |
| 70 | + pak, |
| 71 | + 'push', |
| 72 | + '--files-template', |
| 73 | + fileURLToPath(new URL(`./{languageTag}.json`, PROJECT_1_DIR)), |
| 74 | + '-l', |
| 75 | + 'fr', |
| 76 | + ]); |
| 77 | + |
| 78 | + expect(out.code).toBe(0); |
| 79 | + |
| 80 | + const keys = await client.GET('/v2/projects/{projectId}/translations', { |
| 81 | + params: { |
| 82 | + path: { projectId: client.getProjectId() }, |
| 83 | + query: { search: 'wire' }, |
| 84 | + }, |
| 85 | + }); |
| 86 | + expect(keys.data?.page?.totalElements).toBe(2); |
| 87 | + |
| 88 | + const stored = tolgeeDataToDict(keys.data); |
| 89 | + expect(stored).toEqual({ |
| 90 | + wired: { |
| 91 | + __ns: null, |
| 92 | + fr: 'Filaire', |
| 93 | + }, |
| 94 | + wireless: { |
| 95 | + __ns: null, |
| 96 | + fr: 'Sans-fil', |
| 97 | + }, |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + it('pushes only selected languages (config)', async () => { |
| 102 | + const { configFile } = await createTmpFolderWithConfig({ |
| 103 | + apiKey: pak, |
| 104 | + push: { |
| 105 | + files: pushFilesConfig(PROJECT_1_DIR), |
| 106 | + languages: ['fr'], |
| 107 | + }, |
| 108 | + }); |
| 109 | + const out = await run(['--config', configFile, 'push']); |
| 110 | + |
| 111 | + expect(out.code).toBe(0); |
| 112 | + |
| 113 | + const keys = await client.GET('/v2/projects/{projectId}/translations', { |
| 114 | + params: { |
| 115 | + path: { projectId: client.getProjectId() }, |
| 116 | + query: { search: 'wire' }, |
| 117 | + }, |
| 118 | + }); |
| 119 | + expect(keys.data?.page?.totalElements).toBe(2); |
| 120 | + |
| 121 | + const stored = tolgeeDataToDict(keys.data); |
| 122 | + expect(stored).toEqual({ |
| 123 | + wired: { |
| 124 | + __ns: null, |
| 125 | + fr: 'Filaire', |
| 126 | + }, |
| 127 | + wireless: { |
| 128 | + __ns: null, |
| 129 | + fr: 'Sans-fil', |
| 130 | + }, |
| 131 | + }); |
| 132 | + }); |
| 133 | +}); |
0 commit comments