entry_test.go 1.7 KB

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