fix tests

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-09-26 19:46:37 +03:00
parent 73be8c8a32
commit 96f18c2c8c
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
2 changed files with 11 additions and 7 deletions

View File

@ -29,7 +29,7 @@ func TestDefaultAccountManager_PostureCheck(t *testing.T) {
t.Run("Generic posture check flow", func(t *testing.T) {
// regular users can not create checks
err := am.SavePostureChecks(context.Background(), account.Id, regularUserID, &posture.Checks{})
err := am.SavePostureChecks(context.Background(), account.Id, regularUserID, &posture.Checks{}, false)
assert.Error(t, err)
// regular users cannot list check
@ -45,7 +45,7 @@ func TestDefaultAccountManager_PostureCheck(t *testing.T) {
MinVersion: "0.26.0",
},
},
})
}, false)
assert.NoError(t, err)
// admin users can list check
@ -66,7 +66,7 @@ func TestDefaultAccountManager_PostureCheck(t *testing.T) {
},
},
},
})
}, false)
assert.Error(t, err)
// admins can update posture checks
@ -78,7 +78,7 @@ func TestDefaultAccountManager_PostureCheck(t *testing.T) {
MinVersion: "0.27.0",
},
},
})
}, false)
assert.NoError(t, err)
// users should not be able to delete posture checks

View File

@ -1057,14 +1057,18 @@ func (s *SqlStore) GetAccountDNSSettings(ctx context.Context, lockStrength Locki
// AccountExists checks whether an account exists by the given ID.
func (s *SqlStore) AccountExists(ctx context.Context, lockStrength LockingStrength, id string) (bool, error) {
var count int64
var accountID string
result := s.db.WithContext(ctx).Clauses(clause.Locking{Strength: string(lockStrength)}).Model(&Account{}).
Where(idQueryCondition, id).Count(&count)
Select("id").First(&accountID, idQueryCondition, id)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return false, nil
}
return false, result.Error
}
return count > 0, nil
return accountID != "", nil
}
// GetAccountDomainAndCategory retrieves the Domain and DomainCategory fields for an account based on the given accountID.