Skip to content

Commit

Permalink
- fix erreur GetActivityFromId
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Ninucci committed Nov 12, 2023
1 parent d186dcf commit 01f51bd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package libwekan

import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"time"

Expand Down Expand Up @@ -215,6 +216,9 @@ func (wekan *Wekan) GetActivityFromID(ctx context.Context, activityID ActivityID
var activity Activity
err := wekan.db.Collection("activities").FindOne(ctx, bson.M{"_id": activityID}).Decode(&activity)
if err != nil {
if err == mongo.ErrNoDocuments {
return Activity{}, ActivityNotFoundError{string(activityID)}
}
return Activity{}, UnexpectedMongoError{err}
}
return activity, nil
Expand Down
6 changes: 3 additions & 3 deletions activities_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func TestActivities_GetActivityFromID_WhenActivityDoesntExist(t *testing.T) {
// THEN
ass.Empty(actualActivityFromMethod)
ass.Empty(actualActivityFromID)
ass.IsType(UnknownActivityError{}, errFromMethod)
ass.IsType(UnknownActivityError{}, errFromID)
ass.IsType(ActivityNotFoundError{}, errFromMethod)
ass.IsType(ActivityNotFoundError{}, errFromID)
}

func TestActivities_CheckActivityFromID(t *testing.T) {
Expand All @@ -128,5 +128,5 @@ func TestActivities_CheckActivityFromID_WhenActivityDoesntExist(t *testing.T) {
activityID := ActivityID(t.Name() + "absent")

// THEN
ass.IsType(UnknownActivityError{}, activityID.Check(ctx, &wekan))
ass.IsType(ActivityNotFoundError{}, activityID.Check(ctx, &wekan))
}
4 changes: 2 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ func (e NothingDoneError) Error() string {
return "le traitement n'a eu aucun effet"
}

type UnknownActivityError struct {
type ActivityNotFoundError struct {
key string
}

func (e UnknownActivityError) Error() string {
func (e ActivityNotFoundError) Error() string {
return fmt.Sprintf("l'activité n'existe pas (ID: %s)", e.key)
}

Expand Down
2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestErrors_NothingDoneError(t *testing.T) {
assert.EqualError(t, e, expected)
}
func TestErrors_UnknownActivityError(t *testing.T) {
e := UnknownActivityError{"test"}
e := ActivityNotFoundError{"test"}
expected := fmt.Sprintf("l'activité n'existe pas (ID: %s)", e.key)
assert.EqualError(t, e, expected)
}
Expand Down

0 comments on commit 01f51bd

Please sign in to comment.