-
Notifications
You must be signed in to change notification settings - Fork 1
Test/new/scheduler #126
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
Draft
trappaly
wants to merge
5
commits into
development
Choose a base branch
from
test/new/scheduler
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Test/new/scheduler #126
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a34627
updated helper scheduler tests to pass
trappaly ff9080e
updated schedu
trappaly 9a02aed
deleted unecessasry tests and moved tests to user utils file
trappaly 621ae16
added another test and fixed identation
trappaly cc03b1f
Added calculate deadline test
trappaly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { describe, it, expect, beforeAll } from 'vitest'; | ||
| import FakeDataFactory from './FakeDataFactory'; | ||
| import Scheduler from '../utils/Scheduler'; | ||
| import { PreferenceQuestion, User, UserDeadline, UserEvent, UserPreference } from '../db/types.ts'; | ||
| import { faker } from '@faker-js/faker'; | ||
|
|
||
| /* | ||
| * Test to test the calculate deadline remainders function | ||
| */ | ||
|
|
||
| describe("calculate deadline remainders with specific data", () => { | ||
| // Declares types of variables | ||
| let factory: FakeDataFactory; | ||
| let user: User; | ||
| let userEvents: UserEvent[] = []; | ||
| let userDeadlines: UserDeadline[] = []; | ||
| let userPreferences: UserPreference[] = []; | ||
|
|
||
| // Initializes all of the variables before the test | ||
| beforeAll(() => { | ||
| factory = new FakeDataFactory(); | ||
| user = factory.randomUser(); | ||
| userEvents = [ | ||
| { | ||
| id: "event1", | ||
| user_id: user.id, | ||
| title: "Event 1", | ||
| start_time: new Date("2025-05-15T09:00:00"), | ||
| end_time: new Date("2025-05-15T11:00:00"), | ||
| description: "CS Class", | ||
| location_place: "Noyce", | ||
| is_recurring: false, | ||
| recurrence_pattern: null, | ||
| recurrence_start_date: null, | ||
| recurrence_end_date: null, | ||
| is_generated: false, | ||
| break_time: "00:15", | ||
| created_at: new Date(), | ||
| deadline_id: "class", | ||
| }, | ||
| { | ||
| id: "Tennis practce", | ||
| user_id: user.id, | ||
| title: "Tennis practice", | ||
| start_time: new Date("2025-05-15T14:00:00"), | ||
| end_time: new Date("2025-05-15T16:00:00"), | ||
| description: "Tennis practice", | ||
| location_place: "Tennis Courts", | ||
| is_recurring: false, | ||
| recurrence_pattern: null, | ||
| recurrence_start_date: null, | ||
| recurrence_end_date: null, | ||
| is_generated: false, | ||
| break_time: "00:10", | ||
| created_at: new Date(), | ||
| deadline_id: "tennis", | ||
| } | ||
| ]; | ||
|
|
||
| userDeadlines = [ | ||
| { | ||
| id: "test", | ||
| user_id: user.id, | ||
| event_id: "test", | ||
| title: "test", | ||
| due_time: new Date("2025-05-15T12:00:00"), | ||
| description: "Test", | ||
| priority: "High", | ||
| projected_duration: 60, // 1 hour | ||
| created_at: new Date(), | ||
| }, | ||
| { | ||
| id: "essay", | ||
| user_id: user.id, | ||
| event_id: "essay", | ||
| title: "essay", | ||
| due_time: new Date("2025-05-15T18:00:00"), | ||
| description: "essay", | ||
| priority: "Medium", | ||
| projected_duration: 120, // 2 hours | ||
| created_at: new Date(), | ||
| } | ||
| ]; | ||
|
|
||
| userPreferences = [ | ||
| { | ||
| id: "pref", | ||
| user_id: user.id, | ||
| question_id: "question", | ||
| answer: "answer", | ||
| } | ||
| ]; | ||
| }); | ||
| // Testing for a regular unscheduled minutes | ||
| it("regular test case to schedule unscheduled minutes", () => { | ||
| userEvents.forEach((event) => { | ||
| const deadline = userDeadlines.find(d => d.id === event.deadline_id); | ||
| // Makes sure deadline, end time, and start times found | ||
| if (deadline && event.end_time && event.start_time) { | ||
| const result = Scheduler.calculateDeadlineRemainders([event], [deadline]); | ||
|
|
||
| // Expected scheduled duration in minutes | ||
| const scheduledDuration = (event.end_time.getTime() - event.start_time.getTime()) / 60000; | ||
|
|
||
| // Declare outside the if-block | ||
| let expectedUnscheduled = 0; | ||
|
|
||
| // Checks to make sure deadline isn't null and if it's not null then subtract the total amount scheduled minutes away from the unscheduled minutes | ||
| if (deadline.projected_duration != null) { | ||
| expectedUnscheduled = deadline.projected_duration - scheduledDuration; | ||
| } | ||
| // Checks to make sure the test passes | ||
| expect(result[0].unscheduledMinutes).toBeCloseTo(expectedUnscheduled, 1); | ||
| } | ||
| // throws an error otherwise | ||
| else { | ||
| console.error(`Missing data for event: ${event.id}`); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaning up, good