stock_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "strings"
  4. "testing"
  5. "go-common/app/service/openplatform/ticket-sales/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestTxAddStockLog(t *testing.T) {
  9. Convey("TestTxAddStockLog", t, func() {
  10. tx, _ := d.BeginTx(ctx)
  11. err := d.TxAddStockLog(tx, &model.SKUStockLog{
  12. SKUID: 1,
  13. OpType: 1,
  14. SrcID: 1,
  15. Stock: 1,
  16. })
  17. tx.Rollback()
  18. if strings.Contains(err.Error(), "Error 1062: Duplicate entry") {
  19. So(err, ShouldNotBeNil)
  20. } else {
  21. So(err, ShouldBeNil)
  22. }
  23. })
  24. }
  25. func TestSkuByItemID(t *testing.T) {
  26. Convey("TestSkuByItemID", t, func() {
  27. res, err := d.SkuByItemID(ctx, 1)
  28. So(err, ShouldBeNil)
  29. So(res, ShouldNotBeNil)
  30. })
  31. }
  32. func TestStocks(t *testing.T) {
  33. Convey("TestStocks", t, func() {
  34. res, err := d.Stocks(ctx, []int64{1}, false)
  35. So(err, ShouldBeNil)
  36. So(res, ShouldNotBeNil)
  37. })
  38. }
  39. func TestGetSKUs(t *testing.T) {
  40. Convey("TestGetSKUs", t, func() {
  41. res, err := d.GetSKUs(ctx, []int64{1}, false)
  42. So(err, ShouldBeNil)
  43. So(res, ShouldNotBeNil)
  44. })
  45. }