intervs_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package service
  2. import (
  3. "fmt"
  4. "testing"
  5. "go-common/app/admin/main/tv/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestService_SeasonValidation(t *testing.T) {
  9. Convey("Season Validation Test", t, WithService(func(s *Service) {
  10. var season model.TVEpSeason
  11. if err := s.DB.Model(&model.TVEpSeason{}).Where("`check`=?", 1).
  12. Where("valid=?", 1).Where("is_deleted=?", 0).First(&season).Error; err != nil {
  13. fmt.Printf("Error:(%v)", err)
  14. return
  15. }
  16. fmt.Printf("Target ID is: %d", season.ID)
  17. res, sModel := s.snValid(season.ID)
  18. So(res, ShouldBeTrue)
  19. So(sModel.ID == season.ID, ShouldBeTrue)
  20. }))
  21. }
  22. func TestService_Intervs(t *testing.T) {
  23. Convey("Get Intervention List", t, WithService(func(s *Service) {
  24. res, err := s.Intervs(&model.IntervListReq{
  25. Rank: 0,
  26. Category: 1,
  27. })
  28. So(err, ShouldBeNil)
  29. fmt.Println(res)
  30. }))
  31. }
  32. func TestService_RemoveInvalids(t *testing.T) {
  33. Convey("Remove Invalid Test", t, WithService(func(s *Service) {
  34. var (
  35. rank model.Rank
  36. err error
  37. invalids []*model.RankError
  38. )
  39. if err = s.DB.Where("is_deleted=?", 0).First(&rank).Error; err != nil {
  40. fmt.Println(err)
  41. return
  42. }
  43. invalids = append(invalids, &model.RankError{
  44. ID: int(rank.ID),
  45. SeasonID: int(rank.ContID),
  46. })
  47. err = s.RemoveInvalids(invalids)
  48. So(err, ShouldBeNil)
  49. // recover
  50. err = s.DB.Model(rank).Where("id=?", rank.ID).Update(map[string]int{"is_deleted": 0}).Error
  51. So(err, ShouldBeNil)
  52. }))
  53. }