payload_test.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // Copyright 2018 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 api
  5. import (
  6. "testing"
  7. "github.com/miniflux/miniflux/model"
  8. )
  9. func TestUpdateFeedURL(t *testing.T) {
  10. feedURL := "http://example.com/"
  11. changes := &feedModification{FeedURL: &feedURL}
  12. feed := &model.Feed{FeedURL: "http://example.org/"}
  13. changes.Update(feed)
  14. if feed.FeedURL != feedURL {
  15. t.Fatalf(`Unexpected value, got %q instead of %q`, feed.FeedURL, feedURL)
  16. }
  17. }
  18. func TestUpdateFeedURLWithEmptyString(t *testing.T) {
  19. feedURL := ""
  20. changes := &feedModification{FeedURL: &feedURL}
  21. feed := &model.Feed{FeedURL: "http://example.org/"}
  22. changes.Update(feed)
  23. if feed.FeedURL == feedURL {
  24. t.Fatal(`The FeedURL should not be modified`)
  25. }
  26. }
  27. func TestUpdateFeedURLWhenNotSet(t *testing.T) {
  28. changes := &feedModification{}
  29. feed := &model.Feed{FeedURL: "http://example.org/"}
  30. changes.Update(feed)
  31. if feed.FeedURL != "http://example.org/" {
  32. t.Fatal(`The FeedURL should not be modified`)
  33. }
  34. }
  35. func TestUpdateFeedSiteURL(t *testing.T) {
  36. siteURL := "http://example.com/"
  37. changes := &feedModification{SiteURL: &siteURL}
  38. feed := &model.Feed{SiteURL: "http://example.org/"}
  39. changes.Update(feed)
  40. if feed.SiteURL != siteURL {
  41. t.Fatalf(`Unexpected value, got %q instead of %q`, feed.SiteURL, siteURL)
  42. }
  43. }
  44. func TestUpdateFeedSiteURLWithEmptyString(t *testing.T) {
  45. siteURL := ""
  46. changes := &feedModification{FeedURL: &siteURL}
  47. feed := &model.Feed{SiteURL: "http://example.org/"}
  48. changes.Update(feed)
  49. if feed.SiteURL == siteURL {
  50. t.Fatal(`The FeedURL should not be modified`)
  51. }
  52. }
  53. func TestUpdateFeedSiteURLWhenNotSet(t *testing.T) {
  54. changes := &feedModification{}
  55. feed := &model.Feed{SiteURL: "http://example.org/"}
  56. changes.Update(feed)
  57. if feed.SiteURL != "http://example.org/" {
  58. t.Fatal(`The SiteURL should not be modified`)
  59. }
  60. }
  61. func TestUpdateFeedTitle(t *testing.T) {
  62. title := "Example 2"
  63. changes := &feedModification{Title: &title}
  64. feed := &model.Feed{Title: "Example"}
  65. changes.Update(feed)
  66. if feed.Title != title {
  67. t.Fatalf(`Unexpected value, got %q instead of %q`, feed.Title, title)
  68. }
  69. }
  70. func TestUpdateFeedTitleWithEmptyString(t *testing.T) {
  71. title := ""
  72. changes := &feedModification{Title: &title}
  73. feed := &model.Feed{Title: "Example"}
  74. changes.Update(feed)
  75. if feed.Title == title {
  76. t.Fatal(`The Title should not be modified`)
  77. }
  78. }
  79. func TestUpdateFeedTitleWhenNotSet(t *testing.T) {
  80. changes := &feedModification{}
  81. feed := &model.Feed{Title: "Example"}
  82. changes.Update(feed)
  83. if feed.Title != "Example" {
  84. t.Fatal(`The Title should not be modified`)
  85. }
  86. }
  87. func TestUpdateFeedUsername(t *testing.T) {
  88. username := "Alice"
  89. changes := &feedModification{Username: &username}
  90. feed := &model.Feed{Username: "Bob"}
  91. changes.Update(feed)
  92. if feed.Username != username {
  93. t.Fatalf(`Unexpected value, got %q instead of %q`, feed.Username, username)
  94. }
  95. }
  96. func TestUpdateFeedUsernameWithEmptyString(t *testing.T) {
  97. username := ""
  98. changes := &feedModification{Username: &username}
  99. feed := &model.Feed{Username: "Bob"}
  100. changes.Update(feed)
  101. if feed.Username != "" {
  102. t.Fatal(`The Username should be empty now`)
  103. }
  104. }
  105. func TestUpdateFeedUsernameWhenNotSet(t *testing.T) {
  106. changes := &feedModification{}
  107. feed := &model.Feed{Username: "Alice"}
  108. changes.Update(feed)
  109. if feed.Username != "Alice" {
  110. t.Fatal(`The Username should not be modified`)
  111. }
  112. }
  113. func TestUpdateFeedCategory(t *testing.T) {
  114. categoryID := int64(1)
  115. changes := &feedModification{CategoryID: &categoryID}
  116. feed := &model.Feed{Category: &model.Category{ID: 42}}
  117. changes.Update(feed)
  118. if feed.Category.ID != categoryID {
  119. t.Fatalf(`Unexpected value, got %q instead of %q`, feed.Username, categoryID)
  120. }
  121. }
  122. func TestUpdateFeedCategoryWithZero(t *testing.T) {
  123. categoryID := int64(0)
  124. changes := &feedModification{CategoryID: &categoryID}
  125. feed := &model.Feed{Category: &model.Category{ID: 42}}
  126. changes.Update(feed)
  127. if feed.Category.ID != 42 {
  128. t.Fatal(`The CategoryID should not be modified`)
  129. }
  130. }
  131. func TestUpdateFeedCategoryWhenNotSet(t *testing.T) {
  132. changes := &feedModification{}
  133. feed := &model.Feed{Category: &model.Category{ID: 42}}
  134. changes.Update(feed)
  135. if feed.Category.ID != 42 {
  136. t.Fatal(`The CategoryID should not be modified`)
  137. }
  138. }
  139. func TestUpdateUserTheme(t *testing.T) {
  140. theme := "Example 2"
  141. changes := &userModification{Theme: &theme}
  142. user := &model.User{Theme: "Example"}
  143. changes.Update(user)
  144. if user.Theme != theme {
  145. t.Fatalf(`Unexpected value, got %q instead of %q`, user.Theme, theme)
  146. }
  147. }
  148. func TestUserThemeWhenNotSet(t *testing.T) {
  149. changes := &userModification{}
  150. user := &model.User{Theme: "Example"}
  151. changes.Update(user)
  152. if user.Theme != "Example" {
  153. t.Fatal(`The user Theme should not be modified`)
  154. }
  155. }