entry_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2021 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package validator // import "miniflux.app/validator"
  5. import (
  6. "testing"
  7. "miniflux.app/model"
  8. )
  9. func TestValidateEntriesStatusUpdateRequest(t *testing.T) {
  10. err := ValidateEntriesStatusUpdateRequest(&model.EntriesStatusUpdateRequest{
  11. Status: model.EntryStatusRead,
  12. EntryIDs: []int64{int64(123), int64(456)},
  13. })
  14. if err != nil {
  15. t.Error(`A valid request should not be rejected`)
  16. }
  17. err = ValidateEntriesStatusUpdateRequest(&model.EntriesStatusUpdateRequest{
  18. Status: model.EntryStatusRead,
  19. })
  20. if err == nil {
  21. t.Error(`An empty list of entries is not valid`)
  22. }
  23. err = ValidateEntriesStatusUpdateRequest(&model.EntriesStatusUpdateRequest{
  24. Status: "invalid",
  25. EntryIDs: []int64{int64(123)},
  26. })
  27. if err == nil {
  28. t.Error(`Only a valid status should be accepted`)
  29. }
  30. }
  31. func TestValidateEntryStatus(t *testing.T) {
  32. for _, status := range []string{model.EntryStatusRead, model.EntryStatusUnread, model.EntryStatusRemoved} {
  33. if err := ValidateEntryStatus(status); err != nil {
  34. t.Error(`A valid status should not generate any error`)
  35. }
  36. }
  37. if err := ValidateEntryStatus("invalid"); err == nil {
  38. t.Error(`An invalid status should generate a error`)
  39. }
  40. }
  41. func TestValidateEntryOrder(t *testing.T) {
  42. for _, status := range []string{"id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id"} {
  43. if err := ValidateEntryOrder(status); err != nil {
  44. t.Error(`A valid order should not generate any error`)
  45. }
  46. }
  47. if err := ValidateEntryOrder("invalid"); err == nil {
  48. t.Error(`An invalid order should generate a error`)
  49. }
  50. }