Improve the task logic.
This commit is contained in:
@@ -2,7 +2,6 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/utils/check"
|
"github.com/LazyBachelor/LazyPM/internal/utils/check"
|
||||||
@@ -103,47 +102,32 @@ func (t *IssueReviewCleanupTask) Validate(ctx context.Context) ValidationFeedbac
|
|||||||
|
|
||||||
issues, err := FetchIssues(ctx, t.app, t.setupIssue)
|
issues, err := FetchIssues(ctx, t.app, t.setupIssue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return expect.Fail("Could not fetch issues: " + err.Error()).Complete()
|
return expect.Fatal("Could not fetch issues")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 1 cannot be verified (opening/viewing leaves no trace) — not shown in results
|
// Count the amount of comments on each issue
|
||||||
|
commentCount := map[string]int{}
|
||||||
// Step 2: Add comment to 2 issues
|
|
||||||
var issueIDs []string
|
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
issueIDs = append(issueIDs, issue.ID)
|
comments, _ := t.app.Issues.GetIssueComments(ctx, issue.ID)
|
||||||
|
commentCount[issue.ID] = len(comments)
|
||||||
}
|
}
|
||||||
issuesWithComments := 0
|
|
||||||
if len(issueIDs) > 0 {
|
// Add a count if there are comment on a issue
|
||||||
counts, err := t.app.Issues.GetCommentCounts(ctx, issueIDs)
|
commentsInIssues := 0
|
||||||
if err != nil {
|
for _, count := range commentCount {
|
||||||
expect.Fail("Step 2: Could not verify comments: " + err.Error())
|
if count > 0 {
|
||||||
} else {
|
commentsInIssues++
|
||||||
for _, count := range counts {
|
|
||||||
if count >= 1 {
|
|
||||||
issuesWithComments++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if issuesWithComments >= 2 {
|
|
||||||
expect.Pass(fmt.Sprintf("Step 2: Added comments to at least 2 issues (%d issues have comments)", issuesWithComments))
|
|
||||||
} else {
|
|
||||||
expect.Fail(fmt.Sprintf("Step 2: Add comments to at least 2 issues (found %d with comments)", issuesWithComments))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
expect.Fail("Step 2: Add comments to at least 2 issues (no issues to check)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Delete the cleanup task issue — we verify it's gone (Step 4 is same outcome; we can't verify they "looked")
|
expect.Equal(commentsInIssues, 2, "Comments on issues")
|
||||||
setupStillExists, _ := t.app.Issues.GetIssue(ctx, t.setupIssue.ID)
|
|
||||||
deletedCleanupIssue := setupStillExists == nil
|
|
||||||
|
|
||||||
if len(issues) == 5 && deletedCleanupIssue {
|
// Fetching the setup issue as as FetchIssues only updates the setup issue if it exists,
|
||||||
expect.Pass("Step 3: Deleted the cleanup task issue — it no longer appears in the list")
|
// we can check if it was deleted by seeing if it can be fetched again
|
||||||
} else if len(issues) < 5 {
|
if t.setupIssue, err = t.app.Issues.GetIssue(ctx, t.setupIssue.ID); t.setupIssue != nil {
|
||||||
expect.Fail(fmt.Sprintf("Step 3: Delete only the cleanup task issue — you deleted a project issue (expected 5, got %d)", len(issues)))
|
expect.Fail("Setup issue still exists")
|
||||||
} else if !deletedCleanupIssue {
|
} else {
|
||||||
expect.Fail("Step 3: Delete the cleanup task issue (\"Issue Review and Cleanup Task\") from the list")
|
expect.Pass("Setup issue deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
return expect.Complete()
|
return expect.Complete()
|
||||||
|
|||||||
@@ -90,9 +90,10 @@ func (e *Expector) Equal(val, expected any, message string) *Expector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Expector) Assert(condition bool, message string) *Expector {
|
func (e *Expector) Assert(condition bool, message string) *Expector {
|
||||||
check := NewCheck(message, condition)
|
if !condition {
|
||||||
e.Checks = append(e.Checks, check)
|
return e.Fail(message)
|
||||||
return e
|
}
|
||||||
|
return e.Pass(message + " is correct")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Expector) Nil(value any, message string) *Expector {
|
func (e *Expector) Nil(value any, message string) *Expector {
|
||||||
|
|||||||
Reference in New Issue
Block a user