-
Notifications
You must be signed in to change notification settings - Fork 61
fix(dates): allow clearing issue, cycle, and module dates #255
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
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package handler_test | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/Devlaner/devlane/api/internal/model" | ||
| "github.com/Devlaner/devlane/api/internal/testutil" | ||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // reloadIssue reads a fresh copy — GORM's First does not reset a reused struct's | ||
| // NULL fields, so each assertion needs its own value. | ||
| func reloadIssue(t *testing.T, ts *testutil.TestServer, id uuid.UUID) model.Issue { | ||
| t.Helper() | ||
| var got model.Issue | ||
| require.NoError(t, ts.DB.First(&got, "id = ?", id).Error) | ||
| return got | ||
| } | ||
|
|
||
| func TestIssue_ClearDates(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| issue := testutil.CreateIssue(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + | ||
| "/issues/" + issue.ID.String() + "/" | ||
|
|
||
| // Set both dates. | ||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{ | ||
| "start_date": "2026-03-15", "target_date": "2026-03-20", | ||
| }, w.Session).Code) | ||
| set := reloadIssue(t, ts, issue.ID) | ||
| require.NotNil(t, set.StartDate) | ||
| require.NotNil(t, set.TargetDate) | ||
|
|
||
| // Clearing with null persists as NULL. | ||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{ | ||
| "start_date": nil, "target_date": nil, | ||
| }, w.Session).Code) | ||
| cleared := reloadIssue(t, ts, issue.ID) | ||
| require.Nil(t, cleared.StartDate, "start_date should clear to null") | ||
| require.Nil(t, cleared.TargetDate, "target_date should clear to null") | ||
|
|
||
| // Omitting the field leaves it unchanged. | ||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{"start_date": "2026-04-01"}, w.Session).Code) | ||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{"name": "Renamed"}, w.Session).Code) | ||
| kept := reloadIssue(t, ts, issue.ID) | ||
| require.NotNil(t, kept.StartDate, "omitting start_date must not clear it") | ||
| } | ||
|
|
||
| func TestCycle_ClearDates(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| cy := testutil.CreateCycle(t, ts.DB, w.Project.ID, w.Workspace.ID, w.User.ID) | ||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + | ||
| "/cycles/" + cy.ID.String() + "/" | ||
|
|
||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{ | ||
| "start_date": "2026-03-15", "end_date": "2026-03-20", | ||
| }, w.Session).Code) | ||
| var set model.Cycle | ||
| require.NoError(t, ts.DB.First(&set, "id = ?", cy.ID).Error) | ||
| require.NotNil(t, set.StartDate) | ||
| require.NotNil(t, set.EndDate) | ||
|
|
||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{ | ||
| "start_date": nil, "end_date": nil, | ||
| }, w.Session).Code) | ||
| var cleared model.Cycle | ||
| require.NoError(t, ts.DB.First(&cleared, "id = ?", cy.ID).Error) | ||
| require.Nil(t, cleared.StartDate, "cycle start_date should clear") | ||
| require.Nil(t, cleared.EndDate, "cycle end_date should clear") | ||
| } | ||
|
|
||
| func TestModule_ClearDates(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| w := testutil.SeedWorld(t, ts.DB) | ||
| mod := testutil.CreateModule(t, ts.DB, w.Project.ID, w.Workspace.ID) | ||
| base := "/api/workspaces/" + w.Workspace.Slug + "/projects/" + w.Project.ID.String() + | ||
| "/modules/" + mod.ID.String() + "/" | ||
|
|
||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{ | ||
| "start_date": "2026-03-15", "target_date": "2026-03-20", | ||
| }, w.Session).Code) | ||
| var set model.Module | ||
| require.NoError(t, ts.DB.First(&set, "id = ?", mod.ID).Error) | ||
| require.NotNil(t, set.StartDate) | ||
| require.NotNil(t, set.TargetDate) | ||
|
|
||
| require.Equal(t, http.StatusOK, ts.PATCH(base, map[string]any{ | ||
| "start_date": nil, "target_date": nil, | ||
| }, w.Session).Code) | ||
| var cleared model.Module | ||
| require.NoError(t, ts.DB.First(&cleared, "id = ?", mod.ID).Error) | ||
| require.Nil(t, cleared.StartDate, "module start_date should clear") | ||
| require.Nil(t, cleared.TargetDate, "module target_date should clear") | ||
| } |
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,40 @@ | ||
| package handler | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // parseUpdatableDate reads a JSON date field for PATCH semantics so a set date | ||
| // can actually be cleared: | ||
| // | ||
| // key absent -> set=false (leave the value unchanged) | ||
| // null or "" -> set=true, t=nil (clear the date) | ||
| // "YYYY-MM-DD" -> set=true, t=&parsed | ||
| // RFC3339 timestamp -> set=true, t=&parsed | ||
| // | ||
| // ok=false signals an unparseable value; the caller should return 400. | ||
| func parseUpdatableDate(raw json.RawMessage) (set bool, t *time.Time, ok bool) { | ||
| if len(raw) == 0 { | ||
| return false, nil, true | ||
| } | ||
| if string(raw) == "null" { | ||
| return true, nil, true | ||
| } | ||
| var s string | ||
| if err := json.Unmarshal(raw, &s); err != nil { | ||
| return false, nil, false | ||
| } | ||
| s = strings.TrimSpace(s) | ||
| if s == "" { | ||
| return true, nil, true | ||
| } | ||
| if parsed, err := time.Parse(time.RFC3339, s); err == nil { | ||
| return true, &parsed, true | ||
| } | ||
| if parsed, err := time.Parse("2006-01-02", s); err == nil { | ||
| return true, &parsed, true | ||
| } | ||
| return false, nil, false | ||
| } |
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
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
Oops, something went wrong.
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.