emoji_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDao_Emoji(t *testing.T) {
  8. // insert emoji
  9. Convey("CreateEmoji", t, WithDao(func(d *Dao) {
  10. id, err := d.CreateEmoji(context.Background(), 1, "[小电视_1]", "baidu.com", 0, 0, "ssss")
  11. So(err, ShouldBeNil)
  12. So(id, ShouldNotEqual, 0)
  13. defer d.DelEmojiByID(context.Background(), id)
  14. insertID := id
  15. //get all emoji
  16. Convey("EmojiList", WithDao(func(d *Dao) {
  17. data, err := d.EmojiList(context.Background())
  18. So(err, ShouldBeNil)
  19. for _, v := range data {
  20. t.Logf("v.Id= %d, v.PackageID= %d, v.Name= %s, v.Url= %s, v.Remark= %s, v.State= %d, v.Sort= %d",
  21. v.ID, v.PackageID, v.Name, v.URL, v.Remark, v.State, v.Sort)
  22. }
  23. }))
  24. // get emoji by package_id
  25. Convey("EmojiListByPid", WithDao(func(d *Dao) {
  26. data, err := d.EmojiListByPid(context.Background(), 1)
  27. So(err, ShouldBeNil)
  28. for _, v := range data {
  29. t.Logf("v.Id= %d, v.PackageID= %d, v.Name= %s, v.Url= %s, v.Remark= %s, v.State= %d, v.Sort= %d",
  30. v.ID, v.PackageID, v.Name, v.URL, v.Remark, v.State, v.Sort)
  31. }
  32. }))
  33. //update emoji sort
  34. Convey("UpEmojiSort", WithDao(func(d *Dao) {
  35. tx, _ := d.BeginTran(context.Background())
  36. err := d.UpEmojiSort(tx, "2,1")
  37. if err != nil {
  38. tx.Rollback()
  39. t.Errorf("UpEmojiSort err (%v)", err)
  40. return
  41. }
  42. tx.Commit()
  43. }))
  44. //update emoji state
  45. Convey("test UpdateEmojis", WithDao(func(d *Dao) {
  46. id, err := d.UpEmojiStateByID(context.Background(), 1, 70)
  47. So(err, ShouldBeNil)
  48. So(id, ShouldNotEqual, 0)
  49. t.Logf("id= %d", id)
  50. }))
  51. Convey("test select emoji by name", WithDao(func(d *Dao) {
  52. emojis, err := d.EmojiByName(context.Background(), "[小电视_1]")
  53. So(err, ShouldBeNil)
  54. for _, v := range emojis {
  55. t.Logf("v.ID= %d", v.ID)
  56. }
  57. }))
  58. // update emoji remark
  59. Convey("test SortEmojis", WithDao(func(d *Dao) {
  60. id, err := d.UpEmoji(context.Background(), "[小电视]", "cccxxx", "google.com", insertID)
  61. So(err, ShouldBeNil)
  62. So(id, ShouldNotEqual, 0)
  63. t.Logf("id= %d", id)
  64. }))
  65. Convey("test delEmoji", WithDao(func(d *Dao) {
  66. id, err := d.DelEmojiByID(context.Background(), insertID)
  67. So(err, ShouldBeNil)
  68. So(id, ShouldNotEqual, 0)
  69. t.Logf("id= %d", id)
  70. }))
  71. }))
  72. }