Skip to content

Commit

Permalink
Merge branch 'EN-7996-outing-conversation' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-entourage committed Mar 6, 2025
2 parents e814d2b + 51da815 commit 2d1d20c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def privates
.order(updated_at: :desc)
.page(params[:page] || 1).per(per)

render json: privates, root: :privates, each_serializer: ::V1::ConversationSerializer, scope: {
render json: privates, root: :conversations, each_serializer: ::V1::ConversationSerializer, scope: {
user: current_user, include_last_message: true
}
end
Expand Down Expand Up @@ -60,7 +60,7 @@ def outings
.order(updated_at: :desc)
.page(params[:page] || 1).per(per)

render json: outings, root: :outings, each_serializer: ::V1::ConversationSerializer, scope: {
render json: outings, root: :conversations, each_serializer: ::V1::ConversationSerializer, scope: {
user: current_user, include_last_message: true
}
end
Expand Down
60 changes: 30 additions & 30 deletions spec/controllers/api/v1/conversations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@

before { get :privates, params: { token: user.token } }

it { expect(subject["privates"].count).to eq(0) }
it { expect(subject["conversations"].count).to eq(0) }
end

context "actions are not private" do
Expand All @@ -291,7 +291,7 @@

before { get :privates, params: { token: user.token } }

it { expect(subject["privates"].count).to eq(0) }
it { expect(subject["conversations"].count).to eq(0) }
end

describe "some private conversations" do
Expand All @@ -309,59 +309,59 @@

context "name is other participant name when the user is the creator" do
# let(:creator) { user }
it { expect(subject["privates"].count).to eq(1) }
it { expect(subject["privates"][0]["name"]).to eq("Foo B.") }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]["name"]).to eq("Foo B.") }
end

context "name is other participant name when the user is not the creator" do
let(:creator) { other_user }
it { expect(subject["privates"].count).to eq(1) }
it { expect(subject["privates"][0]["name"]).to eq("Foo B.") }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]["name"]).to eq("Foo B.") }
end
end

context "default properties" do
before { get :privates, params: { token: user.token } }
it { expect(subject["privates"].count).to eq(1) }
it { expect(subject["privates"][0]).to have_key("last_message") }
it { expect(subject["privates"][0]).to have_key("number_of_unread_messages") }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]).to have_key("last_message") }
it { expect(subject["conversations"][0]).to have_key("number_of_unread_messages") }
end

context "with unread" do
let!(:chat_message) { FactoryBot.create(:chat_message, created_at: 1.minute.from_now, messageable: conversation)}

before { get :privates, params: { token: user.token } }
it { expect(subject["privates"].first["number_of_unread_messages"]).to eq(1) }
it { expect(subject["conversations"].first["number_of_unread_messages"]).to eq(1) }
end

context "without unread" do
let!(:chat_message) { FactoryBot.create(:chat_message, created_at: 1.minute.ago, messageable: conversation)}

before { get :privates, params: { token: user.token } }
it { expect(subject["privates"].first["number_of_unread_messages"]).to eq(0) }
it { expect(subject["conversations"].first["number_of_unread_messages"]).to eq(0) }
end

context "with last_message" do
let!(:chat_message) { FactoryBot.create(:chat_message, messageable: conversation)}

before { get :privates, params: { token: user.token } }
it { expect(subject["privates"].first["last_message"]).to be_a(Hash) }
it { expect(subject["conversations"].first["last_message"]).to be_a(Hash) }
end

context "with some messages, get last_message" do
let!(:chat_message_1) { FactoryBot.create(:chat_message, messageable: conversation, content: "foo", created_at: 1.hour.ago) }
let!(:chat_message_2) { FactoryBot.create(:chat_message, messageable: conversation, content: "bar", created_at: 2.hours.ago) }

before { get :privates, params: { token: user.token } }
it { expect(subject["privates"].first["last_message"]).to be_a(Hash) }
it { expect(subject["privates"].first["last_message"]["text"]).to eq("foo") }
it { expect(subject["conversations"].first["last_message"]).to be_a(Hash) }
it { expect(subject["conversations"].first["last_message"]["text"]).to eq("foo") }
end

context "without last_message" do
let!(:chat_message) { FactoryBot.create(:chat_message, messageable: other_conversation)}

before { get :privates, params: { token: user.token } }
it { expect(subject["privates"].first["last_message"]).to eq(nil) }
it { expect(subject["conversations"].first["last_message"]).to eq(nil) }
end
end

Expand All @@ -378,8 +378,8 @@
before { request }

it { expect(response.status).to eq(200) }
it { expect(subject["privates"].count).to eq(1) }
it { expect(subject["privates"][0]['blockers']).to match_array([ "me" ]) }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]['blockers']).to match_array([ "me" ]) }
end

context 'participant blocked' do
Expand All @@ -388,8 +388,8 @@
before { request }

it { expect(response.status).to eq(200) }
it { expect(subject["privates"].count).to eq(1) }
it { expect(subject["privates"][0]['blockers']).to match_array([ "participant" ]) }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]['blockers']).to match_array([ "participant" ]) }
end

context 'both blocked' do
Expand All @@ -399,8 +399,8 @@
before { request }

it { expect(response.status).to eq(200) }
it { expect(subject["privates"].count).to eq(1) }
it { expect(subject["privates"][0]['blockers']).to match_array([ "me", "participant" ]) }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]['blockers']).to match_array([ "me", "participant" ]) }
end
end
end
Expand Down Expand Up @@ -477,52 +477,52 @@

context "default properties" do
before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].count).to eq(1) }
it { expect(subject["outings"][0]).to have_key("last_message") }
it { expect(subject["outings"][0]).to have_key("number_of_unread_messages") }
it { expect(subject["conversations"].count).to eq(1) }
it { expect(subject["conversations"][0]).to have_key("last_message") }
it { expect(subject["conversations"][0]).to have_key("number_of_unread_messages") }
end

context "with unread" do
let!(:chat_message) { FactoryBot.create(:chat_message, created_at: 1.minute.from_now, messageable: entourage)}

before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].first["number_of_unread_messages"]).to eq(1) }
it { expect(subject["conversations"].first["number_of_unread_messages"]).to eq(1) }
end

context "without unread" do
let!(:chat_message) { FactoryBot.create(:chat_message, created_at: 1.minute.ago, messageable: entourage)}

before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].first["number_of_unread_messages"]).to eq(0) }
it { expect(subject["conversations"].first["number_of_unread_messages"]).to eq(0) }
end

context "with last_message" do
let!(:chat_message) { FactoryBot.create(:chat_message, messageable: entourage)}

before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].first["last_message"]).to be_a(Hash) }
it { expect(subject["conversations"].first["last_message"]).to be_a(Hash) }
end

context "without last_message" do
let!(:chat_message) { FactoryBot.create(:chat_message, messageable: other_entourage)}

before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].first["last_message"]).to eq(nil) }
it { expect(subject["conversations"].first["last_message"]).to eq(nil) }
end
end

context "no outings conversations" do
let!(:join_request) { FactoryBot.create(:join_request, joinable: entourage, user: other_user, status: "accepted") }

before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].count).to eq(0) }
it { expect(subject["conversations"].count).to eq(0) }
end

context "outings conversations are not accepted" do
let!(:join_request) { FactoryBot.create(:join_request, joinable: entourage, user: user, status: "pending") }

before { get :outings, params: { token: user.token } }
it { expect(subject["outings"].count).to eq(0) }
it { expect(subject["conversations"].count).to eq(0) }
end
end

Expand Down

0 comments on commit 2d1d20c

Please sign in to comment.