2021-12-25 02:16:58 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2022-06-17 21:39:12 +02:00
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2021-12-25 02:16:58 +01:00
|
|
|
"testing"
|
2022-06-17 21:39:12 +02:00
|
|
|
|
|
|
|
"orblivion/lbry-id/auth"
|
2021-12-25 02:16:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerRegisterErrors(t *testing.T) {
|
|
|
|
t.Fatalf("Test me:")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerValidateRegisterRequest(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: Implement and test RegisterRequest.validate()")
|
|
|
|
}
|