debian-mirror-gitlab/spec/requests/api/graphql/mutations/boards/destroy_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.9 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Boards::Destroy do
include GraphqlHelpers
let_it_be(:current_user, reload: true) { create(:user) }
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:board) { create(:board, project: project) }
2021-06-08 01:23:25 +05:30
let_it_be(:other_board, refind: true) { create(:board, project: project) }
2020-11-24 15:15:51 +05:30
let(:mutation) do
variables = {
id: GitlabSchema.id_from_object(board).to_s
}
graphql_mutation(:destroy_board, variables)
end
subject { post_graphql_mutation(mutation, current_user: current_user) }
def mutation_response
graphql_mutation_response(:destroy_board)
end
context 'when the user does not have permission' do
it_behaves_like 'a mutation that returns a top-level access error'
it 'does not destroy the board' do
expect { subject }.not_to change { Board.count }
end
end
context 'when the user has permission' do
before do
project.add_maintainer(current_user)
end
context 'when given id is not for a board' do
let_it_be(:board) { build_stubbed(:issue, project: project) }
it 'returns an error' do
subject
expect(graphql_errors.first['message']).to include('does not represent an instance of Board')
end
end
context 'when everything is ok' do
it 'destroys the board' do
expect { subject }.to change { Board.count }.from(2).to(1)
end
it 'returns an empty board' do
post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response).to have_key('board')
expect(mutation_response['board']).to be_nil
end
end
context 'when there is only 1 board for the parent' do
before do
other_board.destroy!
end
2022-08-27 11:52:29 +05:30
it 'does destroy the board' do
expect { subject }.to change { Board.count }.by(-1)
2020-11-24 15:15:51 +05:30
end
end
end
end