From a3942f79b8b93402045a031f888f205fe1248498 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Fri, 19 May 2017 12:41:07 +0200 Subject: [PATCH] [BUGFIX] test 100% again :D --- http/good.go | 15 +++++++++------ http/good_test.go | 1 + webroot/static/js/item-add.controller.js | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/http/good.go b/http/good.go index 9123b4f..8c7faa9 100644 --- a/http/good.go +++ b/http/good.go @@ -88,17 +88,20 @@ func delGood(w http.ResponseWriter, r *http.Request) { now := time.Now() var good models.Good good.ID = id + db := good.FilterAvailable(database.Read).First(&good) + if db.RecordNotFound() { + log.Warnf("good could not found: %s", db.Error) + http.Error(w, "the good could not found", http.StatusNotFound) + return + } good.ManuelleDelete = true good.DeletedAt = &now - db := database.Write.Save(&good) + + db = database.Write.Save(&good) if db.Error != nil { log.Warnf("good could not delete: %s", db.Error) http.Error(w, "the good could not delete", http.StatusInternalServerError) return } - if db.RowsAffected != 1 { - log.Warnf("good could not found: %s", db.Error) - http.Error(w, "the good could not found", http.StatusNotFound) - return - } + log.Info("done") } diff --git a/http/good_test.go b/http/good_test.go index b9e5f93..682e25a 100644 --- a/http/good_test.go +++ b/http/good_test.go @@ -115,6 +115,7 @@ func TestDelGood(t *testing.T) { _, w = session.JSONRequest("DELETE", fmt.Sprintf("/api/good/%d", good.ID), nil) assertion.Equal(http.StatusNotFound, w.StatusCode) + time.Sleep(time.Millisecond) database.Close() _, w = session.JSONRequest("DELETE", "/api/good/1", nil) diff --git a/webroot/static/js/item-add.controller.js b/webroot/static/js/item-add.controller.js index fb1d381..5b76347 100644 --- a/webroot/static/js/item-add.controller.js +++ b/webroot/static/js/item-add.controller.js @@ -16,7 +16,7 @@ angular.module('microStock') $scope.obj = {}; $scope.msg = {type:'success',text:'Saved '+$scope.count+' good(s) from product '+$scope.product.title+'.'}; }, function(){ - $scope.msg = {type:'error',text:'Error: Saved '+$scope.count+' good(s) from product '+$scope.product.title+'.'}; + $scope.msg = {type:'error',text:'Error: During saving of '+$scope.count+' good(s) from product '+$scope.product.title+'.'}; }); }; }]);