wallet-sync-server/server/register_test.go

46 lines
1.1 KiB
Go
Raw Normal View History

package server
import (
2022-06-17 21:39:12 +02:00
"bytes"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
2022-06-17 21:39:12 +02:00
"orblivion/lbry-id/auth"
)
func TestServerRegisterSuccess(t *testing.T) {
2022-06-17 21:39:12 +02:00
testAuth := TestAuth{TestToken: auth.TokenString("seekrit")}
testStore := TestStore{}
s := Server{&testAuth, &testStore}
requestBody := []byte(`{"email": "abc@example.com", "password": "123"}`)
req := httptest.NewRequest(http.MethodPost, PathRegister, bytes.NewBuffer(requestBody))
w := httptest.NewRecorder()
s.register(w, req)
body, _ := ioutil.ReadAll(w.Body)
if want, got := http.StatusCreated, w.Result().StatusCode; want != got {
t.Errorf("StatusCode: expected %s (%d), got %s (%d)", http.StatusText(want), want, http.StatusText(got), got)
}
if string(body) != "{}" {
t.Errorf("Expected register response to be \"{}\": result: %+v", string(body))
}
if !testStore.Called.CreateAccount {
t.Errorf("Expected Store.CreateAccount to be called")
}
}
func TestServerRegisterErrors(t *testing.T) {
t.Fatalf("Test me:")
}
func TestServerValidateRegisterRequest(t *testing.T) {
t.Fatalf("Test me: Implement and test RegisterRequest.validate()")
}