~ttt/minifluxlite

minifluxlite/api/payload_test.go -rw-r--r-- 4.8 KiB
a04fe1aa — Frédéric Guillot Update Docker image to Alpine Linux 3.10.0 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright 2018 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package api // import "miniflux.app/api"

import (
	"testing"

	"miniflux.app/model"
)

func TestUpdateFeedURL(t *testing.T) {
	feedURL := "http://example.com/"
	changes := &feedModification{FeedURL: &feedURL}
	feed := &model.Feed{FeedURL: "http://example.org/"}
	changes.Update(feed)

	if feed.FeedURL != feedURL {
		t.Fatalf(`Unexpected value, got %q instead of %q`, feed.FeedURL, feedURL)
	}
}

func TestUpdateFeedURLWithEmptyString(t *testing.T) {
	feedURL := ""
	changes := &feedModification{FeedURL: &feedURL}
	feed := &model.Feed{FeedURL: "http://example.org/"}
	changes.Update(feed)

	if feed.FeedURL == feedURL {
		t.Fatal(`The FeedURL should not be modified`)
	}
}

func TestUpdateFeedURLWhenNotSet(t *testing.T) {
	changes := &feedModification{}
	feed := &model.Feed{FeedURL: "http://example.org/"}
	changes.Update(feed)

	if feed.FeedURL != "http://example.org/" {
		t.Fatal(`The FeedURL should not be modified`)
	}
}

func TestUpdateFeedSiteURL(t *testing.T) {
	siteURL := "http://example.com/"
	changes := &feedModification{SiteURL: &siteURL}
	feed := &model.Feed{SiteURL: "http://example.org/"}
	changes.Update(feed)

	if feed.SiteURL != siteURL {
		t.Fatalf(`Unexpected value, got %q instead of %q`, feed.SiteURL, siteURL)
	}
}

func TestUpdateFeedSiteURLWithEmptyString(t *testing.T) {
	siteURL := ""
	changes := &feedModification{FeedURL: &siteURL}
	feed := &model.Feed{SiteURL: "http://example.org/"}
	changes.Update(feed)

	if feed.SiteURL == siteURL {
		t.Fatal(`The FeedURL should not be modified`)
	}
}

func TestUpdateFeedSiteURLWhenNotSet(t *testing.T) {
	changes := &feedModification{}
	feed := &model.Feed{SiteURL: "http://example.org/"}
	changes.Update(feed)

	if feed.SiteURL != "http://example.org/" {
		t.Fatal(`The SiteURL should not be modified`)
	}
}

func TestUpdateFeedTitle(t *testing.T) {
	title := "Example 2"
	changes := &feedModification{Title: &title}
	feed := &model.Feed{Title: "Example"}
	changes.Update(feed)

	if feed.Title != title {
		t.Fatalf(`Unexpected value, got %q instead of %q`, feed.Title, title)
	}
}

func TestUpdateFeedTitleWithEmptyString(t *testing.T) {
	title := ""
	changes := &feedModification{Title: &title}
	feed := &model.Feed{Title: "Example"}
	changes.Update(feed)

	if feed.Title == title {
		t.Fatal(`The Title should not be modified`)
	}
}

func TestUpdateFeedTitleWhenNotSet(t *testing.T) {
	changes := &feedModification{}
	feed := &model.Feed{Title: "Example"}
	changes.Update(feed)

	if feed.Title != "Example" {
		t.Fatal(`The Title should not be modified`)
	}
}

func TestUpdateFeedUsername(t *testing.T) {
	username := "Alice"
	changes := &feedModification{Username: &username}
	feed := &model.Feed{Username: "Bob"}
	changes.Update(feed)

	if feed.Username != username {
		t.Fatalf(`Unexpected value, got %q instead of %q`, feed.Username, username)
	}
}

func TestUpdateFeedUsernameWithEmptyString(t *testing.T) {
	username := ""
	changes := &feedModification{Username: &username}
	feed := &model.Feed{Username: "Bob"}
	changes.Update(feed)

	if feed.Username != "" {
		t.Fatal(`The Username should be empty now`)
	}
}

func TestUpdateFeedUsernameWhenNotSet(t *testing.T) {
	changes := &feedModification{}
	feed := &model.Feed{Username: "Alice"}
	changes.Update(feed)

	if feed.Username != "Alice" {
		t.Fatal(`The Username should not be modified`)
	}
}

func TestUpdateFeedCategory(t *testing.T) {
	categoryID := int64(1)
	changes := &feedModification{CategoryID: &categoryID}
	feed := &model.Feed{Category: &model.Category{ID: 42}}
	changes.Update(feed)

	if feed.Category.ID != categoryID {
		t.Fatalf(`Unexpected value, got %q instead of %q`, feed.Username, categoryID)
	}
}

func TestUpdateFeedCategoryWithZero(t *testing.T) {
	categoryID := int64(0)
	changes := &feedModification{CategoryID: &categoryID}
	feed := &model.Feed{Category: &model.Category{ID: 42}}
	changes.Update(feed)

	if feed.Category.ID != 42 {
		t.Fatal(`The CategoryID should not be modified`)
	}
}

func TestUpdateFeedCategoryWhenNotSet(t *testing.T) {
	changes := &feedModification{}
	feed := &model.Feed{Category: &model.Category{ID: 42}}
	changes.Update(feed)

	if feed.Category.ID != 42 {
		t.Fatal(`The CategoryID should not be modified`)
	}
}

func TestUpdateUserTheme(t *testing.T) {
	theme := "Example 2"
	changes := &userModification{Theme: &theme}
	user := &model.User{Theme: "Example"}
	changes.Update(user)

	if user.Theme != theme {
		t.Fatalf(`Unexpected value, got %q instead of %q`, user.Theme, theme)
	}
}

func TestUserThemeWhenNotSet(t *testing.T) {
	changes := &userModification{}
	user := &model.User{Theme: "Example"}
	changes.Update(user)

	if user.Theme != "Example" {
		t.Fatal(`The user Theme should not be modified`)
	}
}