backend: membership errorhandling tests

This commit is contained in:
Alex
2025-02-28 10:05:25 +01:00
parent 386b50e857
commit 20754b4422
4 changed files with 17 additions and 15 deletions

View File

@@ -33,11 +33,12 @@ func (service *MembershipService) UpdateSubscription(subscription *models.Subscr
existingSubscription, err := repositories.GetSubscriptionByName(&subscription.Name)
if err != nil {
if err.Error() == "record not found" {
return nil, errors.ErrSubscriptionNotFound
}
return nil, err
}
if existingSubscription == nil {
return nil, errors.ErrSubscriptionNotFound
}
if existingSubscription.MonthlyFee != subscription.MonthlyFee ||
existingSubscription.HourlyRate != subscription.HourlyRate ||
existingSubscription.Conditions != subscription.Conditions ||
@@ -56,11 +57,12 @@ func (service *MembershipService) DeleteSubscription(id *uint, name *string) err
}
exists, err := repositories.GetSubscriptionByName(name)
if err != nil {
if err.Error() == "record not found" {
return errors.ErrSubscriptionNotFound
}
return err
}
if exists == nil {
return errors.ErrNotFound
}
if *id != exists.ID {
return errors.ErrInvalidSubscriptionData
}