Commit 926bf71e authored by Luke Duncalfe's avatar Luke Duncalfe

Improve specs for Issues and Notes controllers

This adds test that Todos are completed.

https://gitlab.com/gitlab-org/gitlab-ce/issues/63372
parent 15b02da6
...@@ -1104,18 +1104,39 @@ describe Projects::IssuesController do ...@@ -1104,18 +1104,39 @@ describe Projects::IssuesController do
project.add_developer(user) project.add_developer(user)
end end
subject do
post(:toggle_award_emoji, params: {
namespace_id: project.namespace,
project_id: project,
id: issue.iid,
name: emoji_name
})
end
let(:emoji_name) { 'thumbsup' }
it "toggles the award emoji" do it "toggles the award emoji" do
expect do expect do
post(:toggle_award_emoji, params: { subject
namespace_id: project.namespace,
project_id: project,
id: issue.iid,
name: "thumbsup"
})
end.to change { issue.award_emoji.count }.by(1) end.to change { issue.award_emoji.count }.by(1)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
it "removes the already awarded emoji" do
create(:award_emoji, awardable: issue, name: emoji_name, user: user)
expect { subject }.to change { AwardEmoji.count }.by(-1)
expect(response).to have_gitlab_http_status(200)
end
it 'marks Todos on the Issue as done' do
todo = create(:todo, target: issue, project: project, user: user)
subject
expect(todo.reload).to be_done
end
end end
describe 'POST create_merge_request' do describe 'POST create_merge_request' do
......
...@@ -543,23 +543,32 @@ describe Projects::NotesController do ...@@ -543,23 +543,32 @@ describe Projects::NotesController do
project.add_developer(user) project.add_developer(user)
end end
subject { post(:toggle_award_emoji, params: request_params.merge(name: emoji_name)) }
let(:emoji_name) { 'thumbsup' }
it "toggles the award emoji" do it "toggles the award emoji" do
expect do expect do
post(:toggle_award_emoji, params: request_params.merge(name: "thumbsup")) subject
end.to change { note.award_emoji.count }.by(1) end.to change { note.award_emoji.count }.by(1)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
it "removes the already awarded emoji" do it "removes the already awarded emoji" do
post(:toggle_award_emoji, params: request_params.merge(name: "thumbsup")) create(:award_emoji, awardable: note, name: emoji_name, user: user)
expect do expect { subject }.to change { AwardEmoji.count }.by(-1)
post(:toggle_award_emoji, params: request_params.merge(name: "thumbsup"))
end.to change { AwardEmoji.count }.by(-1)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
it 'marks Todos on the Noteable as done' do
todo = create(:todo, target: note.noteable, project: project, user: user)
subject
expect(todo.reload).to be_done
end
end end
describe "resolving and unresolving" do describe "resolving and unresolving" do
......
...@@ -155,6 +155,14 @@ describe API::AwardEmoji do ...@@ -155,6 +155,14 @@ describe API::AwardEmoji do
expect(json_response['user']['username']).to eq(user.username) expect(json_response['user']['username']).to eq(user.username)
end end
it 'marks Todos on the Issue as done' do
todo = create(:todo, target: issue, project: project, user: user)
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user), params: { name: '8ball' }
expect(todo.reload).to be_done
end
it "returns a 400 bad request error if the name is not given" do it "returns a 400 bad request error if the name is not given" do
post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user) post api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user)
...@@ -209,6 +217,14 @@ describe API::AwardEmoji do ...@@ -209,6 +217,14 @@ describe API::AwardEmoji do
expect(json_response['user']['username']).to eq(user.username) expect(json_response['user']['username']).to eq(user.username)
end end
it 'marks Todos on the Noteable as done' do
todo = create(:todo, target: note2.noteable, project: project, user: user)
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: 'rocket' }
expect(todo.reload).to be_done
end
it "normalizes +1 as thumbsup award" do it "normalizes +1 as thumbsup award" do
post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: '+1' } post api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{note.id}/award_emoji", user), params: { name: '+1' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment