MSP-5186 Make application id required
This commit is contained in:
1 parent
9a1e8a7cd4
commit
1d4c81c425
3 files changed
+2
-44
No files matched your search
@@ -41,7 +41,7 @@ type ApplicationSimple struct {
|
||||
}
|
||||
|
||||
type CreateApplicationRequest struct {
|
||||
Id int
|
||||
Id int `validate:"required"`
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
ApplicationGroupId int `validate:"required"`
|
||||
|
||||
@@ -249,15 +249,7 @@ func (s Application) GetAll(ctx context.Context) ([]domain.Application, error) {
|
||||
}
|
||||
|
||||
func (s Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) {
|
||||
appId := req.Id
|
||||
var err error
|
||||
if appId == 0 {
|
||||
appId, err = s.appRepo.NextApplicationId(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "next application id")
|
||||
}
|
||||
}
|
||||
app, err := s.appRepo.CreateApplication(ctx, appId, req.Name, req.Description, req.ApplicationGroupId, req.Type)
|
||||
app, err := s.appRepo.CreateApplication(ctx, req.Id, req.Name, req.Description, req.ApplicationGroupId, req.Type)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "create application")
|
||||
}
|
||||
|
||||
@@ -97,40 +97,6 @@ func (s *ApplicationSuite) TestCreate_HappyPath() {
|
||||
s.Require().Empty(result.Tokens)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestCreate_WithEmptyAppId_HappyPath() {
|
||||
nextAppId, err := s.appRepo.NextApplicationId(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
result := domain.ApplicationWithTokens{}
|
||||
apiReq := fake.It[domain.CreateApplicationRequest]()
|
||||
apiReq.Type = domain.ApplicationMobileType
|
||||
appGroup := s.createAppGroup()
|
||||
apiReq.ApplicationGroupId = appGroup.Id
|
||||
apiReq.Id = 0
|
||||
|
||||
err = s.api.Invoke("system/application/create_application").
|
||||
JsonRequestBody(apiReq).
|
||||
JsonResponseBody(&result).
|
||||
Do(s.T().Context())
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NotEmpty(result.App.CreatedAt)
|
||||
result.App.CreatedAt = time.Time{}
|
||||
|
||||
s.Require().NotEmpty(result.App.UpdatedAt)
|
||||
result.App.UpdatedAt = time.Time{}
|
||||
|
||||
expectedApp := domain.Application{
|
||||
Id: nextAppId,
|
||||
Name: apiReq.Name,
|
||||
Description: apiReq.Description,
|
||||
Type: apiReq.Type,
|
||||
ServiceId: apiReq.ApplicationGroupId,
|
||||
}
|
||||
s.Require().Equal(expectedApp, result.App)
|
||||
s.Require().Empty(result.Tokens)
|
||||
}
|
||||
|
||||
func (s *ApplicationSuite) TestCreate_AppGroupNotFound() {
|
||||
apiReq := fake.It[domain.CreateApplicationRequest]()
|
||||
apiReq.Type = domain.ApplicationSystemType
|
||||
|
||||
Reference in new issue
Block a user