@@ -4,18 +4,13 @@ import (
44 "context"
55 "net/http"
66 "testing"
7- "time"
87
98 "github.com/go-shiori/shiori/internal/model"
109 "github.com/go-shiori/shiori/internal/testutil"
1110 "github.com/sirupsen/logrus"
1211 "github.com/stretchr/testify/require"
1312)
1413
15- func noopLegacyLoginHandler (_ * model.AccountDTO , _ time.Duration ) (string , error ) {
16- return "test-session" , nil
17- }
18-
1914func TestHandleLogin (t * testing.T ) {
2015 logger := logrus .New ()
2116 // _, deps := testutil.GetTestConfigurationAndDependencies(t, context.Background(), logger)
@@ -24,39 +19,31 @@ func TestHandleLogin(t *testing.T) {
2419 ctx := context .Background ()
2520 _ , deps := testutil .GetTestConfigurationAndDependencies (t , ctx , logger )
2621 body := `{"username":}`
27- w := testutil .PerformRequest (deps , func (deps model.Dependencies , c model.WebContext ) {
28- HandleLogin (deps , c , noopLegacyLoginHandler )
29- }, "POST" , "/login" , testutil .WithBody (body ))
22+ w := testutil .PerformRequest (deps , HandleLogin , "POST" , "/login" , testutil .WithBody (body ))
3023 require .Equal (t , http .StatusBadRequest , w .Code )
3124 })
3225
3326 t .Run ("missing username" , func (t * testing.T ) {
3427 ctx := context .Background ()
3528 _ , deps := testutil .GetTestConfigurationAndDependencies (t , ctx , logger )
3629 body := `{"password": "test"}`
37- w := testutil .PerformRequest (deps , func (deps model.Dependencies , c model.WebContext ) {
38- HandleLogin (deps , c , noopLegacyLoginHandler )
39- }, "POST" , "/login" , testutil .WithBody (body ))
30+ w := testutil .PerformRequest (deps , HandleLogin , "POST" , "/login" , testutil .WithBody (body ))
4031 require .Equal (t , http .StatusBadRequest , w .Code )
4132 })
4233
4334 t .Run ("missing password" , func (t * testing.T ) {
4435 ctx := context .Background ()
4536 _ , deps := testutil .GetTestConfigurationAndDependencies (t , ctx , logger )
4637 body := `{"username": "test"}`
47- w := testutil .PerformRequest (deps , func (deps model.Dependencies , c model.WebContext ) {
48- HandleLogin (deps , c , noopLegacyLoginHandler )
49- }, "POST" , "/login" , testutil .WithBody (body ))
38+ w := testutil .PerformRequest (deps , HandleLogin , "POST" , "/login" , testutil .WithBody (body ))
5039 require .Equal (t , http .StatusBadRequest , w .Code )
5140 })
5241
5342 t .Run ("invalid credentials" , func (t * testing.T ) {
5443 ctx := context .Background ()
5544 _ , deps := testutil .GetTestConfigurationAndDependencies (t , ctx , logger )
5645 body := `{"username": "test", "password": "wrong"}`
57- w := testutil .PerformRequest (deps , func (deps model.Dependencies , c model.WebContext ) {
58- HandleLogin (deps , c , noopLegacyLoginHandler )
59- }, "POST" , "/login" , testutil .WithBody (body ))
46+ w := testutil .PerformRequest (deps , HandleLogin , "POST" , "/login" , testutil .WithBody (body ))
6047 require .Equal (t , http .StatusBadRequest , w .Code )
6148 })
6249
@@ -74,16 +61,13 @@ func TestHandleLogin(t *testing.T) {
7461 "password": "test",
7562 "remember_me": true
7663 }`
77- w := testutil .PerformRequest (deps , func (deps model.Dependencies , c model.WebContext ) {
78- HandleLogin (deps , c , noopLegacyLoginHandler )
79- }, "POST" , "/login" , testutil .WithBody (body ))
64+ w := testutil .PerformRequest (deps , HandleLogin , "POST" , "/login" , testutil .WithBody (body ))
8065 require .Equal (t , http .StatusOK , w .Code )
8166
8267 response , err := testutil .NewTestResponseFromReader (w .Body )
8368 require .NoError (t , err )
8469 response .AssertOk (t )
8570 response .AssertMessageContains (t , "token" )
86- response .AssertMessageContains (t , "session" )
8771 response .AssertMessageContains (t , "expires" )
8872 })
8973}
0 commit comments