diff --git a/subreddit_test.go b/subreddit_test.go index 96ff990..7fa11e1 100644 --- a/subreddit_test.go +++ b/subreddit_test.go @@ -292,30 +292,51 @@ func TestSubredditService_GetModerated(t *testing.T) { assert.Equal(t, expectedSubreddits, subreddits) } -// todo: WIP -// func TestSubredditService_GetSticky1(t *testing.T) { -// setup() -// defer teardown() +func TestSubredditService_GetSticky1(t *testing.T) { + setup() + defer teardown() -// blob, err:= readFileContents( "testdata/subreddit/sticky.json") -// assert.NoError(t,err) + blob, err := readFileContents("testdata/post/post.json") + assert.NoError(t, err) -// mux.HandleFunc("/r/nba/about/sticky", func(w http.ResponseWriter, r *http.Request) { -// assert.Equal(t, http.MethodGet, r.Method) + mux.HandleFunc("/r/test/about/sticky", func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method) -// err := r.ParseForm() -// assert.NoError(t, err) -// assert.Equal(t, "1", r.Form.Get("num")) + err := r.ParseForm() + assert.NoError(t, err) + assert.Equal(t, "1", r.Form.Get("num")) -// fmt.Fprint(w, blob) -// }) + fmt.Fprint(w, blob) + }) -// sticky, _, err := client.Subreddit.GetSticky1(ctx, "nba") -// assert.NoError(t, err) -// assert.Equal(t, expectedSticky.Post, sticky.Post) -// // b, _ := json.MarshalIndent(sticky.Comments, "", " ") -// // fmt.Println(string(b)) -// } + post, comments, _, err := client.Subreddit.GetSticky1(ctx, "test") + assert.NoError(t, err) + assert.Equal(t, expectedPost2, post) + assert.Equal(t, expectedComments, comments) +} + +func TestSubredditService_GetSticky2(t *testing.T) { + setup() + defer teardown() + + blob, err := readFileContents("testdata/post/post.json") + assert.NoError(t, err) + + mux.HandleFunc("/r/test/about/sticky", func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method) + + err := r.ParseForm() + assert.NoError(t, err) + assert.Equal(t, "2", r.Form.Get("num")) + + fmt.Fprint(w, blob) + }) + + post, comments, _, err := client.Subreddit.GetSticky2(ctx, "test") + assert.NoError(t, err) + assert.Equal(t, expectedPost2, post) + assert.Equal(t, expectedComments, comments) +} func TestSubredditService_Subscribe(t *testing.T) { setup() diff --git a/testdata/subreddit/sticky.json b/testdata/subreddit/sticky.json deleted file mode 100644 index 9231565..0000000 --- a/testdata/subreddit/sticky.json +++ /dev/null @@ -1,456 +0,0 @@ -[ - { - "kind": "Listing", - "data": { - "modhash": null, - "dist": 1, - "children": [ - { - "kind": "t3", - "data": { - "approved_at_utc": null, - "subreddit": "test", - "selftext": "test", - "user_reports": [], - "saved": false, - "mod_reason_title": null, - "gilded": 0, - "clicked": false, - "title": "test", - "link_flair_richtext": [], - "subreddit_name_prefixed": "r/test", - "hidden": false, - "pwls": 6, - "link_flair_css_class": null, - "downs": 0, - "thumbnail_height": null, - "top_awarded_type": null, - "parent_whitelist_status": "all_ads", - "hide_score": false, - "name": "t3_agi5zf", - "quarantine": false, - "link_flair_text_color": "dark", - "upvote_ratio": 0.99, - "author_flair_background_color": null, - "subreddit_type": "public", - "ups": 253, - "total_awards_received": 0, - "media_embed": {}, - "thumbnail_width": null, - "author_flair_template_id": null, - "is_original_content": false, - "author_fullname": "t2_30a5ktgt", - "secure_media": null, - "is_reddit_media_domain": false, - "is_meta": false, - "category": null, - "secure_media_embed": {}, - "link_flair_text": null, - "can_mod_post": false, - "score": 253, - "approved_by": null, - "author_premium": false, - "thumbnail": "self", - "edited": false, - "author_flair_css_class": null, - "author_flair_richtext": [], - "gildings": {}, - "content_categories": null, - "is_self": true, - "mod_note": null, - "created": 1547647071.0, - "link_flair_type": "text", - "wls": 6, - "removed_by_category": null, - "banned_by": null, - "author_flair_type": "text", - "domain": "self.test", - "allow_live_comments": true, - "selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>test</p>\n</div><!-- SC_ON -->", - "likes": null, - "suggested_sort": null, - "banned_at_utc": null, - "view_count": null, - "archived": true, - "no_follow": true, - "is_crosspostable": true, - "pinned": false, - "over_18": false, - "all_awardings": [], - "awarders": [], - "media_only": false, - "can_gild": true, - "spoiler": false, - "locked": false, - "author_flair_text": null, - "treatment_tags": [], - "visited": false, - "removed_by": null, - "num_reports": null, - "distinguished": null, - "subreddit_id": "t5_2qh23", - "mod_reason_by": null, - "removal_reason": null, - "link_flair_background_color": "", - "id": "agi5zf", - "is_robot_indexable": true, - "num_duplicates": 5, - "report_reasons": null, - "author": "kmiller0112", - "discussion_type": null, - "num_comments": 1634, - "send_replies": true, - "media": null, - "contest_mode": false, - "author_patreon_flair": false, - "author_flair_text_color": null, - "permalink": "/r/test/comments/agi5zf/test/", - "whitelist_status": "all_ads", - "stickied": true, - "url": "https://www.reddit.com/r/test/comments/agi5zf/test/", - "subreddit_subscribers": 8137, - "created_utc": 1547618271.0, - "num_crossposts": 7, - "mod_reports": [], - "is_video": false - } - } - ], - "after": null, - "before": null - } - }, - { - "kind": "Listing", - "data": { - "modhash": null, - "dist": null, - "children": [ - { - "kind": "t1", - "data": { - "total_awards_received": 0, - "approved_at_utc": null, - "ups": 25, - "awarders": [], - "mod_reason_by": null, - "banned_by": null, - "author_flair_type": "text", - "removal_reason": null, - "link_id": "t3_agi5zf", - "author_flair_template_id": null, - "likes": null, - "replies": { - "kind": "Listing", - "data": { - "modhash": null, - "dist": null, - "children": [ - { - "kind": "t1", - "data": { - "total_awards_received": 0, - "approved_at_utc": null, - "ups": 6, - "awarders": [], - "mod_reason_by": null, - "banned_by": null, - "author_flair_type": "text", - "removal_reason": null, - "link_id": "t3_agi5zf", - "author_flair_template_id": null, - "likes": null, - "replies": { - "kind": "Listing", - "data": { - "modhash": null, - "dist": null, - "children": [ - { - "kind": "more", - "data": { - "count": 13, - "name": "t1_en01zbs", - "id": "en01zbs", - "parent_id": "t1_efwm2b9", - "depth": 2, - "children": [ - "en01zbs", - "et8l4dd", - "ehf8h0n", - "erlfgpp", - "egnfntj" - ] - } - } - ], - "after": null, - "before": null - } - }, - "user_reports": [], - "saved": false, - "id": "efwm2b9", - "banned_at_utc": null, - "mod_reason_title": null, - "gilded": 0, - "archived": true, - "no_follow": true, - "author": "HappyNumberBot", - "can_mod_post": false, - "send_replies": true, - "parent_id": "t1_eetghdx", - "score": 6, - "author_fullname": "t2_2yz4imzj", - "report_reasons": null, - "approved_by": null, - "all_awardings": [], - "subreddit_id": "t5_2qh23", - "collapsed": false, - "body": "!stats", - "edited": false, - "author_flair_css_class": null, - "is_submitter": false, - "downs": 0, - "author_flair_richtext": [], - "author_patreon_flair": false, - "body_html": "<div class=\"md\"><p>!stats</p>\n</div>", - "gildings": {}, - "collapsed_reason": null, - "associated_award": null, - "stickied": false, - "author_premium": false, - "subreddit_type": "public", - "can_gild": true, - "top_awarded_type": null, - "author_flair_text_color": null, - "score_hidden": false, - "permalink": "/r/test/comments/agi5zf/test/efwm2b9/", - "num_reports": null, - "locked": false, - "name": "t1_efwm2b9", - "created": 1549523627.0, - "subreddit": "test", - "author_flair_text": null, - "treatment_tags": [], - "created_utc": 1549494827.0, - "subreddit_name_prefixed": "r/test", - "controversiality": 0, - "depth": 1, - "author_flair_background_color": null, - "collapsed_because_crowd_control": null, - "mod_reports": [], - "mod_note": null, - "distinguished": null - } - }, - { - "kind": "t1", - "data": { - "total_awards_received": 0, - "approved_at_utc": null, - "ups": 3, - "awarders": [], - "mod_reason_by": null, - "banned_by": null, - "author_flair_type": "text", - "removal_reason": null, - "link_id": "t3_agi5zf", - "author_flair_template_id": null, - "likes": null, - "replies": { - "kind": "Listing", - "data": { - "modhash": null, - "dist": null, - "children": [ - { - "kind": "more", - "data": { - "count": 10, - "name": "t1_elbu38g", - "id": "elbu38g", - "parent_id": "t1_efwmm9z", - "depth": 2, - "children": [ - "elbu38g", - "eois738", - "ery3duu", - "es5w949", - "eodp11g", - "eo0kwc9", - "es5yr94", - "esxgdlw", - "ehk4hjz" - ] - } - } - ], - "after": null, - "before": null - } - }, - "user_reports": [], - "saved": false, - "id": "efwmm9z", - "banned_at_utc": null, - "mod_reason_title": null, - "gilded": 0, - "archived": true, - "no_follow": true, - "author": "HappyNumberBot", - "can_mod_post": false, - "send_replies": true, - "parent_id": "t1_eetghdx", - "score": 3, - "author_fullname": "t2_2yz4imzj", - "report_reasons": null, - "approved_by": null, - "all_awardings": [], - "subreddit_id": "t5_2qh23", - "collapsed": false, - "body": "!stats", - "edited": false, - "author_flair_css_class": null, - "is_submitter": false, - "downs": 0, - "author_flair_richtext": [], - "author_patreon_flair": false, - "body_html": "<div class=\"md\"><p>!stats</p>\n</div>", - "gildings": {}, - "collapsed_reason": null, - "associated_award": null, - "stickied": false, - "author_premium": false, - "subreddit_type": "public", - "can_gild": true, - "top_awarded_type": null, - "author_flair_text_color": null, - "score_hidden": false, - "permalink": "/r/test/comments/agi5zf/test/efwmm9z/", - "num_reports": null, - "locked": false, - "name": "t1_efwmm9z", - "created": 1549524051.0, - "subreddit": "test", - "author_flair_text": null, - "treatment_tags": [], - "created_utc": 1549495251.0, - "subreddit_name_prefixed": "r/test", - "controversiality": 0, - "depth": 1, - "author_flair_background_color": null, - "collapsed_because_crowd_control": null, - "mod_reports": [], - "mod_note": null, - "distinguished": null - } - }, - { - "kind": "more", - "data": { - "count": 55, - "name": "t1_egv3v5t", - "id": "egv3v5t", - "parent_id": "t1_eetghdx", - "depth": 1, - "children": [ - "egv3v5t", - "ehf5ll4", - "erycvkn", - "esb18tp", - "erf1yxe", - "eicha8k", - "efygq0v", - "egiwsux", - "elmj995", - "egtg49t", - "esb17ow", - "el5f35i", - "eonmybd", - "eolmt33", - "espv8aq", - "ekn0a01", - "egvklzd", - "ehk3mfk", - "ern08no", - "epcypxz", - "erw1r6g", - "elm21k2", - "el5f8f7", - "en14mp5", - "en4t8mi", - "erw1sdp", - "eghvxg4", - "ekxa456", - "ehh50sf" - ] - } - } - ], - "after": null, - "before": null - } - }, - "user_reports": [], - "saved": false, - "id": "eetghdx", - "banned_at_utc": null, - "mod_reason_title": null, - "gilded": 0, - "archived": true, - "no_follow": true, - "author": "Jcat49er", - "can_mod_post": false, - "send_replies": true, - "parent_id": "t3_agi5zf", - "score": 25, - "author_fullname": "t2_yzlw7", - "report_reasons": null, - "approved_by": null, - "all_awardings": [], - "subreddit_id": "t5_2qh23", - "body": "[r/funny](https://youtu.be/dQw4w9WgXcQ) ", - "edited": false, - "downs": 0, - "author_flair_css_class": null, - "is_submitter": false, - "collapsed": false, - "author_flair_richtext": [], - "author_patreon_flair": false, - "body_html": "<div class=\"md\"><p><a href=\"https://youtu.be/dQw4w9WgXcQ\">r/funny</a> </p>\n</div>", - "gildings": {}, - "collapsed_reason": null, - "associated_award": null, - "stickied": false, - "author_premium": false, - "subreddit_type": "public", - "can_gild": true, - "top_awarded_type": null, - "author_flair_text_color": null, - "score_hidden": false, - "permalink": "/r/test/comments/agi5zf/test/eetghdx/", - "num_reports": null, - "locked": false, - "name": "t1_eetghdx", - "created": 1548328913.0, - "subreddit": "test", - "author_flair_text": null, - "treatment_tags": [], - "created_utc": 1548300113.0, - "subreddit_name_prefixed": "r/test", - "controversiality": 0, - "depth": 0, - "author_flair_background_color": null, - "collapsed_because_crowd_control": null, - "mod_reports": [], - "mod_note": null, - "distinguished": null - } - } - ], - "after": null, - "before": null - } - } -]