Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJonne Haß <me@jhass.eu>2020-02-02 21:58:36 +0300
committerJonne Haß <me@jhass.eu>2020-02-02 23:49:20 +0300
commit2e7526bac53400e85c4cf01f9cd0598297c0fafc (patch)
tree9dc49137cbc70282f12300ba262f1d2437a20331 /spec
parentdcbd02cf7f810c0ea93ed54b968849ef0fd73a7b (diff)
API: Let hide endpoint take payload as documented and act according to it
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/api/post_interactions_controller_spec.rb97
1 files changed, 80 insertions, 17 deletions
diff --git a/spec/integration/api/post_interactions_controller_spec.rb b/spec/integration/api/post_interactions_controller_spec.rb
index d388e8a82..2e785029a 100644
--- a/spec/integration/api/post_interactions_controller_spec.rb
+++ b/spec/integration/api/post_interactions_controller_spec.rb
@@ -25,6 +25,7 @@ describe Api::V1::PostInteractionsController do
let!(:access_token_public_only) { auth_public_only.create_access_token.to_s }
let!(:access_token_minimum_scopes) { auth_minimum_scopes.create_access_token.to_s }
let(:invalid_token) { SecureRandom.hex(9) }
+ let(:headers) { {"Authorization" => "Bearer #{access_token}"} }
before do
@status = alice.post(
@@ -118,17 +119,42 @@ describe Api::V1::PostInteractionsController do
end
describe "#hide" do
+ def hidden_shareables_count
+ auth.user.reload.hidden_shareables.values.map(&:size).inject(0, :+)
+ end
+
context "succeeds" do
it "with proper guid and access token" do
- hidden_count = auth.user.hidden_shareables.count
+ hidden_count = hidden_shareables_count
post(
api_v1_post_hide_path(@status.guid),
- params: {
- access_token: access_token
- }
+ as: :json,
+ headers: headers,
+ params: {hide: true}
+ )
+ expect(response.status).to eq(204)
+ expect(hidden_shareables_count).to eq(hidden_count + 1)
+ end
+
+ it "to unhide a post" do
+ hidden_count = hidden_shareables_count
+ post(
+ api_v1_post_hide_path(@status.guid),
+ as: :json,
+ headers: headers,
+ params: {hide: true}
+ )
+ expect(response.status).to eq(204)
+ expect(hidden_shareables_count).to eq(hidden_count + 1)
+
+ post(
+ api_v1_post_hide_path(@status.guid),
+ as: :json,
+ headers: headers,
+ params: {hide: false}
)
expect(response.status).to eq(204)
- expect(auth.user.reload.hidden_shareables.count).to eq(hidden_count + 1)
+ expect(hidden_shareables_count).to eq(hidden_count)
end
end
@@ -136,19 +162,56 @@ describe Api::V1::PostInteractionsController do
it "with improper guid" do
post(
api_v1_post_hide_path("999_999_999"),
- params: {
- access_token: access_token
- }
+ as: :json,
+ headers: headers,
+ params: {hide: true}
)
confirm_api_error(response, 404, "Post with provided guid could not be found")
end
+ it "without hide param" do
+ post(
+ api_v1_post_hide_path(@status.guid),
+ as: :json,
+ headers: headers
+ )
+ confirm_api_error(response, 422, "Missing parameter")
+ end
+
+ it "hiding already hidden post" do
+ post(
+ api_v1_post_hide_path(@status.guid),
+ as: :json,
+ headers: headers,
+ params: {hide: true}
+ )
+ expect(response.status).to eq(204)
+
+ post(
+ api_v1_post_hide_path(@status.guid),
+ as: :json,
+ headers: headers,
+ params: {hide: true}
+ )
+ confirm_api_error(response, 409, "Post already hidden")
+ end
+
+ it "unhiding not hidden post" do
+ post(
+ api_v1_post_hide_path(@status.guid),
+ as: :json,
+ headers: headers,
+ params: {hide: false}
+ )
+ confirm_api_error(response, 410, "Post not hidden")
+ end
+
it "with insufficient token" do
post(
api_v1_post_hide_path(@status.guid),
- params: {
- access_token: access_token_minimum_scopes
- }
+ as: :json,
+ headers: {"Authorization" => "Bearer #{access_token_minimum_scopes}"},
+ params: {hide: true}
)
expect(response.status).to eq(403)
end
@@ -156,9 +219,9 @@ describe Api::V1::PostInteractionsController do
it "on private post without private token" do
post(
api_v1_post_hide_path(@shared_post.guid),
- params: {
- access_token: access_token_public_only
- }
+ as: :json,
+ headers: {"Authorization" => "Bearer #{access_token_public_only}"},
+ params: {hide: true}
)
expect(response.status).to eq(404)
end
@@ -166,9 +229,9 @@ describe Api::V1::PostInteractionsController do
it "with invalid token" do
post(
api_v1_post_hide_path(@status.guid),
- params: {
- access_token: invalid_token
- }
+ as: :json,
+ headers: {"Authorization" => "Bearer #{invalid_token}"},
+ params: {hide: true}
)
expect(response.status).to eq(401)
end