-
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.
- Loading branch information
1 parent
8ce9540
commit 207ea5e
Showing
4 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"ahbcc/cmd/api/user/session" | ||
"ahbcc/internal/log" | ||
) | ||
|
||
// LogOut Logs the user out. It deletes the current user session associated to that user by the token | ||
type LogOut func(ctx context.Context, token string) error | ||
|
||
// MakeLogOut creates a new LogOut | ||
func MakeLogOut(deleteUserSession session.Delete) LogOut { | ||
return func(ctx context.Context, token string) error { | ||
|
||
err := deleteUserSession(ctx, token) | ||
if err != nil { | ||
log.Error(ctx, err.Error()) | ||
return FailedToDeleteUserSession | ||
} | ||
|
||
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,33 @@ | ||
package auth_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"ahbcc/cmd/api/auth" | ||
"ahbcc/cmd/api/user/session" | ||
) | ||
|
||
func TestLogOut_success(t *testing.T) { | ||
mockDeleteUserSession := session.MockDelete(nil) | ||
|
||
logOut := auth.MakeLogOut(mockDeleteUserSession) | ||
|
||
got := logOut(context.Background(), "token") | ||
|
||
assert.Nil(t, got) | ||
} | ||
|
||
func TestLogOut_failsWhenDeleteSessionThrowsError(t *testing.T) { | ||
mockDeleteUserSession := session.MockDelete(errors.New("failed to delete session")) | ||
|
||
logOut := auth.MakeLogOut(mockDeleteUserSession) | ||
|
||
want := auth.FailedToDeleteUserSession | ||
got := logOut(context.Background(), "token") | ||
|
||
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