fix: test case
This commit is contained in:
parent
040cc16b8e
commit
59525d8a05
|
@ -14,6 +14,7 @@ import (
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
entity "code.30cm.net/digimon/app-cloudep-member-server/pkg/domain/entity"
|
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"
|
mongo "go.mongodb.org/mongo-driver/mongo"
|
||||||
gomock "go.uber.org/mock/gomock"
|
gomock "go.uber.org/mock/gomock"
|
||||||
)
|
)
|
||||||
|
@ -132,17 +133,17 @@ func (mr *MockAccountRepositoryMockRecorder) Update(ctx, data any) *gomock.Call
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTokenByLoginID mocks base method.
|
// 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()
|
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)
|
ret0, _ := ret[0].(error)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTokenByLoginID indicates an expected call of UpdateTokenByLoginID.
|
// 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()
|
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.
|
// MockAccountIndexUP is a mock of AccountIndexUP interface.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.30cm.net/digimon/app-cloudep-member-server/pkg/domain/member"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -313,6 +314,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
loginID string
|
loginID string
|
||||||
newToken string
|
newToken string
|
||||||
|
platform int64
|
||||||
expectedErr error
|
expectedErr error
|
||||||
expectFound bool
|
expectFound bool
|
||||||
}{
|
}{
|
||||||
|
@ -320,6 +322,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
|
||||||
name: "Valid Update Token",
|
name: "Valid Update Token",
|
||||||
loginID: "testuser2",
|
loginID: "testuser2",
|
||||||
newToken: "newtoken123",
|
newToken: "newtoken123",
|
||||||
|
platform: 1,
|
||||||
expectedErr: nil,
|
expectedErr: nil,
|
||||||
expectFound: true,
|
expectFound: true,
|
||||||
},
|
},
|
||||||
|
@ -327,6 +330,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
|
||||||
name: "Account Not Found for Update",
|
name: "Account Not Found for Update",
|
||||||
loginID: "nonexistentuser",
|
loginID: "nonexistentuser",
|
||||||
newToken: "newtoken456",
|
newToken: "newtoken456",
|
||||||
|
platform: 1,
|
||||||
expectedErr: ErrNotFound,
|
expectedErr: ErrNotFound,
|
||||||
expectFound: false,
|
expectFound: false,
|
||||||
},
|
},
|
||||||
|
@ -334,7 +338,7 @@ func TestAccountModel_UpdateTokenByLoginID(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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 {
|
if tt.expectFound {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -414,17 +414,17 @@ func TestUpdateUserToken(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Successful token update",
|
name: "Successful token update",
|
||||||
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "newPassword"},
|
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "newPassword", Platform: 1},
|
||||||
mockSetup: func() {
|
mockSetup: func() {
|
||||||
mockAccountRepo.EXPECT().
|
mockAccountRepo.EXPECT().
|
||||||
UpdateTokenByLoginID(gomock.Any(), "testAccount", "encrypted-password").
|
UpdateTokenByLoginID(gomock.Any(), "testAccount", "encrypted-password", gomock.Any()).
|
||||||
Return(nil)
|
Return(nil)
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Password encryption failure",
|
name: "Password encryption failure",
|
||||||
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "fail"},
|
req: usecase.UpdateTokenRequest{Account: "testAccount", Token: "fail", Platform: 1},
|
||||||
mockSetup: func() {
|
mockSetup: func() {
|
||||||
// No repo call expected
|
// No repo call expected
|
||||||
},
|
},
|
||||||
|
@ -432,20 +432,20 @@ func TestUpdateUserToken(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Account not found",
|
name: "Account not found",
|
||||||
req: usecase.UpdateTokenRequest{Account: "nonExistentAccount", Token: "newPassword"},
|
req: usecase.UpdateTokenRequest{Account: "nonExistentAccount", Token: "newPassword", Platform: 1},
|
||||||
mockSetup: func() {
|
mockSetup: func() {
|
||||||
mockAccountRepo.EXPECT().
|
mockAccountRepo.EXPECT().
|
||||||
UpdateTokenByLoginID(gomock.Any(), "nonExistentAccount", "encrypted-password").
|
UpdateTokenByLoginID(gomock.Any(), "nonExistentAccount", "encrypted-password", gomock.Any()).
|
||||||
Return(mon.ErrNotFound)
|
Return(mon.ErrNotFound)
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Database error during token update",
|
name: "Database error during token update",
|
||||||
req: usecase.UpdateTokenRequest{Account: "errorAccount", Token: "newPassword"},
|
req: usecase.UpdateTokenRequest{Account: "errorAccount", Token: "newPassword", Platform: 1},
|
||||||
mockSetup: func() {
|
mockSetup: func() {
|
||||||
mockAccountRepo.EXPECT().
|
mockAccountRepo.EXPECT().
|
||||||
UpdateTokenByLoginID(gomock.Any(), "errorAccount", "encrypted-password").
|
UpdateTokenByLoginID(gomock.Any(), "errorAccount", "encrypted-password", gomock.Any()).
|
||||||
Return(errors.New("database error"))
|
Return(errors.New("database error"))
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
|
Loading…
Reference in New Issue