At least is passes tests

master
breel 2020-08-02 11:54:35 -06:00
parent 8e6e86955e
commit 953d2d1365
2 changed files with 12 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
"github.com/google/uuid"
"github.com/iancoleman/orderedmap"
"go.mongodb.org/mongo-driver/bson"
)
@ -198,6 +199,11 @@ func whoPost(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter
return nil
}
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 {
return err
}

View File

@ -278,7 +278,8 @@ func TestWho(t *testing.T) {
handler, _, iwant, _, can := fresh(t)
defer can()
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()
handler.ServeHTTP(w, r)
if w.Code != http.StatusConflict {
@ -291,7 +292,7 @@ func TestWho(t *testing.T) {
defer can()
iwant := want
iwant.Name = ""
iwant.ID = "NEWBIE" + iwant.ID
iwant.ID = ""
b, err := json.Marshal(iwant)
if err != nil {
t.Fatal(err)
@ -320,7 +321,7 @@ func TestWho(t *testing.T) {
handler, _, want, _, can := fresh(t)
defer can()
want.Name = "hello world #1 e ę"
want.ID = "hello world #1 e ę" + want.ID
want.ID = ""
want.Connections = nil
b, err := json.Marshal(want)
if err != nil {
@ -371,7 +372,7 @@ func TestWho(t *testing.T) {
defer can()
want.Name = "hello world #4"
want.ID = "hello world #4" + want.ID
want.ID = ""
want.Connections = nil
b, err := json.Marshal(want)
if err != nil {
@ -413,7 +414,7 @@ func TestWho(t *testing.T) {
defer can()
want.Name = "hello world #1 e ę"
want.ID = "hello world #1 e ę" + want.ID
want.ID = ""
want.Connections = nil
b, err := json.Marshal(want)
if err != nil {