-
Notifications
You must be signed in to change notification settings - Fork 23
Feature: customize weekends #61
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
33 changes: 33 additions & 0 deletions
33
src/converters/utils/calculations/calcAverageValue.spec.ts
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,33 @@ | ||
| import { calcAverageValue } from './calcAverageValue'; | ||
|
|
||
| describe('calcAverageValue', () => { | ||
| it('should return 0 if no values are provided', () => { | ||
| expect(calcAverageValue()).toBe(0); | ||
| }); | ||
|
|
||
| it('should return 0 if an empty array is provided', () => { | ||
| expect(calcAverageValue([])).toBe(0); | ||
| }); | ||
|
|
||
| it('should return the average value of the provided numbers', () => { | ||
| expect(calcAverageValue([1, 2, 3, 4, 5])).toBe(3); | ||
| expect(calcAverageValue([10, 20, 30])).toBe(20); | ||
| expect(calcAverageValue([1, 1, 1, 1, 1])).toBe(1); | ||
| }); | ||
|
|
||
| it('should return the ceiling of the average value', () => { | ||
| expect(calcAverageValue([1, 2, 3])).toBe(2); | ||
| expect(calcAverageValue([1, 2, 2])).toBe(2); | ||
| expect(calcAverageValue([1, 1, 2])).toBe(2); | ||
| }); | ||
|
|
||
| it('should handle negative numbers correctly', () => { | ||
| expect(calcAverageValue([-1, -2, -3, -4, -5])).toBe(-3); | ||
| expect(calcAverageValue([-10, -20, -30])).toBe(-20); | ||
| }); | ||
|
|
||
| it('should handle a mix of positive and negative numbers', () => { | ||
| expect(calcAverageValue([-1, 1, -1, 1])).toBe(0); | ||
| expect(calcAverageValue([-10, 10, -10, 10])).toBe(0); | ||
| }); | ||
| }); |
101 changes: 101 additions & 0 deletions
101
src/converters/utils/calculations/calcDraftTime.spec.ts
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,101 @@ | ||
| import { calcDraftTime } from "./calcDraftTime"; | ||
| import { | ||
| convertToDraftTimelineEvent, | ||
| readyForReviewTimelineEvent, | ||
| } from "../../constants"; | ||
|
|
||
| describe("calcDraftTime", () => { | ||
| it("should return an empty array if statuses is empty", () => { | ||
| const result = calcDraftTime( | ||
| "2021-01-01T00:00:00Z", | ||
| "2021-01-02T00:00:00Z", | ||
| [] | ||
| ); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it("should calculate draft time correctly when there is only one readyForReviewTimelineEvent", () => { | ||
| const statuses = [ | ||
| { | ||
| event: readyForReviewTimelineEvent, | ||
| created_at: "2021-01-01T12:00:00Z", | ||
| }, | ||
| ]; | ||
| const result = calcDraftTime( | ||
| "2021-01-01T00:00:00Z", | ||
| "2021-01-02T00:00:00Z", | ||
| statuses | ||
| ); | ||
| expect(result).toEqual([["2021-01-01T00:00:00Z", "2021-01-01T12:00:00Z"]]); | ||
| }); | ||
|
|
||
| it("should calculate draft time correctly when there are multiple events", () => { | ||
| const statuses = [ | ||
| { | ||
| event: convertToDraftTimelineEvent, | ||
| created_at: "2021-01-01T12:00:00Z", | ||
| }, | ||
| { | ||
| event: readyForReviewTimelineEvent, | ||
| created_at: "2021-01-01T14:00:00Z", | ||
| }, | ||
| { | ||
| event: convertToDraftTimelineEvent, | ||
| created_at: "2021-01-01T16:00:00Z", | ||
| }, | ||
| { | ||
| event: readyForReviewTimelineEvent, | ||
| created_at: "2021-01-01T18:00:00Z", | ||
| }, | ||
| ]; | ||
| const result = calcDraftTime( | ||
| "2021-01-01T00:00:00Z", | ||
| "2021-01-02T00:00:00Z", | ||
| statuses | ||
| ); | ||
| expect(result).toEqual([ | ||
| ["2021-01-01T12:00:00Z", "2021-01-01T14:00:00Z"], | ||
| ["2021-01-01T16:00:00Z", "2021-01-01T18:00:00Z"], | ||
| ]); | ||
| }); | ||
|
|
||
| it("should include the closedAt time if the last event is convertToDraftTimelineEvent", () => { | ||
| const statuses = [ | ||
| { | ||
| event: readyForReviewTimelineEvent, | ||
| created_at: "2021-01-01T12:00:00Z", | ||
| }, | ||
| { | ||
| event: convertToDraftTimelineEvent, | ||
| created_at: "2021-01-01T14:00:00Z", | ||
| }, | ||
| ]; | ||
| const result = calcDraftTime( | ||
| "2021-01-01T00:00:00Z", | ||
| "2021-01-02T00:00:00Z", | ||
| statuses | ||
| ); | ||
| expect(result).toEqual([ | ||
| ["2021-01-01T00:00:00Z", "2021-01-01T12:00:00Z"], | ||
| ["2021-01-01T14:00:00Z", "2021-01-02T00:00:00Z"], | ||
| ]); | ||
| }); | ||
|
|
||
| it("should handle undefined createdAt and closedAt correctly", () => { | ||
| const statuses = [ | ||
| { | ||
| event: readyForReviewTimelineEvent, | ||
| created_at: "2021-01-01T12:00:00Z", | ||
| }, | ||
| { | ||
| event: convertToDraftTimelineEvent, | ||
| created_at: "2021-01-01T14:00:00Z", | ||
| }, | ||
| ]; | ||
| const result = calcDraftTime(undefined, undefined, statuses); | ||
| expect(result).toEqual([ | ||
| [undefined, "2021-01-01T12:00:00Z"], | ||
| ["2021-01-01T14:00:00Z", undefined], | ||
| ]); | ||
| }); | ||
| }); |
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
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,4 @@ | ||
| import { getMultipleValuesInput } from "../../../common/utils"; | ||
| export const checkUserInclusive = (name: string) => { | ||
| return !getMultipleValuesInput('EXCLUDE_USERS').includes(name) ; | ||
| }; |
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,52 @@ | ||
| import { checkWeekend } from "./checkWeekend"; | ||
| import { getMultipleValuesInput } from "../../../common/utils"; | ||
|
|
||
| jest.mock("../../../common/utils", () => ({ | ||
| getMultipleValuesInput: jest.fn(), | ||
| })); | ||
|
|
||
| describe("checkWeekend", () => { | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it("should return true if the date is a weekend", () => { | ||
| (getMultipleValuesInput as jest.Mock).mockReturnValue(["0", "6"]); // Sunday and Saturday | ||
|
|
||
| const date = new Date("2021-01-02T00:00:00Z"); // Saturday | ||
| const result = checkWeekend(date); | ||
| expect(result).toBe(true); | ||
| }); | ||
AlexSim93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it("should return false if the date is not a weekend", () => { | ||
| (getMultipleValuesInput as jest.Mock).mockReturnValue(["0", "6"]); // Sunday and Saturday | ||
|
|
||
| const date = new Date("2021-01-01T00:00:00Z"); // Friday | ||
| const result = checkWeekend(date); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should handle numeric input for date", () => { | ||
| (getMultipleValuesInput as jest.Mock).mockReturnValue(["0", "6"]); // Sunday and Saturday | ||
|
|
||
| const date = new Date("2021-01-02T00:00:00Z").getTime(); // Saturday | ||
| const result = checkWeekend(date); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it("should return false if WEEKENDS environment variable is not set", () => { | ||
| (getMultipleValuesInput as jest.Mock).mockReturnValue([]); | ||
|
|
||
| const date = new Date("2021-01-02T00:00:00Z"); // Saturday | ||
| const result = checkWeekend(date); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it("should return true for custom weekend days", () => { | ||
| (getMultipleValuesInput as jest.Mock).mockReturnValue(["1", "2"]); // Monday and Tuesday | ||
|
|
||
| const date = new Date("2021-01-04T00:00:00Z"); // Monday | ||
| const result = checkWeekend(date); | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
AlexSim93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,8 @@ | ||
| import { getDay } from "date-fns"; | ||
| import { getMultipleValuesInput } from "../../../common/utils"; | ||
|
|
||
| export const checkWeekend = (date: Date | number) => { | ||
| const currentDay = getDay(date); | ||
| const weekends = getMultipleValuesInput('WEEKENDS').map((el) => parseInt(el)); | ||
| return weekends.includes(currentDay); | ||
| }; | ||
AlexSim93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.