Skip to content

Commit

Permalink
fix: review issues and changing key from ko to kr
Browse files Browse the repository at this point in the history
  • Loading branch information
rudouglas committed Feb 22, 2022
1 parent 26d1437 commit 0bc85ab
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { getLocalizedFileData } = require('../add-files-to-translation-queue');
const MOCK_CONSTANTS = {
LOCALE_IDS: {
jp: 'ja-JP',
ko: 'ko-KR',
kr: 'ko-KR',
},
};

Expand Down
56 changes: 32 additions & 24 deletions scripts/actions/__tests__/check-job-progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ describe('check-jobs-progress tests', () => {
test('updates translation record to COMPLETED for failed slug', async () => {
updateTranslations.mockReturnValue([{ id: 0 }]);

const slugStatus = { ok: false, slug: 'failure.txt' };
const slugStatus = { ok: false, slug: 'failure.txt', locale: 'ja-JP' };

await updateTranslationRecords([slugStatus]);

expect(updateTranslations.mock.calls.length).toBe(2);
expect(updateTranslations.mock.calls.length).toBe(1);
expect(updateTranslations.mock.calls[0][0]).toStrictEqual({
slug: 'failure.txt',
status: 'IN_PROGRESS',
Expand All @@ -100,24 +100,16 @@ describe('check-jobs-progress tests', () => {
expect(updateTranslations.mock.calls[0][1]).toStrictEqual({
status: 'COMPLETED',
});
expect(updateTranslations.mock.calls[1][0]).toStrictEqual({
slug: 'failure.txt',
status: 'IN_PROGRESS',
locale: 'ko-KR',
});
expect(updateTranslations.mock.calls[1][1]).toStrictEqual({
status: 'COMPLETED',
});
});

test('updates translation record to COMPLETED for successful slug', async () => {
updateTranslations.mockReturnValue([{ id: 0 }]);

const slugStatus = { ok: true, slug: 'success.txt' };
const slugStatus = { ok: true, slug: 'success.txt', locale: 'ja-JP' };

await updateTranslationRecords([slugStatus]);

expect(updateTranslations.mock.calls.length).toBe(2);
expect(updateTranslations.mock.calls.length).toBe(1);
expect(updateTranslations.mock.calls[0][0]).toStrictEqual({
slug: 'success.txt',
status: 'IN_PROGRESS',
Expand All @@ -126,27 +118,43 @@ describe('check-jobs-progress tests', () => {
expect(updateTranslations.mock.calls[0][1]).toStrictEqual({
status: 'COMPLETED',
});
expect(updateTranslations.mock.calls[1][0]).toStrictEqual({
slug: 'success.txt',
status: 'IN_PROGRESS',
locale: 'ko-KR',
});
expect(updateTranslations.mock.calls[1][1]).toStrictEqual({
status: 'COMPLETED',
});
});

test('updates multiple records', async () => {
updateTranslations.mockReturnValue([{ id: 0 }]);
const slugStatuses = [
{ ok: true, slug: 'fake_slug.txt' },
{ ok: false, slug: 'fake_slug_2.txt' },
{ ok: true, slug: 'fake_slug_3.txt' },
{ ok: true, slug: 'fake_slug.txt', locale: 'ja-JP' },
{ ok: false, slug: 'fake_slug_2.txt', locale: 'ko-KR' },
{ ok: true, slug: 'fake_slug_3.txt', locale: 'ko-KR' },
];

await updateTranslationRecords(slugStatuses);

expect(updateTranslations.mock.calls.length).toBe(6);
expect(updateTranslations.mock.calls.length).toBe(3);
expect(updateTranslations.mock.calls[0][0]).toStrictEqual({
slug: 'fake_slug.txt',
status: 'IN_PROGRESS',
locale: 'ja-JP',
});
expect(updateTranslations.mock.calls[0][1]).toStrictEqual({
status: 'COMPLETED',
});
expect(updateTranslations.mock.calls[1][0]).toStrictEqual({
slug: 'fake_slug_2.txt',
status: 'IN_PROGRESS',
locale: 'ko-KR',
});
expect(updateTranslations.mock.calls[1][1]).toStrictEqual({
status: 'COMPLETED',
});
expect(updateTranslations.mock.calls[2][0]).toStrictEqual({
slug: 'fake_slug_3.txt',
status: 'IN_PROGRESS',
locale: 'ko-KR',
});
expect(updateTranslations.mock.calls[2][1]).toStrictEqual({
status: 'COMPLETED',
});
});

test('logs errored translations to the console', async () => {
Expand Down
21 changes: 10 additions & 11 deletions scripts/actions/check-job-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
const { vendorRequest } = require('./utils/vendor-request');
const { fetchAndDeserializeFiles } = require('./fetch-and-deserialize');
const { configuration } = require('./configuration');
const { LOCALE_IDS } = require('./utils/constants.js');

const PROJECT_ID = configuration.TRANSLATION.VENDOR_PROJECT;

Expand Down Expand Up @@ -48,6 +47,7 @@ const prop = (key) => (x) => x[key];
* @property {boolean} SlugStatus[].ok - Boolean flag signaling if translation deserialized. If it did, we can treat this translation as having completed.
* @property {string} SlugStatus[].slug - Slug representing file path translated.
* @property {string} SlugStatus[].jobId - Job id translation is associated with.
* @property {string} SlugStatus[].locale - Locale ID translation is translated to.
*/

/**
Expand Down Expand Up @@ -175,16 +175,15 @@ const updateTranslationRecords = async (slugStatuses) => {
// TODO: need to update this when we implement multiple locales. This only works for one locale.

await Promise.all(
slugStatuses.map(async ({ slug }) => {
Object.values(LOCALE_IDS).forEach(async (localeId) => {
const records = await updateTranslations(
{ slug, status: StatusEnum.IN_PROGRESS, locale: localeId },
{ status: StatusEnum.COMPLETED }
);
console.log(
`Translation ${records[0].id} for ${localeId} marked as ${StatusEnum.COMPLETED}`
);
});
slugStatuses.map(async ({ locale, slug }) => {
const records = await updateTranslations(
{ slug, status: StatusEnum.IN_PROGRESS, locale },
{ status: StatusEnum.COMPLETED }
);

console.log(
`Translation ${records[0].id} marked as ${StatusEnum.COMPLETED}`
);
})
);
};
Expand Down
3 changes: 2 additions & 1 deletion scripts/actions/fetch-and-deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ const deserializeHtmlToMdx = (locale) => {
return {
ok: true,
slug: completePath,
locale,
};
} catch (ex) {
console.log(`Failed to deserialize: ${contentPath}`);
console.log(ex);

return { ok: false, slug: completePath };
return { ok: false, slug: completePath, locale };
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/actions/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This should be in the format {localeKey: locale} across scripts
const LOCALE_IDS = {
jp: 'ja-JP',
ko: 'ko-KR',
kr: 'ko-KR',
};

const EXCLUSIONS_FILE =
Expand Down

0 comments on commit 0bc85ab

Please sign in to comment.