Commit 908d0d70 authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

TestOpenShare

parent b5a8e689
......@@ -152,7 +152,7 @@ func OpenShare(w http.ResponseWriter, r *http.Request) *HTTPError {
var newShare Share
err = json.Unmarshal(reqBody, &newShare)
if err != nil {
return &HTTPError{err, "Can't parse data", 500}
return &HTTPError{err, "Can't parse body", 400}
}
// create temporary db entries
......
......@@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
......@@ -9,6 +10,7 @@ import (
"log"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
......@@ -131,27 +133,45 @@ func TestGetShare(t *testing.T) {
}
func TestDownloadFile(t *testing.T) {
Reset()
router := mux.NewRouter()
ts := httptest.NewServer(router)
router.Handle("/share/{id}", endpointREST(GetShare)).Methods("GET")
defer ts.Close()
t.Run("happy path", func(t *testing.T) {
})
}
//func TestOpenShare(t *testing.T) {
// t.Run("happy path", func(t *testing.T) {
// b, _ := json.Marshal(Share {
// ID: uuid.MustParse("e5134044-2704-4864-85be-318fb158009f"),
// Name: "TopKek",
// })
// read := strings.NewReader(string(b))
// res := DoRequest(t, "POST", "http://localhost:6969/shares", read, OpenShare, nil)
// assert.Equal(t, http.StatusCreated, res.Code)
// })
//
// t.Run("bad request", func(t *testing.T) {
// res := DoRequest(t, "POST", "http://localhost:6969/shares", nil, OpenShare, nil)
// assert.Equal(t, http.StatusBadRequest, res.Code)
// })
//}
func TestOpenShare(t *testing.T) {
Reset()
router := mux.NewRouter()
ts := httptest.NewServer(router)
router.Handle("/shares", endpointREST(OpenShare)).Methods("POST")
defer ts.Close()
t.Run("happy path", func(t *testing.T) {
b, _ := json.Marshal(Share {
ID: uuid.MustParse("e5134044-2704-4864-85be-318fb158009f"),
Name: "TopKek",
})
req, _ := http.NewRequest("POST", ts.URL + "/shares", strings.NewReader(string(b)))
res, _ := http.DefaultClient.Do(req)
//body, _ := ioutil.ReadAll(res.Body)
assert.Equal(t, http.StatusOK, res.StatusCode)
})
t.Run("bad request", func(t *testing.T) {
req, _ := http.NewRequest("POST", ts.URL + "/shares", nil)
res, _ := http.DefaultClient.Do(req)
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
})
}
func TestCloseShare(t *testing.T) {
t.Run("happy path", func(t *testing.T) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment