Merge conv deletion and visibility deletion
This commit is contained in:
parent
bbbe3aea7f
commit
3f00195eed
4 changed files with 56 additions and 126 deletions
|
|
@ -1,32 +0,0 @@
|
|||
module Api
|
||||
module V0
|
||||
class ConversationVisibilitiesController < Api::V0::BaseController
|
||||
before_action only: %i(destroy) do
|
||||
require_access_token %w(read write)
|
||||
end
|
||||
|
||||
rescue_from ActiveRecord::RecordNotFound do
|
||||
render json: {error: I18n.t("conversations.not_found")}, status: 404
|
||||
end
|
||||
|
||||
def destroy
|
||||
vis = conversation_service.get_visibility(params[:conversation_id])
|
||||
participants = vis.conversation.participants.count
|
||||
vis.destroy!
|
||||
if participants == 1
|
||||
render json: {
|
||||
message: I18n.t("conversations.destroy.delete_success")
|
||||
}
|
||||
else
|
||||
render json: {
|
||||
message: I18n.t("conversations.destroy.hide_success")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def conversation_service
|
||||
ConversationService.new(current_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -45,7 +45,8 @@ module Api
|
|||
end
|
||||
|
||||
def destroy
|
||||
conversation_service.destroy!(params[:id])
|
||||
vis = conversation_service.get_visibility(params[:id])
|
||||
vis.destroy!
|
||||
head :no_content
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Api::V0::ConversationVisibilitiesController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let(:auth_participant) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
let!(:access_token_participant) { auth_participant.create_access_token.to_s }
|
||||
|
||||
before do
|
||||
auth.user.seed_aspects
|
||||
auth.user.share_with auth_participant.user.person, auth.user.aspects[1]
|
||||
auth_participant.user.share_with(
|
||||
auth.user.person, auth_participant.user.aspects[0]
|
||||
)
|
||||
|
||||
@conversation = {
|
||||
author_id: auth.user.id,
|
||||
subject: "new conversation",
|
||||
text: "first message",
|
||||
messages: [{
|
||||
author: auth.user,
|
||||
text: "first message"
|
||||
}],
|
||||
recipients: [auth_participant.user.person.id],
|
||||
access_token: access_token
|
||||
}
|
||||
end
|
||||
|
||||
describe "#destroy " do
|
||||
before do
|
||||
post api_v0_conversations_path, @conversation
|
||||
@conversation_id = JSON.parse(response.body)["conversation"]["id"]
|
||||
end
|
||||
|
||||
context "destroy" do
|
||||
it "destroys the first participant visibility" do
|
||||
delete(
|
||||
api_v0_conversation_visibility_path(@conversation_id),
|
||||
access_token: access_token
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
expect(JSON.parse(response.body)["message"]).to_not be_nil
|
||||
|
||||
get api_v0_conversation_path(
|
||||
@conversation_id,
|
||||
access_token: access_token
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
|
||||
get api_v0_conversation_path(
|
||||
@conversation_id,
|
||||
access_token: access_token_participant
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy again" do
|
||||
it "destroys the second participant visibilty and the conversation" do
|
||||
delete(
|
||||
api_v0_conversation_visibility_path(@conversation_id),
|
||||
access_token: access_token
|
||||
)
|
||||
delete(
|
||||
api_v0_conversation_visibility_path(@conversation_id),
|
||||
access_token: access_token_participant
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
expect(JSON.parse(response.body)["message"]).to_not be_nil
|
||||
|
||||
get api_v0_conversation_path(
|
||||
@conversation_id,
|
||||
access_token: access_token_participant
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
|
||||
expect {
|
||||
Conversation.find(@conversation_id)
|
||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -3,6 +3,8 @@ require "spec_helper"
|
|||
describe Api::V0::ConversationsController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
let(:auth_participant) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token_participant) { auth_participant.create_access_token.to_s }
|
||||
|
||||
before do
|
||||
auth.user.share_with bob.person, auth.user.aspects[0]
|
||||
|
|
@ -86,24 +88,66 @@ describe Api::V0::ConversationsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#delete" do
|
||||
context "valid conversation GUID" do
|
||||
before do
|
||||
post api_v0_conversations_path, @conversation
|
||||
end
|
||||
describe "#destroy " do
|
||||
before do
|
||||
auth.user.seed_aspects
|
||||
auth.user.share_with auth_participant.user.person, auth.user.aspects[1]
|
||||
auth_participant.user.share_with(
|
||||
auth.user.person, auth_participant.user.aspects[0]
|
||||
)
|
||||
|
||||
it "deletes the conversation" do
|
||||
conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
@conversation = {
|
||||
author_id: auth.user.id,
|
||||
subject: "new conversation",
|
||||
body: "first message",
|
||||
recipients: [auth_participant.user.person.id],
|
||||
access_token: access_token
|
||||
}
|
||||
post api_v0_conversations_path, @conversation
|
||||
@conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
end
|
||||
|
||||
context "destroy" do
|
||||
it "destroys the first participant visibility" do
|
||||
delete(
|
||||
api_v0_conversation_path(conversation_guid),
|
||||
api_v0_conversation_path(@conversation_guid),
|
||||
access_token: access_token
|
||||
)
|
||||
expect(response.status).to eq 204
|
||||
get(
|
||||
api_v0_conversation_path(conversation_guid),
|
||||
get api_v0_conversation_path(
|
||||
@conversation_guid,
|
||||
access_token: access_token
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
get api_v0_conversation_path(
|
||||
@conversation_guid,
|
||||
access_token: access_token_participant
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy all visibilities" do
|
||||
it "destroys the second participant visibilty and the conversation" do
|
||||
delete(
|
||||
api_v0_conversation_path(@conversation_guid),
|
||||
access_token: access_token
|
||||
)
|
||||
delete(
|
||||
api_v0_conversation_path(@conversation_guid),
|
||||
access_token: access_token_participant
|
||||
)
|
||||
expect(response.status).to eq 204
|
||||
|
||||
get api_v0_conversation_path(
|
||||
@conversation_guid,
|
||||
access_token: access_token_participant
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
|
||||
expect {
|
||||
Conversation.find({guid: @conversation_guid})
|
||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue