Rename DeleteClientID to DeleteClientByID
This commit is contained in:
parent
b8b15040f9
commit
e44970e684
|
|
@ -51,8 +51,8 @@ func (_m *MockTokenDatabase) DeleteApplicationByID(id string) error {
|
||||||
return r0
|
return r0
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteClientID provides a mock function with given fields: id
|
// DeleteClientByID provides a mock function with given fields: id
|
||||||
func (_m *MockTokenDatabase) DeleteClientID(id string) error {
|
func (_m *MockTokenDatabase) DeleteClientByID(id string) error {
|
||||||
ret := _m.Called(id)
|
ret := _m.Called(id)
|
||||||
|
|
||||||
var r0 error
|
var r0 error
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ type TokenDatabase interface {
|
||||||
CreateClient(client *model.Client) error
|
CreateClient(client *model.Client) error
|
||||||
GetClientByID(id string) *model.Client
|
GetClientByID(id string) *model.Client
|
||||||
GetClientsByUser(userID uint) []*model.Client
|
GetClientsByUser(userID uint) []*model.Client
|
||||||
DeleteClientID(id string) error
|
DeleteClientByID(id string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// The TokenAPI provides handlers for managing clients and applications.
|
// The TokenAPI provides handlers for managing clients and applications.
|
||||||
|
|
@ -76,7 +76,7 @@ func (a *TokenAPI) DeleteApplication(ctx *gin.Context) {
|
||||||
func (a *TokenAPI) DeleteClient(ctx *gin.Context) {
|
func (a *TokenAPI) DeleteClient(ctx *gin.Context) {
|
||||||
clientID := ctx.Param("id")
|
clientID := ctx.Param("id")
|
||||||
if client := a.DB.GetClientByID(clientID); client != nil && client.UserID == auth.GetUserID(ctx) {
|
if client := a.DB.GetClientByID(clientID); client != nil && client.UserID == auth.GetUserID(ctx) {
|
||||||
a.DB.DeleteClientID(clientID)
|
a.DB.DeleteClientByID(clientID)
|
||||||
} else {
|
} else {
|
||||||
ctx.AbortWithError(404, fmt.Errorf("client with id %s doesn't exists", clientID))
|
ctx.AbortWithError(404, fmt.Errorf("client with id %s doesn't exists", clientID))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ func (s *TokenSuite) Test_DeleteClient_expectNotFoundOnCurrentUserIsNotOwner() {
|
||||||
|
|
||||||
s.a.DeleteClient(s.ctx)
|
s.a.DeleteClient(s.ctx)
|
||||||
|
|
||||||
s.db.AssertNotCalled(s.T(), "DeleteClientID", mock.Anything)
|
s.db.AssertNotCalled(s.T(), "DeleteClientByID", mock.Anything)
|
||||||
assert.Equal(s.T(), 404, s.recorder.Code)
|
assert.Equal(s.T(), 404, s.recorder.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,7 +268,7 @@ func (s *TokenSuite) Test_DeleteClient_expectNotFound() {
|
||||||
s.ctx.Request = httptest.NewRequest("DELETE", "/token/"+firstClientToken, nil)
|
s.ctx.Request = httptest.NewRequest("DELETE", "/token/"+firstClientToken, nil)
|
||||||
s.ctx.Params = gin.Params{{Key: "id", Value: firstClientToken}}
|
s.ctx.Params = gin.Params{{Key: "id", Value: firstClientToken}}
|
||||||
|
|
||||||
s.db.On("DeleteClientID", firstClientToken).Return(errors.New("what? that does not exist"))
|
s.db.On("DeleteClientByID", firstClientToken).Return(errors.New("what? that does not exist"))
|
||||||
s.db.On("GetClientByID", firstClientToken).Return(nil)
|
s.db.On("GetClientByID", firstClientToken).Return(nil)
|
||||||
|
|
||||||
s.a.DeleteClient(s.ctx)
|
s.a.DeleteClient(s.ctx)
|
||||||
|
|
@ -281,7 +281,7 @@ func (s *TokenSuite) Test_DeleteClient() {
|
||||||
s.ctx.Request = httptest.NewRequest("DELETE", "/token/"+firstClientToken, nil)
|
s.ctx.Request = httptest.NewRequest("DELETE", "/token/"+firstClientToken, nil)
|
||||||
s.ctx.Params = gin.Params{{Key: "id", Value: firstClientToken}}
|
s.ctx.Params = gin.Params{{Key: "id", Value: firstClientToken}}
|
||||||
|
|
||||||
s.db.On("DeleteClientID", firstClientToken).Return(nil)
|
s.db.On("DeleteClientByID", firstClientToken).Return(nil)
|
||||||
s.db.On("GetClientByID", firstClientToken).Return(&model.Client{ID: firstClientToken, Name: "custom_name", UserID: 5})
|
s.db.On("GetClientByID", firstClientToken).Return(&model.Client{ID: firstClientToken, Name: "custom_name", UserID: 5})
|
||||||
|
|
||||||
s.a.DeleteClient(s.ctx)
|
s.a.DeleteClient(s.ctx)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue