Skip to content

Commit

Permalink
Merge pull request #22 from perebaj/fix_uplaod_response
Browse files Browse the repository at this point in the history
🐛 chore: improve upload return
  • Loading branch information
perebaj authored Sep 30, 2023
2 parents cf567c0 + 0cb971b commit b923d00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
20 changes: 16 additions & 4 deletions api/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ Request:
'http://<>:8080/upload' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=text/plain'
-H 'Cookie: jwt=<>' \
-F '[email protected];type=text/plain'
```

Response:

```JSON
{
"msg": "file uploaded successfully"
}
```

## `/balance/affiliate?name=<>`
Expand All @@ -34,7 +43,8 @@ Request:
```bash
curl -i -X 'GET' \
'http://<>:8080/balance/affiliate?name=<>' \
-H 'accept: application/json'
-H 'accept: application/json' \
-H 'Cookie: jwt=<>'
```

Response:
Expand Down Expand Up @@ -62,7 +72,8 @@ Request:
```bash
curl -i -X 'GET' \
'http://<>:8080/balance/producer?name=<>' \
-H 'accept: application/json'
-H 'accept: application/json' \
-H 'Cookie: jwt=<>'
```

Response:
Expand All @@ -83,7 +94,8 @@ Request:
```bash
curl -i -X 'GET' \
'http://<>:8080/transactions' \
-H 'accept: application/json'
-H 'accept: application/json' \
-H 'Cookie: jwt=<>'
```

Response:
Expand Down
4 changes: 3 additions & 1 deletion api/transactionhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ func (s transactionHandler) upload(w http.ResponseWriter, r *http.Request) {
return
}

send(w, http.StatusOK, nil)
send(w, http.StatusOK, struct {
Msg string `json:"msg"`
}{"file uploaded successfully"})
}

func (s transactionHandler) transactions(w http.ResponseWriter, r *http.Request) {
Expand Down
10 changes: 10 additions & 0 deletions api/transactionhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"bytes"
"context"
"encoding/json"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -64,6 +65,15 @@ func TestTransactionHandlerUpload(t *testing.T) {
if resp.Code != http.StatusOK {
t.Fatalf("expected status code %d, got %d", http.StatusOK, resp.Code)
}

var response struct {
Msg string `json:"msg"`
}
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
t.Fatalf("failed to decode response body: %v", err)
}
assert(t, response.Msg, "file uploaded successfully")

}

func TestTransactionHandlerUpload_Unauthorized(t *testing.T) {
Expand Down

0 comments on commit b923d00

Please sign in to comment.