Skip to content

Commit

Permalink
update to products
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Nov 10, 2020
1 parent f1f467b commit 5634087
Show file tree
Hide file tree
Showing 9 changed files with 937 additions and 898 deletions.
1,784 changes: 894 additions & 890 deletions coverage.out

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ require (
github.com/Ulbora/Level_Logger v1.0.2
github.com/Ulbora/dbinterface v1.0.5
github.com/Ulbora/dbinterface_mysql v1.0.7
github.com/Ulbora/six910-database-interface v1.0.33
github.com/Ulbora/six910-database-interface v1.0.34
github.com/go-sql-driver/mysql v1.5.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/Ulbora/six910-database-interface v1.0.32 h1:+jRvIG9JlNjgNav//ItGy0uBD
github.com/Ulbora/six910-database-interface v1.0.32/go.mod h1:OGqZQ5ETgqxsHB636qmivSR36NzQxhV4T+ATsIUJSLM=
github.com/Ulbora/six910-database-interface v1.0.33 h1:YUuSe7KoRN7ngAGNeuCtgXUTfiJVKE3Rvx2t0ny4L8w=
github.com/Ulbora/six910-database-interface v1.0.33/go.mod h1:OGqZQ5ETgqxsHB636qmivSR36NzQxhV4T+ATsIUJSLM=
github.com/Ulbora/six910-database-interface v1.0.34 h1:BK0I1xKqLyAliqTjnk/mbni6xni9fXzcFyKyThGeqRY=
github.com/Ulbora/six910-database-interface v1.0.34/go.mod h1:OGqZQ5ETgqxsHB636qmivSR36NzQxhV4T+ATsIUJSLM=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
Expand Down
13 changes: 7 additions & 6 deletions mockDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ type MockSix910Mysql struct {
MockInsuranceList *[]mdb.Insurance
MockDeleteInsuranceSuccess bool

MockAddProductSuccess bool
MockProductID int64
MockUpdateProductSuccess bool
MockProduct *mdb.Product
MockProductList *[]mdb.Product
MockDeleteProductSuccess bool
MockAddProductSuccess bool
MockProductID int64
MockUpdateProductSuccess bool
MockUpdateProductQuantitySuccess bool
MockProduct *mdb.Product
MockProductList *[]mdb.Product
MockDeleteProductSuccess bool

MockAddRegionSuccess bool
MockRegionID int64
Expand Down
5 changes: 5 additions & 0 deletions mockDbMeths.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ func (d *MockSix910Mysql) UpdateProduct(p *mdb.Product) bool {
return d.MockUpdateProductSuccess
}

//UpdateProductQuantity UpdateProductQuantity
func (d *MockSix910Mysql) UpdateProductQuantity(p *mdb.Product) bool {
return d.MockUpdateProductQuantitySuccess
}

//GetProductByID GetProductByID
func (d *MockSix910Mysql) GetProductByID(id int64) *mdb.Product {
return d.MockProduct
Expand Down
6 changes: 6 additions & 0 deletions mockDb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ func TestMockSix910Mysql_Mocks(t *testing.T) {
t.Fail()
}

sdb.MockUpdateProductQuantitySuccess = true
uqprodsuc := si.UpdateProductQuantity(&prod)
if !uqprodsuc {
t.Fail()
}

sdb.MockProduct = &prod
fprod := si.GetProductByID(2)
if fprod.Color != prod.Color {
Expand Down
11 changes: 11 additions & 0 deletions product.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ func (d *Six910Mysql) UpdateProduct(p *mdb.Product) bool {
return suc
}

//UpdateProductQuantity UpdateProductQuantity
func (d *Six910Mysql) UpdateProductQuantity(p *mdb.Product) bool {
if !d.testConnection() {
d.DB.Connect()
}
var a []interface{}
a = append(a, p.Stock, p.ID)
suc := d.DB.Update(updateProductQuantity, a...)
return suc
}

//GetProductByID GetProductByID
func (d *Six910Mysql) GetProductByID(id int64) *mdb.Product {
if !d.testConnection() {
Expand Down
9 changes: 8 additions & 1 deletion product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,17 @@ func TestSix910Mysql_AddProduct(t *testing.T) {
t.Fail()
}

prod.Stock = 400
dbi.Close()
uqsuc := si.UpdateProductQuantity(&prod)
if !uqsuc {
t.Fail()
}

dbi.Close()
fprod := si.GetProductByID(pid)
fmt.Println("fprod", fprod)
if fprod.ID != pid {
if fprod.ID != pid || fprod.Stock != 400 {
t.Fail()
}
if fprod.DistributorID != did {
Expand Down
3 changes: 3 additions & 0 deletions queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ const (
" image4 = ?, special_processing = ?, special_processing_type = ? " +
" WHERE id = ?"

updateProductQuantity = "UPDATE product SET stock = ? " +
" WHERE id = ?"

getProduct = "SELECT id, sku, gtin, name, short_description, description, " +
" cost, msrp, map, price, sale_price, currency, manufacturer, stock, stock_alert, weight, " +
" width, height, depth, shipping_markup, visible, searchable, multibox, " +
Expand Down

0 comments on commit 5634087

Please sign in to comment.