mirror of
https://github.com/dnote/dnote
synced 2026-03-14 14:35:50 +01:00
Fix test
This commit is contained in:
parent
b4126aa82b
commit
adb2b0a940
7 changed files with 23 additions and 14 deletions
|
|
@ -149,8 +149,8 @@ func (b *Books) create(r *http.Request) (database.Book, error) {
|
|||
return book, nil
|
||||
}
|
||||
|
||||
// createBookResp is the response from create book api
|
||||
type createBookResp struct {
|
||||
// CreateBookResp is the response from create book api
|
||||
type CreateBookResp struct {
|
||||
Book presenters.Book `json:"book"`
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ func (b *Books) V3Create(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
resp := createBookResp{
|
||||
resp := CreateBookResp{
|
||||
Book: presenters.PresentBook(result),
|
||||
}
|
||||
respondJSON(w, http.StatusCreated, resp)
|
||||
|
|
|
|||
|
|
@ -325,11 +325,11 @@ func TestCreateBook(t *testing.T) {
|
|||
assert.Equal(t, bookRecord.USN, maxUSN, "book user_id mismatch")
|
||||
assert.Equal(t, userRecord.MaxUSN, maxUSN, "user max_usn mismatch")
|
||||
|
||||
var got createBookResp
|
||||
var got CreateBookResp
|
||||
if err := json.NewDecoder(res.Body).Decode(&got); err != nil {
|
||||
t.Fatal(errors.Wrap(err, "decoding"))
|
||||
}
|
||||
expected := createBookResp{
|
||||
expected := CreateBookResp{
|
||||
Book: presenters.Book{
|
||||
UUID: bookRecord.UUID,
|
||||
USN: bookRecord.USN,
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dnote/dnote/pkg/server/context"
|
||||
"github.com/dnote/dnote/pkg/server/database"
|
||||
"github.com/dnote/dnote/pkg/server/helpers"
|
||||
"github.com/dnote/dnote/pkg/server/log"
|
||||
"github.com/dnote/dnote/pkg/server/middleware"
|
||||
"github.com/pkg/errors"
|
||||
|
|
@ -263,8 +263,8 @@ type GetSyncFragmentResp struct {
|
|||
|
||||
// GetSyncFragment responds with a sync fragment
|
||||
func (s *Sync) GetSyncFragment(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := r.Context().Value(helpers.KeyUser).(database.User)
|
||||
if !ok {
|
||||
user := context.User(r.Context())
|
||||
if user == nil {
|
||||
middleware.DoError(w, "No authenticated user found", nil, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
@ -296,8 +296,8 @@ type GetSyncStateResp struct {
|
|||
|
||||
// GetSyncState responds with a sync fragment
|
||||
func (s *Sync) GetSyncState(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := r.Context().Value(helpers.KeyUser).(database.User)
|
||||
if !ok {
|
||||
user := context.User(r.Context())
|
||||
if user == nil {
|
||||
middleware.DoError(w, "No authenticated user found", nil, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ import (
|
|||
// MustNewServer is a test utility function to initialize a new server
|
||||
// with the given app paratmers
|
||||
func MustNewServer(t *testing.T, appParams *app.App) *httptest.Server {
|
||||
server, err := NewServer(appParams)
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "initializing router"))
|
||||
}
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
func NewServer(appParams *app.App) (*httptest.Server, error) {
|
||||
a := app.NewTest(appParams)
|
||||
|
||||
ctl := New(&a)
|
||||
|
|
@ -39,10 +48,10 @@ func MustNewServer(t *testing.T, appParams *app.App) *httptest.Server {
|
|||
}
|
||||
r, err := NewRouter(&a, rc)
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "initializing router"))
|
||||
return nil, errors.Wrap(err, "initializing router")
|
||||
}
|
||||
|
||||
server := httptest.NewServer(r)
|
||||
|
||||
return server
|
||||
return server, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func (w *logResponseWriter) WriteHeader(code int) {
|
|||
}
|
||||
|
||||
// logging is a logging middleware
|
||||
func logging(inner http.Handler) http.HandlerFunc {
|
||||
func Logging(inner http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func APIMw(h http.Handler, app *app.App, rateLimit bool) http.Handler {
|
|||
func Global(h http.Handler) http.Handler {
|
||||
ret := h
|
||||
|
||||
ret = logging(ret)
|
||||
ret = Logging(ret)
|
||||
ret = methodOverride(ret)
|
||||
|
||||
return ret
|
||||
|
|
|
|||
BIN
test/cli/test-cli
Executable file
BIN
test/cli/test-cli
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue