Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Fix exam results overview e2e test #9472

Merged
merged 1 commit into from
Oct 13, 2024

Conversation

SimonEntholzer
Copy link
Contributor

@SimonEntholzer SimonEntholzer commented Oct 13, 2024

Checklist

General

Motivation and Context

The Results › Check exam exercise results › Check exam results for text exercise › Check exam result overview e2e test is still failing.
This is caused by the test relying on the generate-missing-student-exams request to obtain the student exam id, of the student participating in the exam. Since the student exams are already generated automatically, this request yields an empty array, which causes the test to fail as it tries to access the id property of an undefined student exam.

Description

Instead of relying on the result of the student-exam generation, the student exams are explicitly fetched with the
.../exams/${exam.id}/student-exams endpoint

Steps for Testing

Check that the test runs through correctly.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

  • New Features
    • Introduced a new method to retrieve all student exams associated with a specific exam.
  • Bug Fixes
    • Updated logic for fetching student exams to ensure accurate data retrieval after adding exercises to exams.

Copy link

coderabbitai bot commented Oct 13, 2024

Walkthrough

This pull request introduces changes to the test suite for exam results by modifying the method used to retrieve student exams. The existing call to generateMissingIndividualExams has been replaced with a new method getAllStudentExams, which fetches all student exams associated with a specific exam. Additionally, a new method is added to the ExamAPIRequests class to facilitate this retrieval. The overall structure of the test cases remains unchanged.

Changes

File Path Change Summary
src/test/playwright/e2e/exam/ExamResults.spec.ts Replaced generateMissingIndividualExams with getAllStudentExams for retrieving student exams.
src/test/playwright/support/requests/ExamAPIRequests.ts Added new method async getAllStudentExams(exam: Exam) to retrieve all student exams for a specific exam.

Possibly related PRs

Suggested labels

bugfix, server

Suggested reviewers

  • coolchock
  • JohannesStoehr
  • BBesrour
  • rstief

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between e072169 and fed2c00.

📒 Files selected for processing (2)
  • src/test/playwright/e2e/exam/ExamResults.spec.ts (1 hunks)
  • src/test/playwright/support/requests/ExamAPIRequests.ts (1 hunks)
🧰 Additional context used
🪛 Biome
src/test/playwright/support/requests/ExamAPIRequests.ts

[error] 173-173: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

🔇 Additional comments (2)
src/test/playwright/support/requests/ExamAPIRequests.ts (1)

168-175: 🧹 Nitpick (assertive)

Approve implementation with suggestions for improvement

The new getAllStudentExams method is well-implemented and consistent with the existing codebase. However, there are a few suggestions for improvement:

  1. Add error handling to manage potential API request failures.
  2. Include a return type for better type safety.
  3. Address the non-null assertion on exam.course!.id.

Here's a suggested implementation with these improvements:

async getAllStudentExams(exam: Exam): Promise<StudentExam[]> {
  try {
    const response = await this.page.request.get(`${COURSE_BASE}/${exam.course?.id}/exams/${exam.id}/student-exams`);
    return await response.json();
  } catch (error) {
    console.error('Failed to fetch student exams:', error);
    throw error;
  }
}

This implementation:

  1. Adds a return type Promise<StudentExam[]> for better type safety.
  2. Includes a try-catch block for error handling.
  3. Uses the optional chaining operator ?. instead of the non-null assertion ! to safely access exam.course.id.

To ensure that StudentExam is properly imported, run the following script:

If the StudentExam import is missing, you'll need to add it at the top of the file:

import { StudentExam } from 'app/entities/student-exam.model';
✅ Verification successful

StudentExam Import Verified

The import for StudentExam is present and correctly implemented in ExamAPIRequests.ts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that StudentExam is imported
grep -n "import.*StudentExam" src/test/playwright/support/requests/ExamAPIRequests.ts

Length of output: 153

🧰 Tools
🪛 Biome

[error] 173-173: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

src/test/playwright/e2e/exam/ExamResults.spec.ts (1)

85-85: Verify the implementation of getAllStudentExams and consider additional testing.

While this change addresses the immediate issue, please ensure that:

  1. The getAllStudentExams method is properly implemented in the ExamAPIRequests class to handle all possible scenarios (e.g., no exams, multiple exams).
  2. The change doesn't introduce any timing issues or race conditions, especially if there's a delay between exam creation and availability.
  3. The test still covers all necessary scenarios, including edge cases like exams with no participants.

Consider adding a test case that explicitly verifies the behavior when multiple student exams exist for the same exam.

To verify the implementation of getAllStudentExams, you can run the following script:

✅ Verification successful

Implementation of getAllStudentExams Verified

The getAllStudentExams method is properly implemented in the ExamAPIRequests class and is correctly utilized within the test files. No issues were found during the verification process.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of getAllStudentExams in ExamAPIRequests

# Test: Search for the getAllStudentExams method definition
echo "Searching for getAllStudentExams method definition:"
rg --type typescript "getAllStudentExams.*\(.*\).*{" src/test/playwright/support/requests/

# Test: Check for error handling in the method
echo "Checking for error handling in getAllStudentExams:"
rg --type typescript "getAllStudentExams.*\(.*\).*{" -A 10 src/test/playwright/support/requests/ | rg "try|catch|throw"

# Test: Look for usage of getAllStudentExams in other test files
echo "Searching for other usages of getAllStudentExams:"
rg --type typescript "getAllStudentExams\(" src/test/playwright/

Length of output: 893


Script:

#!/bin/bash
# Description: Verify the implementation of getAllStudentExams in ExamAPIRequests

# Test: Search for the getAllStudentExams method definition
echo "Searching for getAllStudentExams method definition:"
rg --type typescript "getAllStudentExams\s*\(.*\)\s*{" src/test/playwright/support/requests/

# Test: Check for error handling in the method
echo "Checking for error handling in getAllStudentExams:"
rg --type typescript "getAllStudentExams\s*\(.*\)\s*{" -A 10 src/test/playwright/support/requests/ | rg "try|catch|throw"

# Test: Look for usage of getAllStudentExams in other test files
echo "Searching for other usages of getAllStudentExams:"
rg --type typescript "getAllStudentExams\s*\(" src/test/playwright/

Length of output: 908


Script:

#!/bin/bash
# Description: Verify the implementation of getAllStudentExams in ExamAPIRequests

# Test: Search for the getAllStudentExams method definition
echo "Searching for getAllStudentExams method definition:"
rg --type ts "getAllStudentExams\s*\(.*\)\s*\{" src/test/playwright/support/requests/

# Test: Check for error handling in the method
echo "Checking for error handling in getAllStudentExams:"
rg --type ts "getAllStudentExams\s*\(.*\)\s*\{" -A 10 src/test/playwright/support/requests/ | rg "try|catch|throw"

# Test: Look for usage of getAllStudentExams in other test files
echo "Searching for other usages of getAllStudentExams:"
rg --type ts "getAllStudentExams\s*\(" src/test/playwright/

Length of output: 935

@krusche krusche added this to the 7.6.0 milestone Oct 13, 2024
@krusche krusche merged commit 6549075 into develop Oct 13, 2024
33 of 37 checks passed
@krusche krusche deleted the chore/bugfix/fix-missed-failing-e2e-test branch October 13, 2024 18:35
@krusche krusche changed the title Development: Fix the exam results overview playwright test Development: Fix exam results overview e2e test Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants