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

@@ -132,7 +132,7 @@ func (mc *MembershipController) DeleteSubscription(c *gin.Context) {
if err := mc.Service.DeleteSubscription(&data.Subscription.ID, &data.Subscription.Name); err != nil {
if err == errors.ErrNoData {
utils.RespondWithError(c, err, "Missing subscription name during deletion", http.StatusExpectationFailed, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.Invalid)
} else if err == errors.ErrNotFound {
} else if err == errors.ErrSubscriptionNotFound {
utils.RespondWithError(c, err, "Subscription not found", http.StatusNotFound, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.NotFound)
} else if err == errors.ErrInvalidSubscriptionData {
utils.RespondWithError(c, err, "Invalid subscription data", http.StatusBadRequest, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.Invalid)

View File

@@ -251,7 +251,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
return []UpdateSubscriptionTest{
{
Name: "Modified Monthly Fee, should fail",
WantResponse: http.StatusNotAcceptable,
WantResponse: http.StatusBadRequest,
WantDBData: map[string]interface{}{"name": "Premium", "monthly_fee": "12"},
Assert: true,
Input: GenerateInputJSON(
@@ -262,7 +262,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
},
{
Name: "Missing ID, should fail",
WantResponse: http.StatusNotAcceptable,
WantResponse: http.StatusBadRequest,
WantDBData: map[string]interface{}{"name": "Premium"},
Assert: true,
Input: GenerateInputJSON(
@@ -273,7 +273,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
},
{
Name: "Modified Hourly Rate, should fail",
WantResponse: http.StatusNotAcceptable,
WantResponse: http.StatusBadRequest,
WantDBData: map[string]interface{}{"name": "Premium", "hourly_rate": "14"},
Assert: true,
Input: GenerateInputJSON(
@@ -284,7 +284,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
},
{
Name: "IncludedPerYear changed, should fail",
WantResponse: http.StatusNotAcceptable,
WantResponse: http.StatusBadRequest,
WantDBData: map[string]interface{}{"name": "Premium", "included_per_year": "0"},
Assert: true,
Input: GenerateInputJSON(
@@ -295,7 +295,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
},
{
Name: "IncludedPerMonth changed, should fail",
WantResponse: http.StatusNotAcceptable,
WantResponse: http.StatusBadRequest,
WantDBData: map[string]interface{}{"name": "Premium", "included_per_month": "1"},
Assert: true,
Input: GenerateInputJSON(
@@ -306,7 +306,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
},
{
Name: "Update non-existent subscription should fail",
WantResponse: http.StatusNotAcceptable,
WantResponse: http.StatusNotFound,
WantDBData: map[string]interface{}{"name": "NonExistentSubscription"},
Assert: false,
Input: GenerateInputJSON(
@@ -343,7 +343,7 @@ func getSubscriptionDeleteData() []DeleteSubscriptionTest {
return []DeleteSubscriptionTest{
{
Name: "Delete non-existent subscription should fail",
WantResponse: http.StatusExpectationFailed,
WantResponse: http.StatusNotFound,
WantDBData: map[string]interface{}{"name": "NonExistentSubscription"},
Assert: false,
Input: GenerateInputJSON(