Update strain. Fixed EML/EMBL typo in json.
This commit is contained in:
parent
b8bda910cd
commit
ff0e37d2ef
9 changed files with 163 additions and 2 deletions
|
@ -38,6 +38,7 @@ func Handler() *mux.Router {
|
|||
m.Get(router.Strain).Handler(handler(serveStrain))
|
||||
m.Get(router.CreateStrain).Handler(handler(serveCreateStrain))
|
||||
m.Get(router.Strains).Handler(handler(serveStrainList))
|
||||
m.Get(router.UpdateStrain).Handler(handler(serveUpdateStrain))
|
||||
|
||||
return m
|
||||
}
|
||||
|
|
|
@ -57,3 +57,22 @@ func serveStrainList(w http.ResponseWriter, r *http.Request) error {
|
|||
|
||||
return writeJSON(w, strains)
|
||||
}
|
||||
|
||||
func serveUpdateStrain(w http.ResponseWriter, r *http.Request) error {
|
||||
id, _ := strconv.ParseInt(mux.Vars(r)["Id"], 10, 0)
|
||||
var strain models.Strain
|
||||
err := json.NewDecoder(r.Body).Decode(&strain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updated, err := store.Strains.Update(id, &strain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updated {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
return writeJSON(w, strain)
|
||||
}
|
||||
|
|
|
@ -96,3 +96,33 @@ func TestStrain_List(t *testing.T) {
|
|||
t.Errorf("got strains %+v but wanted strains %+v", strains, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrain_Update(t *testing.T) {
|
||||
setup()
|
||||
|
||||
want := newStrain()
|
||||
|
||||
calledPut := false
|
||||
store.Strains.(*models.MockStrainsService).Update_ = func(id int64, strain *models.Strain) (bool, error) {
|
||||
if id != want.Id {
|
||||
t.Errorf("wanted request for strain %d but got %d", want.Id, id)
|
||||
}
|
||||
if !normalizeDeepEqual(want, strain) {
|
||||
t.Errorf("wanted request for strain %d but got %d", want, strain)
|
||||
}
|
||||
calledPut = true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
success, err := apiClient.Strains.Update(1, want)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !calledPut {
|
||||
t.Error("!calledPut")
|
||||
}
|
||||
if !success {
|
||||
t.Error("!success")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue