venue_test.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/openplatform/ticket-item/model"
  5. "strconv"
  6. "testing"
  7. "time"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. // TestRawVenues
  11. func TestRawVenues(t *testing.T) {
  12. Convey("RawVenues", t, func() {
  13. once.Do(startService)
  14. res, err := d.RawVenues(context.TODO(), []int64{77, 78})
  15. So(err, ShouldBeNil)
  16. So(len(res), ShouldEqual, 2)
  17. So(res[77].Name, ShouldEqual, "海尔测试-勿动")
  18. })
  19. }
  20. // TestDaoVenue
  21. func TestDaoVenue(t *testing.T) {
  22. var id int64
  23. Convey("AddVenue", t, func() {
  24. once.Do(startService)
  25. venue := model.Venue{
  26. Name: "可删",
  27. Province: 100000,
  28. City: 100000,
  29. District: 100000,
  30. Status: 0,
  31. AddressDetail: "地址详细",
  32. Traffic: "交通",
  33. }
  34. err := d.AddVenue(context.TODO(), &venue)
  35. So(err, ShouldBeNil)
  36. So(venue.ID, ShouldNotEqual, 0)
  37. id = venue.ID
  38. })
  39. Convey("UpdateVenue", t, func() {
  40. once.Do(startService)
  41. venue := model.Venue{
  42. ID: id,
  43. Name: "可删",
  44. Province: 100000,
  45. City: 100000,
  46. District: 100010,
  47. Status: 1,
  48. AddressDetail: "地址详细",
  49. Traffic: "交通",
  50. }
  51. err := d.UpdateVenue(context.TODO(), &venue)
  52. So(err, ShouldBeNil)
  53. So(venue.Status, ShouldEqual, 1)
  54. })
  55. var placeNum int32
  56. Convey("TxIncPlaceNum", t, func() {
  57. once.Do(startService)
  58. c := context.TODO()
  59. res, err := d.RawVenues(c, []int64{id})
  60. placeNum = res[id].PlaceNum
  61. So(err, ShouldBeNil)
  62. tx, _ := d.BeginTran(c)
  63. So(tx, ShouldNotBeNil)
  64. err = d.TxIncPlaceNum(c, tx, id)
  65. So(err, ShouldBeNil)
  66. err = d.CommitTran(c, tx)
  67. So(err, ShouldBeNil)
  68. res, err = d.RawVenues(c, []int64{id})
  69. So(err, ShouldBeNil)
  70. So(res[id].PlaceNum, ShouldEqual, placeNum+1)
  71. })
  72. Convey("TxDecPlaceNum", t, func() {
  73. once.Do(startService)
  74. c := context.TODO()
  75. tx, _ := d.BeginTran(c)
  76. So(tx, ShouldNotBeNil)
  77. err := d.TxDecPlaceNum(c, tx, id)
  78. So(err, ShouldBeNil)
  79. err = d.CommitTran(c, tx)
  80. So(err, ShouldBeNil)
  81. res, _ := d.RawVenues(c, []int64{id})
  82. So(res[id].PlaceNum, ShouldEqual, placeNum)
  83. })
  84. }
  85. // TestRawPlace
  86. func TestRawPlace(t *testing.T) {
  87. Convey("RawPlace", t, func() {
  88. once.Do(startService)
  89. res, err := d.RawPlace(context.TODO(), 132)
  90. So(err, ShouldBeNil)
  91. So(res.Name, ShouldEqual, "海尔测试-勿动")
  92. })
  93. }
  94. // TestTxRawPlace
  95. func TestTxRawPlace(t *testing.T) {
  96. Convey("TxRawPlace", t, func() {
  97. once.Do(startService)
  98. c := context.TODO()
  99. tx, _ := d.BeginTran(c)
  100. So(tx, ShouldNotBeNil)
  101. res, err := d.TxRawPlace(c, tx, 132)
  102. So(err, ShouldBeNil)
  103. So(res.Name, ShouldEqual, "海尔测试-勿动")
  104. err = d.CommitTran(c, tx)
  105. So(err, ShouldBeNil)
  106. So(res.Name, ShouldEqual, "海尔测试-勿动")
  107. })
  108. }
  109. // TestDaoPlace
  110. func TestDaoPlace(t *testing.T) {
  111. var id int64
  112. Convey("TxAddPlace", t, func() {
  113. once.Do(startService)
  114. c := context.TODO()
  115. tx, _ := d.BeginTran(c)
  116. So(tx, ShouldNotBeNil)
  117. place := &model.Place{
  118. Name: "可删",
  119. BasePic: "url",
  120. Status: 1,
  121. Venue: 81,
  122. DWidth: 800,
  123. DHeight: 800,
  124. }
  125. err := d.TxAddPlace(c, tx, place)
  126. So(err, ShouldBeNil)
  127. So(place.ID, ShouldNotEqual, 0)
  128. id = place.ID
  129. err = d.CommitTran(c, tx)
  130. So(err, ShouldBeNil)
  131. place, err = d.RawPlace(c, id)
  132. So(err, ShouldBeNil)
  133. So(place.ID, ShouldNotEqual, 0)
  134. })
  135. Convey("TxUpdatePlace", t, func() {
  136. once.Do(startService)
  137. c := context.TODO()
  138. tx, _ := d.BeginTran(c)
  139. So(tx, ShouldNotBeNil)
  140. place := &model.Place{
  141. ID: id,
  142. Name: "可删",
  143. BasePic: "url2",
  144. Status: 1,
  145. Venue: 81,
  146. DWidth: 800,
  147. DHeight: 800,
  148. }
  149. err := d.TxUpdatePlace(c, tx, place)
  150. So(err, ShouldBeNil)
  151. So(place.BasePic, ShouldEqual, "url2")
  152. err = d.CommitTran(c, tx)
  153. So(err, ShouldBeNil)
  154. place, err = d.RawPlace(c, id)
  155. So(err, ShouldBeNil)
  156. So(place.BasePic, ShouldEqual, "url2")
  157. })
  158. var placePolygon *model.PlacePolygon
  159. Convey("TxAddOrUpdateAreaPolygon", t, func() {
  160. once.Do(startService)
  161. c := context.TODO()
  162. tx, _ := d.BeginTran(c)
  163. So(tx, ShouldNotBeNil)
  164. var co = "292 103,443 113,414 263,230 247"
  165. err := d.TxAddOrUpdateAreaPolygon(c, tx, id, 239, &co)
  166. So(err, ShouldBeNil)
  167. err = d.CommitTran(c, tx)
  168. So(err, ShouldBeNil)
  169. placePolygon, err = d.RawPlacePolygon(c, id)
  170. So(err, ShouldBeNil)
  171. So(placePolygon.Coordinate, ShouldEqual, "{\"239\":\"292 103,443 113,414 263,230 247\"}")
  172. })
  173. Convey("TxDelAreaPolygon", t, func() {
  174. once.Do(startService)
  175. c := context.TODO()
  176. tx, _ := d.BeginTran(c)
  177. So(tx, ShouldNotBeNil)
  178. err := d.TxDelAreaPolygon(c, tx, id, 239)
  179. So(err, ShouldBeNil)
  180. err = d.CommitTran(c, tx)
  181. So(err, ShouldBeNil)
  182. placePolygon, err = d.RawPlacePolygon(c, id)
  183. So(err, ShouldBeNil)
  184. So(placePolygon.Coordinate, ShouldEqual, "{}")
  185. })
  186. }
  187. // TestRawArea
  188. func TestRawArea(t *testing.T) {
  189. Convey("RawArea", t, func() {
  190. once.Do(startService)
  191. res, err := d.RawArea(context.TODO(), 239)
  192. So(err, ShouldBeNil)
  193. So(res.Name, ShouldEqual, "海尔测试-勿动")
  194. })
  195. }
  196. func TestTxRawArea(t *testing.T) {
  197. Convey("RawArea", t, func() {
  198. once.Do(startService)
  199. c := context.TODO()
  200. tx, _ := d.BeginTran(c)
  201. So(tx, ShouldNotBeNil)
  202. res, err := d.TxRawArea(c, tx, 239)
  203. So(err, ShouldBeNil)
  204. So(res.Name, ShouldEqual, "海尔测试-勿动")
  205. err = d.CommitTran(c, tx)
  206. So(err, ShouldBeNil)
  207. res, err = d.RawArea(context.TODO(), 239)
  208. So(err, ShouldBeNil)
  209. So(res.Name, ShouldEqual, "海尔测试-勿动")
  210. })
  211. }
  212. // TestDaoArea
  213. func TestDaoArea(t *testing.T) {
  214. var id int64
  215. Convey("TxAddArea", t, func() {
  216. once.Do(startService)
  217. c := context.TODO()
  218. tx, _ := d.BeginTran(c)
  219. So(tx, ShouldNotBeNil)
  220. area := &model.Area{
  221. AID: "test" + strconv.FormatInt(time.Now().Unix(), 10),
  222. Name: "可删",
  223. Place: 132,
  224. }
  225. err := d.TxAddArea(c, tx, area)
  226. So(err, ShouldBeNil)
  227. So(area.ID, ShouldNotEqual, 0)
  228. id = area.ID
  229. err = d.CommitTran(c, tx)
  230. So(err, ShouldBeNil)
  231. area, err = d.RawArea(c, id)
  232. So(err, ShouldBeNil)
  233. So(area.ID, ShouldNotEqual, 0)
  234. })
  235. Convey("TxUpdateArea", t, func() {
  236. once.Do(startService)
  237. c := context.TODO()
  238. tx, _ := d.BeginTran(c)
  239. So(tx, ShouldNotBeNil)
  240. area := &model.Area{
  241. ID: id,
  242. AID: "test" + strconv.FormatInt(time.Now().Unix(), 10),
  243. Name: "可删-1",
  244. Place: 132,
  245. }
  246. err := d.TxUpdateArea(c, tx, area)
  247. So(err, ShouldBeNil)
  248. err = d.CommitTran(c, tx)
  249. So(err, ShouldBeNil)
  250. area, err = d.RawArea(c, id)
  251. So(err, ShouldBeNil)
  252. So(area.Name, ShouldEqual, "可删-1")
  253. So(area.Place, ShouldEqual, 132)
  254. })
  255. Convey("TxUpdateSeat", t, func() {
  256. once.Do(startService)
  257. c := context.TODO()
  258. tx, _ := d.BeginTran(c)
  259. So(tx, ShouldNotBeNil)
  260. area := &model.Area{
  261. ID: id,
  262. SeatsNum: 10,
  263. Width: 1,
  264. Height: 2,
  265. DeletedStatus: 0,
  266. ColStart: 3,
  267. ColType: 4,
  268. ColDirection: 1,
  269. RowList: "[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\"]",
  270. SeatStart: "",
  271. }
  272. err := d.TxUpdateSeat(c, tx, area)
  273. So(err, ShouldBeNil)
  274. So(area.SeatsNum, ShouldEqual, 10)
  275. area, err = d.RawArea(c, id)
  276. So(err, ShouldBeNil)
  277. So(area.SeatsNum, ShouldEqual, 0)
  278. err = d.CommitTran(c, tx)
  279. So(err, ShouldBeNil)
  280. area, err = d.RawArea(c, id)
  281. So(err, ShouldBeNil)
  282. So(area.SeatsNum, ShouldEqual, 10)
  283. })
  284. }