Skip to content

Commit

Permalink
chore: improve pull tests (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Jul 30, 2024
1 parent 9216707 commit c128d1d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/test/__fixtures__/fullLanguageNamesProject/.tolgeerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"push": {
"files": [
{
"path": "./en-GB.json",
"language": "en-GB"
},
{
"path": "./fr-FR.json",
"language": "fr-FR"
}
]
}
}
3 changes: 3 additions & 0 deletions src/test/__fixtures__/fullLanguageNamesProject/en-GB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"water": "Water"
}
3 changes: 3 additions & 0 deletions src/test/__fixtures__/fullLanguageNamesProject/fr-FR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"water": "Eau"
}
76 changes: 76 additions & 0 deletions src/test/e2e/pull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PROJECT_1 } from './utils/api/project1.js';
import { PROJECT_3 } from './utils/api/project3.js';
import { NESTED_KEYS_PROJECT } from './utils/api/nestedKeysProject.js';
import { NESTED_ARRAY_KEYS_PROJECT } from './utils/api/nestedArrayKeysProject.js';
import { FULL_LANGUAGE_NAMES_PROJECT } from './utils/api/fullLanguageNamesProject.js';

const FIXTURES_PATH = new URL('../__fixtures__/', import.meta.url);
const PROJECT_1_DATA = fileURLToPath(
Expand Down Expand Up @@ -428,4 +429,79 @@ describe('Nested array keys project', () => {
- keyboard: "Keyboard 1"`
);
});

it('pulls nested structure with arrays', async () => {
const out = await run([
'pull',
'--support-arrays',
'--format',
'YAML_ICU',
'--delimiter',
'.',
'--api-key',
pak,
'--path',
TMP_FOLDER,
]);

expect(out.code).toBe(0);
expect(readFileSync(join(TMP_FOLDER, 'en.yaml')).toString()).toContain(
`nested:
- keyboard: "Keyboard 0"
- keyboard: "Keyboard 1"`
);
});
});

describe('Full language names project', () => {
setupTemporaryFolder();
beforeEach(async () => {
client = await createProjectWithClient(
'Full language names project',
FULL_LANGUAGE_NAMES_PROJECT,
{
languages: [
{
name: 'English',
originalName: 'English',
tag: 'en-GB',
flagEmoji: '🇬🇧',
},
{
name: 'French',
originalName: 'French',
tag: 'fr-FR',
flagEmoji: '🇫🇷',
},
],
}
);
pak = await createPak(client);
});
afterEach(async () => {
deleteProject(client);
});

it('honors files template structure (language tags with regions)', async () => {
const out = await run([
'pull',
'--api-key',
pak,
'--exclude-tags',
'soda_tag',
'--file-structure-template',
'{namespace}/{androidLanguageTag}-{languageTag}-{snakeLanguageTag}.{extension}',
'--path',
TMP_FOLDER,
]);

expect(out.code).toBe(0);
await expect(TMP_FOLDER).toMatchStructure(`
├── en-rGB-en-GB-en_GB.json
└── fr-rFR-fr-FR-fr_FR.json
`);
const content = (await import(join(TMP_FOLDER, 'en-rGB-en-GB-en_GB.json')))
.default;
expect(content).toEqual({ water: 'Water' });
});
});
9 changes: 7 additions & 2 deletions src/test/e2e/utils/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ export async function deleteProject(client: TolgeeClient) {
});
}

type Options = {
languages?: components['schemas']['LanguageRequest'][];
};

export async function createProjectWithClient(
name: string,
data: components['schemas']['ImportKeysResolvableDto']
data: components['schemas']['ImportKeysResolvableDto'],
options?: Options
) {
const userToken = await userLogin();
let client = createClient(userToken!);
Expand All @@ -56,7 +61,7 @@ export async function createProjectWithClient(
body: {
name: name,
organizationId: organizations.data!._embedded!.organizations![0].id,
languages: languagesTestData,
languages: options?.languages ?? languagesTestData,
icuPlaceholders: true,
},
});
Expand Down
14 changes: 14 additions & 0 deletions src/test/e2e/utils/api/fullLanguageNamesProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { components } from '../../../../client/internal/schema.generated.js';
import en from '../../../__fixtures__/fullLanguageNamesProject/en-GB.json';
import fr from '../../../__fixtures__/fullLanguageNamesProject/fr-FR.json';

export const FULL_LANGUAGE_NAMES_PROJECT: components['schemas']['ImportKeysResolvableDto'] =
{
keys: Object.keys(en).map((name) => ({
name,
translations: {
'en-GB': { text: en[name], resolution: 'NEW' },
'fr-FR': { text: fr[name], resolution: 'NEW' },
},
})),
};

0 comments on commit c128d1d

Please sign in to comment.