-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Added /criteria/init/v1 endpoint to initialize / enqueue the PENDI…
…NG or IN PROGRESS criteria
- Loading branch information
1 parent
2e3d82f
commit e90a715
Showing
9 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,31 @@ | ||
package criteria | ||
|
||
import ( | ||
"context" | ||
|
||
"ahbcc/internal/log" | ||
) | ||
|
||
// Init retrieves all the criteria in a 'PENDING' or 'IN PROGRESS' state and executes an enqueue of each one | ||
type Init func(ctx context.Context) error | ||
|
||
// MakeInit creates a new Init | ||
func MakeInit(selectExecutionsByStatuses SelectExecutionsByStatuses, enqueue Enqueue) Init { | ||
return func(ctx context.Context) error { | ||
executionsDAO, err := selectExecutionsByStatuses(ctx, []string{PendingStatus, InProgressStatus}) | ||
if err != nil { | ||
log.Error(ctx, err.Error()) | ||
return FailedToExecuteSelectExecutionsByStatuses | ||
} | ||
|
||
for _, execution := range executionsDAO { | ||
err = enqueue(ctx, execution.SearchCriteriaID, true) | ||
if err != nil { | ||
log.Error(ctx, err.Error()) | ||
return FailedToExecuteEnqueueCriteria | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains 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,48 @@ | ||
package criteria_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"ahbcc/cmd/api/search/criteria" | ||
) | ||
|
||
func TestInit_success(t *testing.T) { | ||
mockExecutionsDAO := criteria.MockExecutionsDAO() | ||
mockSelectExecutionsByStatuses := criteria.MockSelectExecutionsByStatuses(mockExecutionsDAO, nil) | ||
mockEnqueue := criteria.MockEnqueue(nil) | ||
|
||
init := criteria.MakeInit(mockSelectExecutionsByStatuses, mockEnqueue) | ||
|
||
got := init(context.Background()) | ||
|
||
assert.Nil(t, got) | ||
} | ||
|
||
func TestInit_failsWhenSelectExecutionsByStatusesThrowsError(t *testing.T) { | ||
mockSelectExecutionsByStatuses := criteria.MockSelectExecutionsByStatuses(nil, errors.New("failed while executing select executions by statuses")) | ||
mockEnqueue := criteria.MockEnqueue(nil) | ||
|
||
init := criteria.MakeInit(mockSelectExecutionsByStatuses, mockEnqueue) | ||
|
||
want := criteria.FailedToExecuteSelectExecutionsByStatuses | ||
got := init(context.Background()) | ||
|
||
assert.Equal(t, want, got) | ||
} | ||
|
||
func TestInit_failsWhenEnqueueThrowsError(t *testing.T) { | ||
mockExecutionsDAO := criteria.MockExecutionsDAO() | ||
mockSelectExecutionsByStatuses := criteria.MockSelectExecutionsByStatuses(mockExecutionsDAO, nil) | ||
mockEnqueue := criteria.MockEnqueue(errors.New("failed while executing enqueue")) | ||
|
||
init := criteria.MakeInit(mockSelectExecutionsByStatuses, mockEnqueue) | ||
|
||
want := criteria.FailedToExecuteEnqueueCriteria | ||
got := init(context.Background()) | ||
|
||
assert.Equal(t, want, got) | ||
} |
This file contains 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 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