Skip to content

Conversation

@emp74ark
Copy link
Contributor

@emp74ark emp74ark commented Oct 7, 2025

Issue:

Description:

  • Added InterviewTemplateValidator and QuestionCategoryValidator classes to validate unique category and question IDs.
  • Added unit tests for the new validation classes.
  • The app build (next build) will now fail with a TemplateValidationError if duplicates are found in an interview template.
  • The TemplateValidationError for duplicate category IDs includes the template name in the error message.
  • The TemplateValidationError for duplicate question IDs includes the category ID.

Usage

new InterviewTemplateValidator(corejs1Template);
image

Self-Check

  • Changes have been tested locally.

@emp74ark emp74ark self-assigned this Oct 7, 2025
@emp74ark emp74ark linked an issue Oct 7, 2025 that may be closed by this pull request
@emp74ark emp74ark requested a review from AlreadyBored October 7, 2025 19:12
@emp74ark emp74ark moved this to In review in RS School App Oct 16, 2025
@AlreadyBored AlreadyBored marked this pull request as ready for review October 19, 2025 16:43
}
}

export class InterviewTemplateValidator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we don't really need classes here, it can be just a function that performs checks and throws error if something is wrong

descriptionHtml?: string;
}

export class QuestionCategoryValidator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this class, it can be just a part of the function I mentioned above

@AlreadyBored AlreadyBored requested a review from Copilot October 19, 2025 16:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds validation for interview templates to ensure category and question IDs are unique, and fails the build with a clear error when duplicates are detected.

  • Introduces TemplateValidationError, InterviewTemplateValidator, and QuestionCategoryValidator
  • Validates templates during module initialization; adds unit tests for validators

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
client/src/data/interviews/templateValidator.ts Adds validation classes and error type to enforce unique category/question IDs
client/src/data/interviews/index.ts Instantiates validators for each template during export to fail builds on duplicates
client/src/data/interviews/testes/templateValidator.test.ts Adds unit tests for validation behavior and error messaging

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


const uniqueQuestionIds = new Set<number>(questions?.map(q => q.id) ?? []);

if (uniqueQuestionIds.size !== questions?.length) {
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If questions is undefined, questions?.length yields undefined, so 0 !== undefined evaluates to true and incorrectly throws. Guard the check when questions is provided, or coalesce length to 0.

Suggested change
if (uniqueQuestionIds.size !== questions?.length) {
if (uniqueQuestionIds.size !== (questions?.length ?? 0)) {

Copilot uses AI. Check for mistakes.

Comment on lines +14 to +21
corejs1: new InterviewTemplateValidator(corejs1Template),
corejs2: new InterviewTemplateValidator(corejs2Template),
react: new InterviewTemplateValidator(reactTemplate),
angular: new InterviewTemplateValidator(angularTemplate),
shortTrackScreening: new InterviewTemplateValidator(shortTrackScreeningTemplate),
shortTrackJavaScript: new InterviewTemplateValidator(shortTrackJavaScriptTemplate),
shortTrackTypeScript: new InterviewTemplateValidator(shortTrackTypeScriptTemplate),
shortTrackPerformance: new InterviewTemplateValidator(shortTrackPerformanceTemplate),
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing template objects with InterviewTemplateValidator instances changes the exported API shape and inferred type of templates, potentially breaking consumers that expect InterviewTemplate. Validate as a side-effect but export the original template objects (and annotate templates as Record<string, InterviewTemplate>) to preserve the public API.

Copilot uses AI. Check for mistakes.

questions: [mockQuestion1, mockQuestionDuplicateId], // IDs are 101, 101
};

describe('TemplateValidationError', () => {
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder name 'testes' appears to be a typo; rename to 'tests' so standard test runners detect and execute these tests.

Copilot uses AI. Check for mistakes.

Comment on lines +24 to +26
categories.forEach(category => {
return new QuestionCategoryValidator(category);
});
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The return inside forEach is unnecessary and misleading; the callback's return value is ignored. Simplify to categories.forEach(category => new QuestionCategoryValidator(category)).

Suggested change
categories.forEach(category => {
return new QuestionCategoryValidator(category);
});
categories.forEach(category => new QuestionCategoryValidator(category));

Copilot uses AI. Check for mistakes.

@emp74ark emp74ark moved this from In review to Done in RS School App Oct 21, 2025
@emp74ark emp74ark moved this from Done to In review in RS School App Oct 21, 2025
@apalchys
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Validation for the interview template entries

3 participants