group_test.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/workflow/model/param"
  6. "github.com/jinzhu/gorm"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoGroupByID(t *testing.T) {
  10. convey.Convey("GroupByID", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. gid = int64(1)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. g, err := d.GroupByID(c, gid)
  17. ctx.Convey("Then err should be nil.g should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(g, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoGroupByOid(t *testing.T) {
  25. convey.Convey("GroupByOid", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. oid = int64(1)
  29. business = int8(1)
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. g, err := d.GroupByOid(c, oid, business)
  33. ctx.Convey("Then err should be nil.g should not be nil.", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. ctx.So(g, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoTxGroupsByOidsStates(t *testing.T) {
  41. convey.Convey("TxGroupsByOidsStates", t, func(ctx convey.C) {
  42. var (
  43. tx = &gorm.DB{}
  44. oids = []int64{}
  45. business = int8(0)
  46. state = int8(0)
  47. )
  48. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  49. groups, err := d.TxGroupsByOidsStates(tx, oids, business, state)
  50. ctx.Convey("Then err should be nil.groups should not be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. ctx.So(groups, convey.ShouldNotBeNil)
  53. })
  54. })
  55. })
  56. }
  57. func TestDaoGroups(t *testing.T) {
  58. convey.Convey("Groups", t, func(ctx convey.C) {
  59. var (
  60. c = context.Background()
  61. gids = []int64{}
  62. )
  63. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  64. groups, err := d.Groups(c, gids)
  65. ctx.Convey("Then err should be nil.groups should not be nil.", func(ctx convey.C) {
  66. ctx.So(err, convey.ShouldBeNil)
  67. ctx.So(groups, convey.ShouldNotBeNil)
  68. })
  69. })
  70. })
  71. }
  72. func TestDaoTxGroups(t *testing.T) {
  73. convey.Convey("TxGroups", t, func(ctx convey.C) {
  74. var (
  75. tx = d.ORM.Begin()
  76. gids = []int64{1}
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. groups, err := d.TxGroups(tx, gids)
  80. err1 := tx.Commit().Error
  81. defer func() {
  82. if err != nil {
  83. tx.Rollback()
  84. }
  85. }()
  86. ctx.Convey("Then err should be nil.groups should not be nil.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. ctx.So(err1, convey.ShouldBeNil)
  89. ctx.So(groups, convey.ShouldNotBeNil)
  90. })
  91. })
  92. })
  93. }
  94. func TestDaoTxUpGroup(t *testing.T) {
  95. convey.Convey("TxUpGroup", t, func(ctx convey.C) {
  96. var (
  97. tx = d.ORM.Begin()
  98. oid = int64(1)
  99. business = int8(1)
  100. tid = int64(0)
  101. note = "test note"
  102. rid = int8(0)
  103. )
  104. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  105. err := d.TxUpGroup(tx, oid, business, tid, note, rid)
  106. err1 := tx.Commit().Error
  107. defer func() {
  108. if err != nil {
  109. tx.Rollback()
  110. }
  111. }()
  112. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  113. ctx.So(err, convey.ShouldBeNil)
  114. ctx.So(err1, convey.ShouldBeNil)
  115. })
  116. })
  117. })
  118. }
  119. func TestDaoUpGroupRole(t *testing.T) {
  120. convey.Convey("UpGroupRole", t, func(ctx convey.C) {
  121. var (
  122. c = context.Background()
  123. grsp = &param.GroupRoleSetParam{
  124. GID: []int64{1},
  125. AdminID: 1,
  126. AdminName: "anonymous",
  127. BID: 1,
  128. RID: 1,
  129. TID: 1,
  130. Note: "test note",
  131. }
  132. )
  133. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  134. err := d.UpGroupRole(c, grsp)
  135. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  136. ctx.So(err, convey.ShouldBeNil)
  137. })
  138. })
  139. })
  140. }
  141. func TestDaoTxUpGroupState(t *testing.T) {
  142. convey.Convey("TxUpGroupState", t, func(ctx convey.C) {
  143. var (
  144. tx = d.ORM.Begin()
  145. gid = int64(1)
  146. state = int8(0)
  147. )
  148. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  149. err := d.TxUpGroupState(tx, gid, state)
  150. err1 := tx.Commit().Error
  151. defer func() {
  152. if err != nil {
  153. tx.Rollback()
  154. }
  155. }()
  156. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  157. ctx.So(err, convey.ShouldBeNil)
  158. ctx.So(err1, convey.ShouldBeNil)
  159. })
  160. })
  161. })
  162. }
  163. func TestDaoTxUpGroupHandling(t *testing.T) {
  164. convey.Convey("TxUpGroupHandling", t, func(ctx convey.C) {
  165. var (
  166. tx = d.ORM.Begin()
  167. gid = int64(1)
  168. handling = int32(0)
  169. )
  170. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  171. err := d.TxUpGroupHandling(tx, gid, handling)
  172. err1 := tx.Commit().Error
  173. defer func() {
  174. if err != nil {
  175. tx.Rollback()
  176. }
  177. }()
  178. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  179. ctx.So(err, convey.ShouldBeNil)
  180. ctx.So(err1, convey.ShouldBeNil)
  181. })
  182. })
  183. })
  184. }
  185. func TestDaoTxBatchUpGroupHandling(t *testing.T) {
  186. convey.Convey("TxBatchUpGroupHandling", t, func(ctx convey.C) {
  187. var (
  188. tx = d.ORM.Begin()
  189. gids = []int64{1, 2}
  190. handling = int32(0)
  191. )
  192. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  193. err := d.TxBatchUpGroupHandling(tx, gids, handling)
  194. err1 := tx.Commit().Error
  195. defer func() {
  196. if err != nil {
  197. tx.Rollback()
  198. }
  199. }()
  200. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  201. ctx.So(err, convey.ShouldBeNil)
  202. ctx.So(err1, convey.ShouldBeNil)
  203. })
  204. })
  205. })
  206. }
  207. func TestDaoTxBatchUpGroupState(t *testing.T) {
  208. convey.Convey("TxBatchUpGroupState", t, func(ctx convey.C) {
  209. var (
  210. tx = d.ORM.Begin()
  211. gids = []int64{1, 2}
  212. state = int8(0)
  213. )
  214. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  215. err := d.TxBatchUpGroupState(tx, gids, state)
  216. err1 := tx.Commit().Error
  217. defer func() {
  218. if err != nil {
  219. tx.Rollback()
  220. }
  221. }()
  222. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  223. ctx.So(err, convey.ShouldBeNil)
  224. ctx.So(err1, convey.ShouldBeNil)
  225. })
  226. })
  227. })
  228. }
  229. func TestDaoTxSetGroupStateTid(t *testing.T) {
  230. convey.Convey("TxSetGroupStateTid", t, func(ctx convey.C) {
  231. var (
  232. tx = d.ORM.Begin()
  233. gids = []int64{1, 2}
  234. state = int8(0)
  235. tid = int64(0)
  236. rid = int8(0)
  237. )
  238. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  239. err := d.TxSetGroupStateTid(tx, gids, state, rid, tid)
  240. err1 := tx.Commit().Error
  241. defer func() {
  242. if err != nil {
  243. tx.Rollback()
  244. }
  245. }()
  246. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  247. ctx.So(err, convey.ShouldBeNil)
  248. ctx.So(err1, convey.ShouldBeNil)
  249. })
  250. })
  251. })
  252. }
  253. func TestDaoTxSimpleSetGroupState(t *testing.T) {
  254. convey.Convey("TxSimpleSetGroupState", t, func(ctx convey.C) {
  255. var (
  256. tx = d.ORM.Begin()
  257. gids = []int64{1, 2}
  258. state = int8(0)
  259. )
  260. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  261. err := d.TxSimpleSetGroupState(tx, gids, state)
  262. err1 := tx.Commit().Error
  263. defer func() {
  264. if err != nil {
  265. tx.Rollback()
  266. }
  267. }()
  268. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  269. ctx.So(err, convey.ShouldBeNil)
  270. ctx.So(err1, convey.ShouldBeNil)
  271. })
  272. })
  273. })
  274. }