Get/update settings
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
+110
@@ -1,6 +1,7 @@
|
||||
package geddit
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -15,6 +16,76 @@ var expectedKarma = []SubredditKarma{
|
||||
{Subreddit: "golang", PostKarma: 1, CommentKarma: 0},
|
||||
}
|
||||
|
||||
var expectedSettings = &Settings{
|
||||
AcceptPrivateMessages: String("everyone"),
|
||||
ActivityRelevantAds: Bool(false),
|
||||
AllowClickTracking: Bool(false),
|
||||
Beta: Bool(false),
|
||||
ShowRecentlyViewedPosts: Bool(true),
|
||||
CollapseReadMessages: Bool(false),
|
||||
Compress: Bool(false),
|
||||
CredditAutorenew: nil,
|
||||
DefaultCommentSort: String("top"),
|
||||
ShowDomainDetails: Bool(false),
|
||||
SendEmailDigests: Bool(false),
|
||||
SendMessagesAsEmails: Bool(false),
|
||||
UnsubscribeFromAllEmails: Bool(true),
|
||||
DisableCustomThemes: Bool(false),
|
||||
Location: String("GLOBAL"),
|
||||
HideAds: Bool(false),
|
||||
HideFromSearchEngines: Bool(false),
|
||||
HideUpvotedPosts: Bool(false),
|
||||
HideDownvotedPosts: Bool(false),
|
||||
HighlightControversialComments: Bool(true),
|
||||
HighlightNewComments: Bool(true),
|
||||
IgnoreSuggestedSorts: Bool(true),
|
||||
UseNewReddit: nil,
|
||||
UsesNewReddit: Bool(false),
|
||||
LabelNSFW: Bool(true),
|
||||
Language: String("en-ca"),
|
||||
ShowOldSearchPage: Bool(false),
|
||||
EnableNotifications: Bool(true),
|
||||
MarkMessagesAsRead: Bool(true),
|
||||
ShowThumbnails: String("subreddit"),
|
||||
AutoExpandMedia: String("off"),
|
||||
MinimumCommentScore: nil,
|
||||
MinimumPostScore: nil,
|
||||
EnableMentionNotifications: Bool(true),
|
||||
OpenLinksInNewWindow: Bool(true),
|
||||
DarkMode: Bool(true),
|
||||
DisableProfanity: Bool(false),
|
||||
NumberOfComments: Int(200),
|
||||
NumberOfPosts: Int(25),
|
||||
ShowSpotlightBox: nil,
|
||||
SubredditTheme: nil,
|
||||
ShowNSFW: Bool(true),
|
||||
EnablePrivateRSSFeeds: Bool(true),
|
||||
ProfileOptOut: Bool(false),
|
||||
PublicizeVotes: Bool(false),
|
||||
AllowResearch: Bool(false),
|
||||
IncludeNSFWSearchResults: Bool(true),
|
||||
ReceiveCrosspostMessages: Bool(false),
|
||||
ReceiveWelcomeMessages: Bool(true),
|
||||
ShowUserFlair: Bool(true),
|
||||
ShowPostFlair: Bool(true),
|
||||
ShowGoldExpiration: Bool(false),
|
||||
ShowLocationBasedRecommendations: Bool(false),
|
||||
ShowPromote: nil,
|
||||
ShowCustomSubredditThemes: Bool(true),
|
||||
ShowTrendingSubreddits: Bool(true),
|
||||
ShowTwitter: Bool(false),
|
||||
StoreVisits: Bool(false),
|
||||
ThemeSelector: nil,
|
||||
AllowThirdPartyDataAdPersonalization: Bool(false),
|
||||
AllowThirdPartySiteDataAdPersonalization: Bool(false),
|
||||
AllowThirdPartySiteDataContentPersonalization: Bool(false),
|
||||
EnableThreadedMessages: Bool(true),
|
||||
EnableThreadedModmail: Bool(false),
|
||||
TopKarmaSubreddits: Bool(false),
|
||||
UseGlobalDefaults: Bool(false),
|
||||
EnableVideoAutoplay: Bool(true),
|
||||
}
|
||||
|
||||
func TestAccountServiceOp_Karma(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
@@ -30,3 +101,42 @@ func TestAccountServiceOp_Karma(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedKarma, karma)
|
||||
}
|
||||
|
||||
func TestAccountServiceOp_Settings(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
blob := readFileContents(t, "testdata/account/settings.json")
|
||||
|
||||
mux.HandleFunc("/api/v1/me/prefs", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, http.MethodGet, r.Method)
|
||||
fmt.Fprint(w, blob)
|
||||
})
|
||||
|
||||
settings, _, err := client.Account.Settings(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedSettings, settings)
|
||||
}
|
||||
|
||||
func TestAccountServiceOp_UpdateSettings(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
blob := readFileContents(t, "testdata/account/settings.json")
|
||||
expectedSettingsBody := &Settings{NumberOfPosts: Int(10), MinimumCommentScore: Int(5), Compress: Bool(true)}
|
||||
|
||||
mux.HandleFunc("/api/v1/me/prefs", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, http.MethodPatch, r.Method)
|
||||
|
||||
settingsBody := new(Settings)
|
||||
err := json.NewDecoder(r.Body).Decode(settingsBody)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedSettingsBody, settingsBody)
|
||||
|
||||
fmt.Fprint(w, blob)
|
||||
})
|
||||
|
||||
settings, _, err := client.Account.UpdateSettings(ctx, expectedSettingsBody)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedSettings, settings)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user