From ef509743b5f6f24107a3119bdda1a5c32e259f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cec=C3=ADlia=20Rom=C3=A3o?= Date: Tue, 31 Oct 2023 12:29:30 -0300 Subject: [PATCH] [statistics] fix: include canceled payment status (#81) What Include CANCELED payment status to statistics Why Sentry alerts: status CANCELED is not a valid payment status --- .../httphandler/statistics_handler_test.go | 6 ++++ internal/statistics/calculate_statistics.go | 36 +++++++++++-------- .../statistics/calculate_statistics_test.go | 8 +++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/internal/serve/httphandler/statistics_handler_test.go b/internal/serve/httphandler/statistics_handler_test.go index 597d3792e..86c1b5fa1 100644 --- a/internal/serve/httphandler/statistics_handler_test.go +++ b/internal/serve/httphandler/statistics_handler_test.go @@ -42,6 +42,7 @@ func TestStatisticsHandler(t *testing.T) { wantJson := `{ "payment_counters": { + "canceled": 0, "draft": 0, "ready": 0, "pending": 0, @@ -110,6 +111,7 @@ func TestStatisticsHandler(t *testing.T) { wantJson := `{ "payment_counters": { + "canceled": 0, "draft": 0, "ready": 0, "pending": 0, @@ -160,6 +162,7 @@ func TestStatisticsHandler(t *testing.T) { assert.Equal(t, http.StatusOK, rr.Code) wantJson := `{ "payment_counters": { + "canceled": 0, "draft": 1, "ready": 0, "pending": 0, @@ -172,6 +175,7 @@ func TestStatisticsHandler(t *testing.T) { { "asset_code": "USDC", "payment_amounts": { + "canceled": "", "draft": "10.0000000", "ready": "", "pending": "", @@ -208,6 +212,7 @@ func TestStatisticsHandler(t *testing.T) { wantJson := `{ "payment_counters": { + "canceled": 0, "draft": 1, "ready": 0, "pending": 0, @@ -220,6 +225,7 @@ func TestStatisticsHandler(t *testing.T) { { "asset_code": "USDC", "payment_amounts": { + "canceled": "", "draft": "10.0000000", "ready": "", "pending": "", diff --git a/internal/statistics/calculate_statistics.go b/internal/statistics/calculate_statistics.go index f06603f34..2e84a6a84 100644 --- a/internal/statistics/calculate_statistics.go +++ b/internal/statistics/calculate_statistics.go @@ -15,24 +15,26 @@ import ( var ErrResourcesNotFound = errors.New("resources not found") type PaymentCounters struct { - Draft int64 `json:"draft"` - Ready int64 `json:"ready"` - Pending int64 `json:"pending"` - Paused int64 `json:"paused"` - Success int64 `json:"success"` - Failed int64 `json:"failed"` - Total int64 `json:"total"` + Draft int64 `json:"draft"` + Ready int64 `json:"ready"` + Pending int64 `json:"pending"` + Paused int64 `json:"paused"` + Success int64 `json:"success"` + Failed int64 `json:"failed"` + Canceled int64 `json:"canceled"` + Total int64 `json:"total"` } type PaymentAmounts struct { - Draft string `json:"draft"` - Ready string `json:"ready"` - Pending string `json:"pending"` - Paused string `json:"paused"` - Success string `json:"success"` - Failed string `json:"failed"` - Average string `json:"average"` - Total string `json:"total"` + Draft string `json:"draft"` + Ready string `json:"ready"` + Pending string `json:"pending"` + Paused string `json:"paused"` + Success string `json:"success"` + Failed string `json:"failed"` + Canceled string `json:"canceled"` + Average string `json:"average"` + Total string `json:"total"` } type PaymentAmountsByAsset struct { @@ -151,6 +153,10 @@ func getPaymentsStats(ctx context.Context, sqlExec db.SQLExecuter, disbursementI case data.PausedPaymentStatus: paymentCounters.Paused += count paymentAmounts.Paused = amount + + case data.CanceledPaymentStatus: + paymentCounters.Canceled += count + paymentAmounts.Canceled = amount default: return nil, nil, fmt.Errorf("status %v is not a valid payment status", status) } diff --git a/internal/statistics/calculate_statistics_test.go b/internal/statistics/calculate_statistics_test.go index cca1ee486..36406dbfa 100644 --- a/internal/statistics/calculate_statistics_test.go +++ b/internal/statistics/calculate_statistics_test.go @@ -32,6 +32,7 @@ func TestCalculateStatistics_emptyDatabase(t *testing.T) { gotJsonCounter, errJson := json.Marshal(paymentsCounter) require.NoError(t, errJson) wantJsonCounter := `{ + "canceled":0, "draft": 0, "ready": 0, "pending": 0, @@ -180,6 +181,7 @@ func TestCalculateStatistics(t *testing.T) { require.NoError(t, errJson) wantJsonCounter := `{ + "canceled":0, "draft": 2, "ready": 0, "pending": 0, @@ -198,6 +200,7 @@ func TestCalculateStatistics(t *testing.T) { { "asset_code": "USDC", "payment_amounts": { + "canceled": "", "draft": "20.0000000", "ready": "", "pending": "", @@ -249,6 +252,7 @@ func TestCalculateStatistics(t *testing.T) { require.NoError(t, err) wantJsonCounter := `{ + "canceled": 0, "draft": 2, "ready": 0, "pending": 0, @@ -267,6 +271,7 @@ func TestCalculateStatistics(t *testing.T) { { "asset_code": "EURT", "payment_amounts": { + "canceled": "", "draft": "", "ready": "", "pending": "", @@ -280,6 +285,7 @@ func TestCalculateStatistics(t *testing.T) { { "asset_code": "USDC", "payment_amounts": { + "canceled":"", "draft": "20.0000000", "ready": "", "pending": "", @@ -306,6 +312,7 @@ func TestCalculateStatistics(t *testing.T) { require.NoError(t, err) wantJsonCounter := `{ + "canceled":0, "draft": 0, "ready": 0, "pending": 0, @@ -324,6 +331,7 @@ func TestCalculateStatistics(t *testing.T) { { "asset_code": "EURT", "payment_amounts": { + "canceled":"", "draft": "", "ready": "", "pending": "",