Skip to content

Commit

Permalink
fix assignment path with kz locale (#35)
Browse files Browse the repository at this point in the history
* fix assignment path with kz locale

* fix node versions

* update

---------

Co-authored-by: Maksim Litvinov <[email protected]>
  • Loading branch information
Malcom1986 and Maksim Litvinov authored Dec 21, 2023
1 parent 3c7b06e commit 2c229fb
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# OS list
os: [ubuntu-latest, windows-latest, macos-latest]
# Node versions list
node-version: [14, 16, 18]
node-version: [14, 18, 21]

steps:
# When using the package on windows, line breaks will not be converted
Expand Down
160 changes: 160 additions & 0 deletions __tests__/assignments/__snapshots__/download.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,86 @@ exports[`Download assignment download the same assignment again (with backup) 3`
]
`;

exports[`Download assignment download with kz locale 1`] = `
[
{
"name": "hexlet-check.yml",
"path": "hexlet-assignments/.github/workflows/hexlet-check.yml",
"size": 600n,
},
{
"name": "README.md",
"path": "hexlet-assignments/README.md",
"size": 24n,
},
{
"name": ".gitignore",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/.gitignore",
"size": 29n,
},
{
"name": "Makefile",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/Makefile",
"size": 36n,
},
{
"name": "README.html",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/README.html",
"size": 27470n,
},
{
"name": "README.md",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/README.md",
"size": 3583n,
},
{
"name": "ShouldBeCleaned.md",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/ShouldBeCleaned.md",
"size": 0n,
},
{
"name": "build.gradle",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/build.gradle",
"size": 417n,
},
{
"name": "ThreadExample.java",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/examples/ThreadExample.java",
"size": 2687n,
},
{
"name": "fileWithMarkers",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/fileWithMarkers",
"size": 32n,
},
{
"name": "gradlew",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/gradlew",
"size": 5766n,
},
{
"name": "gradlew.bat",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/gradlew.bat",
"size": 2763n,
},
{
"name": "presentation.pdf",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/presentation.pdf",
"size": 1110740n,
},
{
"name": "App.java",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/src/main/java/exercise/App.java",
"size": 36n,
},
{
"name": "AppTest.java",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/src/test/java/exercise/AppTest.java",
"size": 403n,
},
]
`;

exports[`Download latest version of the assignment reset 1`] = `
[
{
Expand Down Expand Up @@ -339,3 +419,83 @@ exports[`Download latest version of the assignment reset the same assignment aga
},
]
`;

exports[`Download latest version of the assignment reset with kz locale 1`] = `
[
{
"name": "hexlet-check.yml",
"path": "hexlet-assignments/.github/workflows/hexlet-check.yml",
"size": 600n,
},
{
"name": "README.md",
"path": "hexlet-assignments/README.md",
"size": 24n,
},
{
"name": ".gitignore",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/.gitignore",
"size": 29n,
},
{
"name": "Makefile",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/Makefile",
"size": 36n,
},
{
"name": "README.html",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/README.html",
"size": 27470n,
},
{
"name": "README.md",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/README.md",
"size": 3583n,
},
{
"name": "ShouldBeCleaned.md",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/ShouldBeCleaned.md",
"size": 0n,
},
{
"name": "build.gradle",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/build.gradle",
"size": 417n,
},
{
"name": "ThreadExample.java",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/examples/ThreadExample.java",
"size": 2687n,
},
{
"name": "fileWithMarkers",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/fileWithMarkers",
"size": 32n,
},
{
"name": "gradlew",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/gradlew",
"size": 5766n,
},
{
"name": "gradlew.bat",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/gradlew.bat",
"size": 2763n,
},
{
"name": "presentation.pdf",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/presentation.pdf",
"size": 1110740n,
},
{
"name": "App.java",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/src/main/java/exercise/App.java",
"size": 36n,
},
{
"name": "AppTest.java",
"path": "hexlet-assignments/java-advanced-ru/multithreading-java/src/test/java/exercise/AppTest.java",
"size": 403n,
},
]
`;
25 changes: 21 additions & 4 deletions __tests__/assignments/download.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const assignmentResetCmd = require('../../src/commands/assignment/reset.js');
const { initSettings } = require('../../src/config.js');
const { readDirP, getFixturePath, getAssignmentConfig } = require('../helpers/index.js');

const buildLessonUrl = (courseSlug, lessonSlug) => (
`https://ru.hexlet.io/courses/${courseSlug}/lessons/${lessonSlug}/theory_unit`
const buildLessonUrl = (courseSlug, lessonSlug, locale = 'ru') => (
`https://${locale}.hexlet.io/courses/${courseSlug}/lessons/${lessonSlug}/theory_unit`
);
const buildApiUrl = (courseSlug, lessonSlug) => (
`https://ru.hexlet.io/api_internal/courses/${courseSlug}/lessons/${lessonSlug}/assignment/download`
const buildApiUrl = (courseSlug, lessonSlug, locale = 'ru') => (
`https://${locale}.hexlet.io/api_internal/courses/${courseSlug}/lessons/${lessonSlug}/assignment/download`
);

const hexletToken = 'some-hexlet-token';
Expand Down Expand Up @@ -62,6 +62,12 @@ describe.each(testCases)('$command.description', ({
.matchHeader('X-Auth-Key', hexletToken)
.intercept('', method)
.replyWithFile(successCode, lessonArchivePath);

const scope2 = nock(buildApiUrl(courseSlug, lessonSlug, 'kz')).persist();
scope2
.matchHeader('X-Auth-Key', hexletToken)
.intercept('', method)
.replyWithFile(successCode, lessonArchivePath);
});

afterAll(() => {
Expand All @@ -87,6 +93,17 @@ describe.each(testCases)('$command.description', ({
expect(await readDirP(hexletDir)).toMatchSnapshot();
});

it(`${commandName} with kz locale`, async () => {
await fse.writeJson(hexletConfigPath, config);
const params = {
...args,
lessonUrl: buildLessonUrl(courseSlug, lessonSlug, 'kz'),
};

await command.handler(params, customSettings);
expect(await readDirP(hexletDir)).toMatchSnapshot();
});

it(`${commandName} the same assignment again (with backup)`, async () => {
await fse.writeJson(hexletConfigPath, config);
const coursePath = path.join(assignmentsPath, courseSlugWithLocale);
Expand Down
10 changes: 9 additions & 1 deletion src/utils/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const path = require('path');

const git = require('./git.js');

const contentLocales = {
ru: 'ru',
kz: 'ru',
en: 'en',
es: 'es',
};

const isValidLessonUrl = (lessonUrl) => {
const urlRegExp = /^https:\/\/\w{0,2}\.*hexlet.io\/courses\/.+\/lessons\/[^/]+/;
return urlRegExp.test(lessonUrl);
Expand Down Expand Up @@ -36,7 +43,8 @@ const getLessonData = (lessonUrl) => {
};

const generateAssignmentPath = (repoPath, courseSlug, lessonSlug, locale) => {
const courseSlugWithLocale = locale === 'en' ? courseSlug : `${courseSlug}-${locale}`;
const normalizedLocale = contentLocales[locale];
const courseSlugWithLocale = normalizedLocale === 'en' ? courseSlug : `${courseSlug}-${normalizedLocale}`;
return path.join(repoPath, courseSlugWithLocale, lessonSlug);
};

Expand Down

0 comments on commit 2c229fb

Please sign in to comment.