fix: test case

This commit is contained in:
王性驊 2025-02-08 10:06:43 +08:00
parent 040cc16b8e
commit 59525d8a05
3 changed files with 17 additions and 12 deletions

View File

@ -14,6 +14,7 @@ import (
reflect "reflect"
entity "code.30cm.net/digimon/app-cloudep-member-server/pkg/domain/entity"
member "code.30cm.net/digimon/app-cloudep-member-server/pkg/domain/member"
mongo "go.mongodb.org/mongo-driver/mongo"
gomock "go.uber.org/mock/gomock"
)
@ -132,17 +133,17 @@ func (mr *MockAccountRepositoryMockRecorder) Update(ctx, data any) *gomock.Call
}
// UpdateTokenByLoginID mocks base method.
func (m *MockAccountRepository) UpdateTokenByLoginID(ctx context.Context, account, token string) error {
func (m *MockAccountRepository) UpdateTokenByLoginID(ctx context.Context, account, token string, platform member.Platform) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UpdateTokenByLoginID", ctx, account, token)
ret := m.ctrl.Call(m, "UpdateTokenByLoginID", ctx, account, token, platform)
ret0, _ := ret[0].(error)
return ret0
}
// UpdateTokenByLoginID indicates an expected call of UpdateTokenByLoginID.
func (mr *MockAccountRepositoryMockRecorder) UpdateTokenByLoginID(ctx, account, token any) *gomock.Call {
func (mr *MockAccountRepositoryMockRecorder) UpdateTokenByLoginID(ctx, account, token, platform any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateTokenByLoginID", reflect.TypeOf((*MockAccountRepository)(nil).UpdateTokenByLoginID), ctx, account, token)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateTokenByLoginID", reflect.TypeOf((*MockAccountRepository)(nil).UpdateTokenByLoginID), ctx, account, token, platform)
}
// MockAccountIndexUP is a mock of AccountIndexUP interface.

View File

@ -1,6 +1,7 @@
package repository
import (
"code.30cm.net/digimon/app-cloudep-member-server/pkg/domain/member"
"context"
"errors"
"fmt"
@ -313,6 +314,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
name string
loginID string
newToken string
platform int64
expectedErr error
expectFound bool
}{
@ -320,6 +322,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
name: "Valid Update Token",
loginID: "testuser2",
newToken: "newtoken123",
platform: 1,
expectedErr: nil,
expectFound: true,
},
@ -327,6 +330,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
name: "Account Not Found for Update",
loginID: "nonexistentuser",
newToken: "newtoken456",
platform: 1,
expectedErr: ErrNotFound,
expectFound: false,
},
@ -334,7 +338,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := repo.UpdateTokenByLoginID(context.Background(), tt.loginID, tt.newToken)
err := repo.UpdateTokenByLoginID(context.Background(), tt.loginID, tt.newToken, member.Platform(tt.platform))
if tt.expectFound {
assert.NoError(t, err)

View File

@ -414,17 +414,17 @@ func TestUpdateUserToken(t *testing.T) {
}{
{
name: "Successful token update",
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "newPassword"},
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "newPassword", Platform: 1},
mockSetup: func() {
mockAccountRepo.EXPECT().
UpdateTokenByLoginID(gomock.Any(), "testAccount", "encrypted-password").
UpdateTokenByLoginID(gomock.Any(), "testAccount", "encrypted-password", gomock.Any()).
Return(nil)
},
wantErr: false,
},
{
name: "Password encryption failure",
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "fail"},
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "fail", Platform: 1},
mockSetup: func() {
// No repo call expected
},
@ -432,20 +432,20 @@ func TestUpdateUserToken(t *testing.T) {
},
{
name: "Account not found",
req: usecase.UpdateTokenRequest{Account: "nonExistentAccount", Token: "newPassword"},
req: usecase.UpdateTokenRequest{Account: "nonExistentAccount", Token: "newPassword", Platform: 1},
mockSetup: func() {
mockAccountRepo.EXPECT().
UpdateTokenByLoginID(gomock.Any(), "nonExistentAccount", "encrypted-password").
UpdateTokenByLoginID(gomock.Any(), "nonExistentAccount", "encrypted-password", gomock.Any()).
Return(mon.ErrNotFound)
},
wantErr: true,
},
{
name: "Database error during token update",
req: usecase.UpdateTokenRequest{Account: "errorAccount", Token: "newPassword"},
req: usecase.UpdateTokenRequest{Account: "errorAccount", Token: "newPassword", Platform: 1},
mockSetup: func() {
mockAccountRepo.EXPECT().
UpdateTokenByLoginID(gomock.Any(), "errorAccount", "encrypted-password").
UpdateTokenByLoginID(gomock.Any(), "errorAccount", "encrypted-password", gomock.Any()).
Return(errors.New("database error"))
},
wantErr: true,