Skip to content

Commit

Permalink
phone| feat: add sumIncomeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
varissara-techup committed May 19, 2024
1 parent 4670fe7 commit 3677ef4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/transaction/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ func (h handler) GetSummaryExpensesHandler(c echo.Context) error {
TotalNumberSpent: s.TotalNumber,
})
}

func (h handler) GetSummaryIncomeHandler(c echo.Context) error {
s := GetSummary(getTransection())

return c.JSON(http.StatusOK, SummaryIncome{
TotalAmountEarned: s.Total,
AvgAmountEarnedPerDay: s.Average,
TotalNumberEarned: s.TotalNumber,
})
}
25 changes: 25 additions & 0 deletions api/transaction/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ var mockSummaryExpesnse = SummaryExpenses{
TotalNumberSpent: 3,
}

var mockSummaryIncome = SummaryIncome{
TotalAmountEarned: 5000,
AvgAmountEarnedPerDay: 1666.67,
TotalNumberEarned: 3,
}

func TestGetSummaryExpenses(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/api/v1/expenses/summary", nil)
Expand All @@ -35,3 +41,22 @@ func TestGetSummaryExpenses(t *testing.T) {
assert.JSONEq(t, string(m), rec.Body.String())

}

func TestGetSummaryIncome(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/api/v1/expenses/summary", nil)
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)

cfg := config.FeatureFlag{EnableCreateSpender: true}

p := New(cfg, nil)
err := p.GetSummaryIncomeHandler(c)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
m, _ := json.Marshal(mockSummaryIncome)

assert.JSONEq(t, string(m), rec.Body.String())

}

0 comments on commit 3677ef4

Please sign in to comment.