1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe "projectBlobsRemove", feature_category: :source_code_management do
include GraphqlHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user, owner_of: project) }
let_it_be(:repo) { project.repository }
let(:project_path) { project.full_path }
let(:mutation_params) { { project_path: project_path, blob_oids: blob_oids } }
let(:mutation) { graphql_mutation(:project_blobs_remove, mutation_params) }
let(:blob_oids) { ['53855584db773c3df5b5f61f72974cb298822fbb'] }
subject(:post_mutation) { post_graphql_mutation(mutation, current_user: current_user) }
describe 'Removing blobs:' do
it 'processes text redaction asynchoronously' do
expect(Repositories::RewriteHistoryWorker).to receive(:perform_async).with(
project_id: project.id, user_id: current_user.id, blob_oids: blob_oids, redactions: []
)
post_mutation
expect(graphql_mutation_response(:project_blobs_remove)['errors']).not_to be_present
end
end
describe 'Invalid requests:' do
context 'when the current_user is a maintainer' do
let(:current_user) { create(:user, maintainer_of: project) }
it_behaves_like 'a mutation on an unauthorized resource'
end
context 'when arg `projectPath` is invalid' do
let(:project_path) { 'gid://Gitlab/User/1' }
it 'returns an error' do
post_mutation
expect(graphql_errors).to include(a_hash_including('message' => <<~MESSAGE.strip))
The resource that you are attempting to access does not exist or you don't have permission to perform this action
MESSAGE
end
end
context 'when arg `blob_oids` is nil' do
let(:blob_oids) { nil }
it 'returns an error' do
post_mutation
expect(graphql_errors).to include(a_hash_including('message' => <<~MESSAGE.strip))
Variable $projectBlobsRemoveInput of type projectBlobsRemoveInput! was provided invalid value for blobOids (Expected value to not be null)
MESSAGE
end
end
context 'when arg `blob_oids` is an empty list' do
let(:blob_oids) { [] }
it 'returns an error' do
post_mutation
expect(graphql_errors).to include(a_hash_including('message' => <<~MESSAGE))
Argument 'blobOids' on InputObject 'projectBlobsRemoveInput' is required. Expected type [String!]!
MESSAGE
end
end
context 'when arg `blob_oids` does not contain any valid strings' do
let(:blob_oids) { ["", ""] }
it 'returns an error' do
post_mutation
expect(graphql_errors).to include(a_hash_including('message' => <<~MESSAGE))
Argument 'blobOids' on InputObject 'projectBlobsRemoveInput' is required. Expected type [String!]!
MESSAGE
end
end
end
end
|