Drop chat_enabled from aspects API
This commit is contained in:
parent
9bb1a36e3d
commit
16b242fa0f
5 changed files with 10 additions and 43 deletions
|
|
@ -28,8 +28,8 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
params.require(%i[name chat_enabled])
|
params.require(%i[name])
|
||||||
aspect = current_user.aspects.build(name: params[:name], chat_enabled: params[:chat_enabled])
|
aspect = current_user.aspects.build(name: params[:name])
|
||||||
if aspect&.save
|
if aspect&.save
|
||||||
render json: aspect_as_json(aspect, true)
|
render json: aspect_as_json(aspect, true)
|
||||||
else
|
else
|
||||||
|
|
@ -65,7 +65,7 @@ module Api
|
||||||
private
|
private
|
||||||
|
|
||||||
def aspect_params(allow_order=false)
|
def aspect_params(allow_order=false)
|
||||||
parameters = params.permit(:name, :chat_enabled)
|
parameters = params.permit(:name)
|
||||||
parameters[:order_id] = params[:order] if params.has_key?(:order) && allow_order
|
parameters[:order_id] = params[:order] if params.has_key?(:order) && allow_order
|
||||||
|
|
||||||
parameters
|
parameters
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ class AspectPresenter < BasePresenter
|
||||||
name: @aspect.name
|
name: @aspect.name
|
||||||
}
|
}
|
||||||
values[:order] = @aspect.order_id if with_order
|
values[:order] = @aspect.order_id if with_order
|
||||||
values[:chat_enabled] = @aspect.chat_enabled if full
|
|
||||||
values
|
values
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,9 @@
|
||||||
},
|
},
|
||||||
"order": {
|
"order": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
|
||||||
"chat_enabled": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["id", "name", "order", "chat_enabled"],
|
"required": ["id", "name", "order"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,6 @@ describe Api::V1::AspectsController do
|
||||||
expect(aspect["id"]).to eq(@aspect2.id)
|
expect(aspect["id"]).to eq(@aspect2.id)
|
||||||
expect(aspect["name"]).to eq(@aspect2.name)
|
expect(aspect["name"]).to eq(@aspect2.name)
|
||||||
expect(aspect["order"]).to eq(@aspect2.order_id)
|
expect(aspect["order"]).to eq(@aspect2.order_id)
|
||||||
expect(aspect["chat_enabled"]).to eq(@aspect2.chat_enabled)
|
|
||||||
|
|
||||||
expect(aspect.to_json).to match_json_schema(:api_v1_schema)
|
expect(aspect.to_json).to match_json_schema(:api_v1_schema)
|
||||||
end
|
end
|
||||||
|
|
@ -122,13 +121,12 @@ describe Api::V1::AspectsController do
|
||||||
new_name = "diaspora developers"
|
new_name = "diaspora developers"
|
||||||
post(
|
post(
|
||||||
api_v1_aspects_path,
|
api_v1_aspects_path,
|
||||||
params: {name: new_name, chat_enabled: true, access_token: access_token}
|
params: {name: new_name, access_token: access_token}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
aspect = JSON.parse(response.body)
|
aspect = JSON.parse(response.body)
|
||||||
expect(aspect["name"]).to eq(new_name)
|
expect(aspect["name"]).to eq(new_name)
|
||||||
expect(aspect["chat_enabled"]).to be_truthy
|
|
||||||
expect(aspect.has_key?("id")).to be_truthy
|
expect(aspect.has_key?("id")).to be_truthy
|
||||||
expect(aspect.has_key?("order")).to be_truthy
|
expect(aspect.has_key?("order")).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
@ -136,7 +134,7 @@ describe Api::V1::AspectsController do
|
||||||
it "fails to create duplicate aspect" do
|
it "fails to create duplicate aspect" do
|
||||||
post(
|
post(
|
||||||
api_v1_aspects_path,
|
api_v1_aspects_path,
|
||||||
params: {name: @aspect1.name, chat_enabled: true, access_token: access_token}
|
params: {name: @aspect1.name, access_token: access_token}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).to eq(422)
|
expect(response.status).to eq(422)
|
||||||
|
|
@ -148,17 +146,7 @@ describe Api::V1::AspectsController do
|
||||||
it "fails when missing name" do
|
it "fails when missing name" do
|
||||||
post(
|
post(
|
||||||
api_v1_aspects_path,
|
api_v1_aspects_path,
|
||||||
params: {chat_enabled: true, access_token: access_token}
|
params: {order: 0, access_token: access_token}
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).to eq(422)
|
|
||||||
expect(response.body).to eq(I18n.t("api.endpoint_errors.aspects.cant_create"))
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fails when missing chat" do
|
|
||||||
post(
|
|
||||||
api_v1_aspects_path,
|
|
||||||
params: {name: "new_aspect", access_token: access_token}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).to eq(422)
|
expect(response.status).to eq(422)
|
||||||
|
|
@ -170,7 +158,7 @@ describe Api::V1::AspectsController do
|
||||||
it "fails when not logged in" do
|
it "fails when not logged in" do
|
||||||
post(
|
post(
|
||||||
api_v1_aspects_path,
|
api_v1_aspects_path,
|
||||||
params: {name: "new_name", chat_enabled: true, access_token: invalid_token}
|
params: {name: "new_name", access_token: invalid_token}
|
||||||
)
|
)
|
||||||
expect(response.status).to eq(401)
|
expect(response.status).to eq(401)
|
||||||
end
|
end
|
||||||
|
|
@ -178,7 +166,7 @@ describe Api::V1::AspectsController do
|
||||||
it "fails when logged in read only" do
|
it "fails when logged in read only" do
|
||||||
post(
|
post(
|
||||||
api_v1_aspects_path,
|
api_v1_aspects_path,
|
||||||
params: {name: "new_name", chat_enabled: true, access_token: access_token_read_only}
|
params: {name: "new_name", access_token: access_token_read_only}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).to eq(403)
|
expect(response.status).to eq(403)
|
||||||
|
|
@ -190,17 +178,15 @@ describe Api::V1::AspectsController do
|
||||||
context "with aspect settings" do
|
context "with aspect settings" do
|
||||||
it "updates full aspect" do
|
it "updates full aspect" do
|
||||||
new_name = "NewAspectName"
|
new_name = "NewAspectName"
|
||||||
new_chat = @aspect2.chat_enabled
|
|
||||||
new_order = @aspect2.order_id + 1
|
new_order = @aspect2.order_id + 1
|
||||||
patch(
|
patch(
|
||||||
api_v1_aspect_path(@aspect2.id),
|
api_v1_aspect_path(@aspect2.id),
|
||||||
params: {name: new_name, chat_enabled: new_chat, order: new_order, access_token: access_token}
|
params: {name: new_name, order: new_order, access_token: access_token}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
aspect = JSON.parse(response.body)
|
aspect = JSON.parse(response.body)
|
||||||
expect(aspect["name"]).to eq(new_name)
|
expect(aspect["name"]).to eq(new_name)
|
||||||
expect(aspect["chat_enabled"]).to eq(new_chat)
|
|
||||||
expect(aspect["order"]).to eq(new_order)
|
expect(aspect["order"]).to eq(new_order)
|
||||||
expect(aspect["id"]).to eq(@aspect2.id)
|
expect(aspect["id"]).to eq(@aspect2.id)
|
||||||
end
|
end
|
||||||
|
|
@ -218,19 +204,6 @@ describe Api::V1::AspectsController do
|
||||||
expect(aspect["id"]).to eq(@aspect2.id)
|
expect(aspect["id"]).to eq(@aspect2.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates chat only" do
|
|
||||||
new_chat = @aspect2.chat_enabled
|
|
||||||
patch(
|
|
||||||
api_v1_aspect_path(@aspect2.id),
|
|
||||||
params: {chat_enabled: new_chat, access_token: access_token}
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
|
||||||
aspect = JSON.parse(response.body)
|
|
||||||
expect(aspect["chat_enabled"]).to eq(new_chat)
|
|
||||||
expect(aspect["id"]).to eq(@aspect2.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "updates order only" do
|
it "updates order only" do
|
||||||
new_order = @aspect2.order_id + 1
|
new_order = @aspect2.order_id + 1
|
||||||
patch(
|
patch(
|
||||||
|
|
@ -253,7 +226,6 @@ describe Api::V1::AspectsController do
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
aspect = JSON.parse(response.body)
|
aspect = JSON.parse(response.body)
|
||||||
expect(aspect["name"]).to eq(@aspect2.name)
|
expect(aspect["name"]).to eq(@aspect2.name)
|
||||||
expect(aspect["chat_enabled"]).to eq(@aspect2.chat_enabled)
|
|
||||||
expect(aspect["id"]).to eq(@aspect2.id)
|
expect(aspect["id"]).to eq(@aspect2.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ describe AspectPresenter do
|
||||||
expect(aspect_json[:id]).to eq(@aspect.id)
|
expect(aspect_json[:id]).to eq(@aspect.id)
|
||||||
expect(aspect_json[:name]).to eq(@aspect.name)
|
expect(aspect_json[:name]).to eq(@aspect.name)
|
||||||
expect(aspect_json[:order]).to eq(@aspect.order_id)
|
expect(aspect_json[:order]).to eq(@aspect.order_id)
|
||||||
expect(aspect_json[:chat_enabled]).to eq(@aspect.chat_enabled)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue