At least is passes tests
parent
8e6e86955e
commit
953d2d1365
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
"github.com/gomarkdown/markdown/html"
|
"github.com/gomarkdown/markdown/html"
|
||||||
"github.com/gomarkdown/markdown/parser"
|
"github.com/gomarkdown/markdown/parser"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/iancoleman/orderedmap"
|
"github.com/iancoleman/orderedmap"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
@ -198,6 +199,11 @@ func whoPost(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
one.Name = id
|
one.Name = id
|
||||||
|
if one.ID != "" {
|
||||||
|
http.Error(w, `{"error":"cannot specify ID in body"}`, http.StatusBadRequest)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
one.ID = uuid.New().String()
|
||||||
if err := g.Insert(r.Context(), namespace, one); err != nil {
|
if err := g.Insert(r.Context(), namespace, one); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,8 @@ func TestWho(t *testing.T) {
|
||||||
handler, _, iwant, _, can := fresh(t)
|
handler, _, iwant, _, can := fresh(t)
|
||||||
defer can()
|
defer can()
|
||||||
want := iwant
|
want := iwant
|
||||||
r := httptest.NewRequest(http.MethodPost, "/who?namespace=col&id="+want.Name, strings.NewReader(`{"title":"this should fail to insert", "_id":"trash"}`))
|
want.ID = ""
|
||||||
|
r := httptest.NewRequest(http.MethodPost, "/who?namespace=col&id="+want.Name, strings.NewReader(`{"title":"this should fail to insert"}`))
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if w.Code != http.StatusConflict {
|
if w.Code != http.StatusConflict {
|
||||||
|
|
@ -291,7 +292,7 @@ func TestWho(t *testing.T) {
|
||||||
defer can()
|
defer can()
|
||||||
iwant := want
|
iwant := want
|
||||||
iwant.Name = ""
|
iwant.Name = ""
|
||||||
iwant.ID = "NEWBIE" + iwant.ID
|
iwant.ID = ""
|
||||||
b, err := json.Marshal(iwant)
|
b, err := json.Marshal(iwant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
@ -320,7 +321,7 @@ func TestWho(t *testing.T) {
|
||||||
handler, _, want, _, can := fresh(t)
|
handler, _, want, _, can := fresh(t)
|
||||||
defer can()
|
defer can()
|
||||||
want.Name = "hello world #1 e ę"
|
want.Name = "hello world #1 e ę"
|
||||||
want.ID = "hello world #1 e ę" + want.ID
|
want.ID = ""
|
||||||
want.Connections = nil
|
want.Connections = nil
|
||||||
b, err := json.Marshal(want)
|
b, err := json.Marshal(want)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -371,7 +372,7 @@ func TestWho(t *testing.T) {
|
||||||
defer can()
|
defer can()
|
||||||
|
|
||||||
want.Name = "hello world #4"
|
want.Name = "hello world #4"
|
||||||
want.ID = "hello world #4" + want.ID
|
want.ID = ""
|
||||||
want.Connections = nil
|
want.Connections = nil
|
||||||
b, err := json.Marshal(want)
|
b, err := json.Marshal(want)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -413,7 +414,7 @@ func TestWho(t *testing.T) {
|
||||||
defer can()
|
defer can()
|
||||||
|
|
||||||
want.Name = "hello world #1 e ę"
|
want.Name = "hello world #1 e ę"
|
||||||
want.ID = "hello world #1 e ę" + want.ID
|
want.ID = ""
|
||||||
want.Connections = nil
|
want.Connections = nil
|
||||||
b, err := json.Marshal(want)
|
b, err := json.Marshal(want)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue