Commit 9b5eb2a6 authored by Matija Čupić's avatar Matija Čupić

Add Disqus clickthrough tests

parent 6e6f6f9e
Pipeline #9013979 passed with stage
in 1 minute and 37 seconds
......@@ -95,8 +95,8 @@ module DisqusClient
# @return [String] the Disqus post url
def get_post_url(post_id, api_key)
post_hash = request_post(post_id, api_key)
thread_hash = request_thread(post_hash[:thread])
"#{thread_hash[:link]}/#comment-#{post_id}"
thread_hash = request_thread(post_hash[:thread], api_key)
"#{thread_hash[:link]}#comment-#{post_id}"
end
# Posts a reply to a Disqus post
......
......@@ -4,7 +4,8 @@ class Disqus::ApiController < ApplicationApiController
end
def clickthrough
redirect_to DisqusClient.get_post_url(clickthrough_param)
redirect_to DisqusClient.get_post_url(clickthrough_param,
Rails.configuration.disqus['api_key'])
end
def pull
......
......@@ -63,6 +63,13 @@ class DisqusClientTest < ActiveSupport::TestCase
end
end
test 'should get post url' do
VCR.use_cassette('disqus/get_post_url') do
disqus_url = DisqusClient.get_post_url('3210563331', 'api_key')
assert_match URI.regexp, disqus_url
end
end
test 'should post a reply' do
VCR.use_cassette('disqus/post_reply') do
new_post = DisqusClient.post_reply('sample message', 'parent',
......
require 'test_helper'
class Disqus::ControllerTest < ActionDispatch::IntegrationTest
test 'should get manifest' do
get disqus_manifest_url, params: { format: :json }
assert_template :manifest
end
test 'should get clickthrough' do
VCR.use_cassette('disqus/get_post_url') do
get disqus_clickthrough_url, params: { external_id: '3210563331' }
assert_response :redirect
end
end
test 'should get pull' do
VCR.use_cassette('disqus/sweep_posts') do
post disqus_pull_url, params: {
......@@ -12,11 +24,6 @@ class Disqus::ControllerTest < ActionDispatch::IntegrationTest
end
end
test 'should get manifest' do
get disqus_manifest_url, params: { format: :json }
assert_template :manifest
end
test 'should post channelback' do
VCR.use_cassette('disqus/post_reply') do
post disqus_channelback_url, params: {
......
---
http_interactions:
- request:
method: get
uri: https://disqus.com/api/3.0/posts/details.json?post=3210563331
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
User-Agent:
- DisqusAgent
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Content-Type:
- application/json
X-Ratelimit-Remaining:
- '996'
X-Ratelimit-Limit:
- '1000'
X-Frame-Options:
- SAMEORIGIN
P3p:
- CP="DSP IDC CUR ADM DELi STP NAV COM UNI INT PHY DEM"
X-Ratelimit-Reset:
- '1497452400'
X-Content-Type-Options:
- nosniff
X-Xss-Protection:
- 1; mode=block
Transfer-Encoding:
- chunked
Date:
- Wed, 14 Jun 2017 14:02:51 GMT
Age:
- '0'
Connection:
- keep-alive
Vary:
- Accept-Encoding, Origin, Cookie
Strict-Transport-Security:
- max-age=300; includeSubdomains
body:
encoding: ASCII-8BIT
string: '{"code":0,"response":{"dislikes":0,"numReports":0,"likes":0,"message":"<p>In
the ''Security Notices'' section of the contact page, you have an email field
and a button called ''Subscribe''. If you want to subscribe there, you need
to fill your email in the field and click subscribe.</p><p> <a href=\"https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png\"
rel=\"nofollow noopener\">https://uploads.disquscdn.c...</a></p>","isSpam":false,"isDeleted":false,"author":{"username":"matteeyah","about":"super
hero","name":"Matija \u010cupi\u0107","disable3rdPartyTrackers":false,"isPowerContributor":false,"joinedAt":"2014-09-29T19:38:24","profileUrl":"https://disqus.com/by/matteeyah/","url":"https://cmattrex.com","location":"Belgrade,
Serbia","isPrivate":false,"signedUrl":"https://disq.us/?url=https%3A%2F%2Fcmattrex.com&key=wIIZ5KUGwa5vZMbDMu4WEQ","isPrimary":true,"isAnonymous":false,"id":"123809507","avatar":{"small":{"permalink":"https://disqus.com/api/users/avatars/matteeyah.jpg","cache":"https://c.disquscdn.com/uploads/users/12380/9507/avatar32.jpg?1495772018"},"isCustom":true,"permalink":"https://disqus.com/api/users/avatars/matteeyah.jpg","cache":"https://c.disquscdn.com/uploads/users/12380/9507/avatar92.jpg?1495772018","large":{"permalink":"https://disqus.com/api/users/avatars/matteeyah.jpg","cache":"https://c.disquscdn.com/uploads/users/12380/9507/avatar92.jpg?1495772018"}}},"media":[{"providerName":"Disquscdn","resolvedUrl":"https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","thumbnailUrl":"//uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","htmlHeight":null,"id":23653624,"thumbnailWidth":794,"title":"","htmlWidth":null,"mediaType":"2","html":"","location":"https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","type":"5","metadata":{"create_method":"preview","thumbnail":"//uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png"},"urlRedirect":"https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","description":"","post":"3210563331","thumbnailURL":"//uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","thread":"5641952336","forum":"gitlab","url":"https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","resolvedUrlRedirect":"https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","thumbnailHeight":886}],"id":"3210563331","isDeletedByAuthor":false,"createdAt":"2017-03-18T16:02:56","parent":null,"isApproved":true,"isFlagged":false,"raw_message":"In
the ''Security Notices'' section of the contact page, you have an email field
and a button called ''Subscribe''. If you want to subscribe there, you need
to fill your email in the field and click subscribe.\n\n https://uploads.disquscdn.com/images/9615c5af0190d5079fc7c35d3110f0d268891b689d86268ec9faef2311b7b64d.png","isHighlighted":false,"canVote":false,"thread":"5641952336","forum":"gitlab","points":0,"moderationLabels":[],"isEdited":false,"sb":false}}'
http_version:
recorded_at: Wed, 14 Jun 2017 14:02:51 GMT
- request:
method: get
uri: https://disqus.com/api/3.0/threads/details.json?thread=5641952336
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
User-Agent:
- DisqusAgent
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Content-Type:
- application/json
X-Ratelimit-Remaining:
- '995'
X-Ratelimit-Limit:
- '1000'
Cache-Control:
- stale-while-revalidate=300, public, max-age=60
X-Frame-Options:
- SAMEORIGIN
P3p:
- CP="DSP IDC CUR ADM DELi STP NAV COM UNI INT PHY DEM"
X-Ratelimit-Reset:
- '1497452400'
X-Content-Type-Options:
- nosniff
X-Xss-Protection:
- 1; mode=block
Content-Length:
- '512'
Date:
- Wed, 14 Jun 2017 14:02:52 GMT
Age:
- '0'
Connection:
- keep-alive
Vary:
- Accept-Encoding, Origin, Cookie
Strict-Transport-Security:
- max-age=300; includeSubdomains
body:
encoding: ASCII-8BIT
string: '{"code":0,"response":{"feed":"https://gitlab.disqus.com/gitlab_critical_security_update_pre_announcement/latest.rss","canModerate":false,"clean_title":"Announcement","dislikes":0,"likes":0,"message":"","id":"5641952336","isDeleted":false,"category":"2549428","author":"58555114","userScore":0,"isSpam":false,"signedLink":"https://disq.us/?url=https%3A%2F%2Fabout.gitlab.com%2F2017%2F03%2F17%2Fgitlab-critical-release-preannouncement%2F&key=3zU8spBqTZT2HR7Gz09RvA","createdAt":"2017-03-17T22:48:21","hasStreaming":false,"raw_message":"","isClosed":false,"link":"https://about.gitlab.com/2017/03/17/gitlab-critical-release-preannouncement/","slug":"gitlab_critical_security_update_pre_announcement","forum":"gitlab","identifiers":["https://about.gitlab.com/2017/03/17/gitlab-critical-release-preannouncement/"],"posts":3,"userSubscription":false,"validateAllPosts":false,"title":"
GitLab Critical Security Update Pre-Announcement ","canPost":true,"highlightedPost":null}}'
http_version:
recorded_at: Wed, 14 Jun 2017 14:02:52 GMT
recorded_with: VCR 3.0.3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment