mysql_author_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "testing"
  4. "go-common/app/interface/openplatform/article/model"
  5. "go-common/library/ecode"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func Test_ApplyCount(t *testing.T) {
  9. mid := int64(1)
  10. pending := 0
  11. Convey("add apply", t, func() {
  12. err := d.AddApply(ctx(), mid, "content", "category")
  13. So(err, ShouldBeNil)
  14. Convey("get apply", func() {
  15. author, err := d.RawAuthor(ctx(), mid)
  16. So(err, ShouldBeNil)
  17. So(author, ShouldResemble, &model.AuthorLimit{State: pending})
  18. })
  19. Convey("apply count", func() {
  20. res, err := d.ApplyCount(ctx())
  21. So(err, ShouldBeNil)
  22. So(res, ShouldBeGreaterThan, 0)
  23. })
  24. Convey("add twice should be ok", func() {
  25. err := d.AddApply(ctx(), mid, "content", "category")
  26. So(err, ShouldBeNil)
  27. author, err := d.RawAuthor(ctx(), mid)
  28. So(err, ShouldBeNil)
  29. So(author, ShouldResemble, &model.AuthorLimit{State: pending})
  30. })
  31. })
  32. }
  33. func Test_Authors(t *testing.T) {
  34. Convey("should get authors", t, func() {
  35. res, err := d.Authors(ctx())
  36. So(err, ShouldBeNil)
  37. So(res, ShouldNotBeEmpty)
  38. })
  39. }
  40. func Test_Identity(t *testing.T) {
  41. Convey("should return identity when no error", t, func() {
  42. httpMock("get", _verifyAPI).Reply(200).JSON(`{"ts":1514341945,"code":0,"data":{"identify":1,"phone":0}}`)
  43. res, err := d.Identify(ctx(), 1)
  44. So(err, ShouldBeNil)
  45. So(res, ShouldResemble, &model.Identify{Identify: 1, Phone: 0})
  46. })
  47. Convey("should return error when code != 0", t, func() {
  48. httpMock("get", _verifyAPI).Reply(200).JSON(`{"ts":1514341945,"code":-3,"data":null}`)
  49. _, err := d.Identify(ctx(), 1)
  50. So(err, ShouldEqual, ecode.SignCheckErr)
  51. })
  52. }