docbrown/spec/requests/followings_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

184 lines
5.8 KiB
Ruby

require "rails_helper"
RSpec.describe "FollowingsController" do
let(:user) { create(:user) }
describe "GET /followings/users" do
let(:followed) { create(:user) }
before do
user.follow(followed)
user.reload
end
context "when user is unauthorized" do
it "returns unauthorized" do
get followings_users_path
expect(response).to have_http_status(:unauthorized)
end
end
context "when user is authorized" do
before do
sign_in user
end
it "returns user's followings list with the correct format" do
get followings_users_path
expect(response).to have_http_status(:ok)
response_following = response.parsed_body.first
expect(response_following["type_of"]).to eq("user_following")
expect(response_following["id"]).to eq(user.follows.last.id)
expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq(followed.path)
expect(response_following["username"]).to eq(followed.username)
expect(response_following["profile_image"]).to eq(followed.profile_image_url_for(length: 60))
end
end
end
describe "GET /followings/tags" do
context "when user is unauthorized" do
let(:followed) { create(:tag) }
before do
user.follow(followed)
user.reload
end
it "returns unauthorized" do
get followings_tags_path
expect(response).to have_http_status(:unauthorized)
end
end
context "when user is authorized" do
let(:first_followed_tag) { create(:tag, name: "tagone") }
let(:antifollowed_tag) { create(:tag, name: "tagtwo") }
let(:second_followed_tag) { create(:tag, name: "tagthree") }
before do
sign_in user
first_followed = user.follow(first_followed_tag)
first_followed.update explicit_points: 5
antifollowed = user.follow(antifollowed_tag)
antifollowed.update explicit_points: -5
second_followed = user.follow(second_followed_tag)
second_followed.update explicit_points: 0
user.reload
end
it "returns the user's followings tag list" do
get followings_tags_path, params: { controller_action: "following_tags" }
expect(response).to have_http_status(:ok)
expect(response.parsed_body.count).to eq(2)
expect(response.parsed_body.pluck("name")).to eq(%w[tagthree tagone])
end
it "returns the user's hidden tag list" do
get followings_tags_path, params: { controller_action: "hidden_tags" }
expect(response).to have_http_status(:ok)
expect(response.parsed_body.count).to eq(1)
expect(response.parsed_body.pluck("name")).to eq(%w[tagtwo])
end
it "returns a list with the correct format" do
get followings_tags_path
expect(response).to have_http_status(:ok)
followed_object = user.follows.detect { |obj| obj["followable_id"] == first_followed_tag.id }
followed_object_response = response.parsed_body.detect { |obj| obj["name"] == "tagone" }
expect(followed_object_response["type_of"]).to eq("tag_following")
expect(followed_object_response["id"]).to eq(followed_object.id)
expect(followed_object_response["name"]).to eq(first_followed_tag.name)
expect(followed_object_response["points"]).to eq(followed_object.points)
expect(followed_object_response["explicit_points"]).to eq(followed_object.explicit_points)
expect(followed_object_response["token"]).to be_present
expect(followed_object_response["color"]).to eq("#000000")
end
end
end
describe "GET /followings/organizations" do
let(:followed) { create(:organization) }
before do
user.follow(followed)
user.reload
end
context "when user is unauthorized" do
it "returns unauthorized" do
get followings_organizations_path
expect(response).to have_http_status(:unauthorized)
end
end
context "when user is authorized" do
before do
sign_in user
end
it "returns user's followings list with the correct format" do
get followings_organizations_path
expect(response).to have_http_status(:ok)
response_following = response.parsed_body.first
expect(response_following["type_of"]).to eq("organization_following")
expect(response_following["id"]).to eq(user.follows.last.id)
expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq(followed.path)
expect(response_following["username"]).to eq(followed.username)
expect(response_following["profile_image"]).to eq(followed.profile_image_url_for(length: 60))
end
end
end
describe "GET /followings/podcasts" do
let(:followed) { create(:podcast) }
before do
user.follow(followed)
user.reload
end
context "when user is unauthorized" do
it "returns unauthorized" do
get followings_podcasts_path
expect(response).to have_http_status(:unauthorized)
end
end
context "when user is authorized" do
before do
sign_in user
end
it "returns user's followings list with the correct format" do
get followings_podcasts_path
expect(response).to have_http_status(:ok)
response_following = response.parsed_body.first
expect(response_following["type_of"]).to eq("podcast_following")
expect(response_following["id"]).to eq(user.follows.last.id)
expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq("/#{followed.path}")
expect(response_following["username"]).to eq(followed.name)
expect(response_following["profile_image"]).to eq(followed.profile_image_url_for(length: 60))
end
end
end
end