category_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2017 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 model // import "miniflux.app/model"
  5. import "testing"
  6. func TestValidateCategoryCreation(t *testing.T) {
  7. category := &Category{}
  8. if err := category.ValidateCategoryCreation(); err == nil {
  9. t.Error(`An empty category should generate an error`)
  10. }
  11. category = &Category{Title: "Test"}
  12. if err := category.ValidateCategoryCreation(); err == nil {
  13. t.Error(`A category without userID should generate an error`)
  14. }
  15. category = &Category{UserID: 42}
  16. if err := category.ValidateCategoryCreation(); err == nil {
  17. t.Error(`A category without title should generate an error`)
  18. }
  19. category = &Category{Title: "Test", UserID: 42}
  20. if err := category.ValidateCategoryCreation(); err != nil {
  21. t.Error(`All required fields are filled, it should not generate any error`)
  22. }
  23. }
  24. func TestValidateCategoryModification(t *testing.T) {
  25. category := &Category{}
  26. if err := category.ValidateCategoryModification(); err == nil {
  27. t.Error(`An empty category should generate an error`)
  28. }
  29. category = &Category{Title: "Test"}
  30. if err := category.ValidateCategoryModification(); err == nil {
  31. t.Error(`A category without userID should generate an error`)
  32. }
  33. category = &Category{UserID: 42}
  34. if err := category.ValidateCategoryModification(); err == nil {
  35. t.Error(`A category without title should generate an error`)
  36. }
  37. category = &Category{ID: -1, Title: "Test", UserID: 42}
  38. if err := category.ValidateCategoryModification(); err == nil {
  39. t.Error(`An invalid categoryID should generate an error`)
  40. }
  41. category = &Category{ID: 0, Title: "Test", UserID: 42}
  42. if err := category.ValidateCategoryModification(); err == nil {
  43. t.Error(`An invalid categoryID should generate an error`)
  44. }
  45. category = &Category{ID: 1, Title: "Test", UserID: 42}
  46. if err := category.ValidateCategoryModification(); err != nil {
  47. t.Error(`All required fields are filled, it should not generate any error`)
  48. }
  49. }