invite_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package dao
  2. import (
  3. "context"
  4. "net"
  5. "testing"
  6. "time"
  7. "github.com/satori/go.uuid"
  8. "go-common/app/admin/main/usersuit/model"
  9. xtime "go-common/library/time"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestDao_RangeInvites(t *testing.T) {
  13. mid := int64(2)
  14. Convey("add invite", t, func() {
  15. now := time.Now().Unix()
  16. inv := &model.Invite{
  17. Mid: mid,
  18. Code: uuid.NewV4().String(),
  19. IPng: net.ParseIP("127.0.0.1"),
  20. Expires: now + int64(time.Hour*72/time.Second),
  21. Ctime: xtime.Time(now),
  22. }
  23. affected, err := d.AddIgnoreInvite(context.Background(), inv)
  24. So(err, ShouldBeNil)
  25. So(affected, ShouldEqual, 1)
  26. })
  27. Convey("range a test account's current month invite codes", t, func() {
  28. now := time.Now()
  29. start, end := rangeMonth(now)
  30. res, err := d.RangeInvites(context.Background(), mid, start, end)
  31. So(err, ShouldBeNil)
  32. So(res, ShouldNotBeNil)
  33. })
  34. }
  35. func rangeMonth(now time.Time) (start, end time.Time) {
  36. year := now.Year()
  37. month := now.Month()
  38. loc := now.Location()
  39. start = time.Date(year, month, 1, 0, 0, 0, 0, loc)
  40. end = time.Date(year, month+1, 0, 23, 59, 59, 0, loc)
  41. return
  42. }