Skip to content

Commit

Permalink
[statistics] fix: include canceled payment status (#81)
Browse files Browse the repository at this point in the history
What
Include CANCELED payment status to statistics

Why
Sentry alerts: status CANCELED is not a valid payment status
  • Loading branch information
ceciliaromao authored Oct 31, 2023
1 parent ac8785e commit ef50974
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
6 changes: 6 additions & 0 deletions internal/serve/httphandler/statistics_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestStatisticsHandler(t *testing.T) {

wantJson := `{
"payment_counters": {
"canceled": 0,
"draft": 0,
"ready": 0,
"pending": 0,
Expand Down Expand Up @@ -110,6 +111,7 @@ func TestStatisticsHandler(t *testing.T) {

wantJson := `{
"payment_counters": {
"canceled": 0,
"draft": 0,
"ready": 0,
"pending": 0,
Expand Down Expand Up @@ -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,
Expand All @@ -172,6 +175,7 @@ func TestStatisticsHandler(t *testing.T) {
{
"asset_code": "USDC",
"payment_amounts": {
"canceled": "",
"draft": "10.0000000",
"ready": "",
"pending": "",
Expand Down Expand Up @@ -208,6 +212,7 @@ func TestStatisticsHandler(t *testing.T) {

wantJson := `{
"payment_counters": {
"canceled": 0,
"draft": 1,
"ready": 0,
"pending": 0,
Expand All @@ -220,6 +225,7 @@ func TestStatisticsHandler(t *testing.T) {
{
"asset_code": "USDC",
"payment_amounts": {
"canceled": "",
"draft": "10.0000000",
"ready": "",
"pending": "",
Expand Down
36 changes: 21 additions & 15 deletions internal/statistics/calculate_statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/statistics/calculate_statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -180,6 +181,7 @@ func TestCalculateStatistics(t *testing.T) {
require.NoError(t, errJson)

wantJsonCounter := `{
"canceled":0,
"draft": 2,
"ready": 0,
"pending": 0,
Expand All @@ -198,6 +200,7 @@ func TestCalculateStatistics(t *testing.T) {
{
"asset_code": "USDC",
"payment_amounts": {
"canceled": "",
"draft": "20.0000000",
"ready": "",
"pending": "",
Expand Down Expand Up @@ -249,6 +252,7 @@ func TestCalculateStatistics(t *testing.T) {
require.NoError(t, err)

wantJsonCounter := `{
"canceled": 0,
"draft": 2,
"ready": 0,
"pending": 0,
Expand All @@ -267,6 +271,7 @@ func TestCalculateStatistics(t *testing.T) {
{
"asset_code": "EURT",
"payment_amounts": {
"canceled": "",
"draft": "",
"ready": "",
"pending": "",
Expand All @@ -280,6 +285,7 @@ func TestCalculateStatistics(t *testing.T) {
{
"asset_code": "USDC",
"payment_amounts": {
"canceled":"",
"draft": "20.0000000",
"ready": "",
"pending": "",
Expand All @@ -306,6 +312,7 @@ func TestCalculateStatistics(t *testing.T) {
require.NoError(t, err)

wantJsonCounter := `{
"canceled":0,
"draft": 0,
"ready": 0,
"pending": 0,
Expand All @@ -324,6 +331,7 @@ func TestCalculateStatistics(t *testing.T) {
{
"asset_code": "EURT",
"payment_amounts": {
"canceled":"",
"draft": "",
"ready": "",
"pending": "",
Expand Down

0 comments on commit ef50974

Please sign in to comment.