diff --git a/api/docs/api.md b/api/docs/api.md index d826ffb..ac7a7c1 100644 --- a/api/docs/api.md +++ b/api/docs/api.md @@ -15,7 +15,16 @@ Request: 'http://<>:8080/upload' \ -H 'accept: application/json' \ -H 'Content-Type: multipart/form-data' \ - -F 'file=@sales.txt;type=text/plain' + -H 'Cookie: jwt=<>' \ + -F 'file=@sales.txt;type=text/plain' +``` + +Response: + +```JSON +{ + "msg": "file uploaded successfully" +} ``` ## `/balance/affiliate?name=<>` @@ -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: @@ -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: @@ -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: diff --git a/api/transactionhandler.go b/api/transactionhandler.go index 87d534e..77ef8be 100644 --- a/api/transactionhandler.go +++ b/api/transactionhandler.go @@ -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) { diff --git a/api/transactionhandler_test.go b/api/transactionhandler_test.go index 51c2f98..5a43d53 100644 --- a/api/transactionhandler_test.go +++ b/api/transactionhandler_test.go @@ -3,6 +3,7 @@ package api import ( "bytes" "context" + "encoding/json" "io" "mime/multipart" "net/http" @@ -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) {