docbrown/spec/requests/follows_create_spec.rb
Ridhwana 5266dd1afb
Showing and hiding tags in the Following and Hidden Tags Pages (#19954)
* feat: remove updated weights

* feat: click on following on the following tags page

* feat: add and listen for the following button click

* fix: dropdowns

* feat: handle hide button click

* feat: update the nav link for following tags

* feat: handel the 'unhide button' on the hidden tags page

* feat: add the styling for the buttons

* feat: add localization

* feat: remove the brand from the card

* feat: add some styling to the page

* feat: init scrolling

* chore: update the name of the file

* feat: abstract out the comment fetch code

* fix: close the attribute

* feta: make some adjustments to where the tag adn the follow show up

* rename class from plural to singular

* feat: updae the comment

* feat: add a mutation observer to initialize the dropdown

* test: follow_craete

* chore: remove irrelevant test

* feat: update the cypress seeds

* feat: update the cypress seeds

* spec: write soem initial tests for the following tags page

* spec: update the unfollow cypress spec

* spec: update the hide cypress spec

* spec: update the posts published spec

* note to add test for pagination

* spec: hidden tags page

* feat: remove aria pressed attributes

* fix: ordering by explicit points gets the page params confused and returns the incorrect and not all results on pagination

* fix: use explicit points

* feat: remove the message at the top of the following and hidden tags page

* chore: remove comment and rather add it to the PR itself

* refactor: do all the actions on success

* feat: refactor the dashboard tag file

* refactor: only show the tagId and followId dataset attributes on the dashboard__tag__container

* feat: disconnect the observer

* chore: add some documentation

* feat: add fr localization

* chore: empty line

* fix: update the dashboardTags page to first declare the observer"
"
"

* fix: update the rails test

* Empty commit

* fix: because I added more tags, the dropdown was longre and covering the body of the editor hence it could not find the text, so I've escaped after selecting my tags
2023-08-25 14:49:39 +02:00

77 lines
2.2 KiB
Ruby

require "rails_helper"
RSpec.describe "Follows #create" do
let(:current_user) { create(:user) }
let(:user) { create(:user) }
let(:tag) { create(:tag) }
let(:headers) { { "Content-Type": "application/json", Accept: "application/json" } }
let(:follow_payload) do
{
followable_type: "User",
followable_id: user.id,
verb: "follow"
}.to_json
end
let(:follow_tag_payload) do
{
followable_type: "Tag",
followable_id: tag.id,
verb: "follow",
explicit_points: -1
}.to_json
end
before do
sign_in current_user
Settings::RateLimit.clear_cache
end
context "when rate limit has been hit" do
before do
rate_limit_checker = RateLimitChecker.new(current_user)
allow(rate_limit_checker)
.to receive(:user_today_follow_count)
.and_return(Settings::RateLimit.follow_count_daily + 1)
allow(RateLimitChecker)
.to receive(:new)
.and_return(rate_limit_checker)
end
it "returns an error for too many follows in a day" do
post "/follows", headers: headers, params: follow_payload
json_response = response.parsed_body
expect(response).to have_http_status(:too_many_requests)
expect(json_response["error"]).to eq("Daily account follow limit reached!")
end
end
context "when follows" do
it "returns followed" do
post "/follows", headers: headers, params: follow_payload
expect(response).to have_http_status(:ok)
expect(response.parsed_body["outcome"]).to eq("followed")
end
it "updates explicit points" do
post "/follows", headers: headers, params: follow_tag_payload
expect(response).to have_http_status(:ok)
expect(response.parsed_body["outcome"]).to eq("followed")
follow = Follow.find_by(followable_id: tag.id, followable_type: "ActsAsTaggableOn::Tag")
expect(follow.explicit_points).to eq(-1.0)
end
end
it "unfollows" do
current_user.follow(user)
post "/follows", headers: headers,
params: { followable_type: "User", followable_id: user.id, verb: "unfollow" }.to_json
expect(response).to have_http_status(:ok)
expect(response.parsed_body["outcome"]).to eq("unfollowed")
end
end