diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-25 18:06:04 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-25 18:06:04 +0000 |
commit | 801ced25ff0540b096c395f9ac8d2d9e005878e8 (patch) | |
tree | 4f3ee19fd0facc1bcda8b93881981ab3315b9658 /spec | |
parent | ed9c54b56af280cc552aaac1cfa55533c900c1be (diff) | |
download | gitlab-ce-801ced25ff0540b096c395f9ac8d2d9e005878e8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
4 files changed, 111 insertions, 128 deletions
diff --git a/spec/frontend/repository/utils/dom_spec.js b/spec/frontend/repository/utils/dom_spec.js index 678d444904d..bf98a9e1a4d 100644 --- a/spec/frontend/repository/utils/dom_spec.js +++ b/spec/frontend/repository/utils/dom_spec.js @@ -1,5 +1,5 @@ import { setHTMLFixture } from '../../helpers/fixtures'; -import { updateElementsVisibility } from '~/repository/utils/dom'; +import { updateElementsVisibility, updateFormAction } from '~/repository/utils/dom'; describe('updateElementsVisibility', () => { it('adds hidden class', () => { @@ -18,3 +18,13 @@ describe('updateElementsVisibility', () => { expect(document.querySelector('.js-test').classList).not.toContain('hidden'); }); }); + +describe('updateFormAction', () => { + it('updates form action', () => { + setHTMLFixture('<form class="js-test" action="/"></form>'); + + updateFormAction('.js-test', '/gitlab/create', '/test'); + + expect(document.querySelector('.js-test').action).toBe('http://localhost/gitlab/create/test'); + }); +}); diff --git a/spec/graphql/mutations/issues/set_due_date_spec.rb b/spec/graphql/mutations/issues/set_due_date_spec.rb new file mode 100644 index 00000000000..9a1f0925fe3 --- /dev/null +++ b/spec/graphql/mutations/issues/set_due_date_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Mutations::Issues::SetDueDate do + let(:issue) { create(:issue) } + let(:user) { create(:user) } + subject(:mutation) { described_class.new(object: nil, context: { current_user: user }) } + + describe '#resolve' do + let(:due_date) { 2.days.since } + let(:mutated_issue) { subject[:issue] } + subject { mutation.resolve(project_path: issue.project.full_path, iid: issue.iid, due_date: due_date) } + + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + + context 'when the user can update the issue' do + before do + issue.project.add_developer(user) + end + + it 'returns the issue with updated due date' do + expect(mutated_issue).to eq(issue) + expect(mutated_issue.due_date).to eq(Date.today + 2.days) + expect(subject[:errors]).to be_empty + end + + context 'when passing incorrect due date value' do + let(:due_date) { 'test' } + + it 'does not update due date' do + expect(mutated_issue.due_date).to eq(issue.due_date) + end + end + end + end +end diff --git a/spec/lib/gitlab/graphql/connections/keyset/legacy_keyset_connection_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/legacy_keyset_connection_spec.rb deleted file mode 100644 index aaf28fed684..00000000000 --- a/spec/lib/gitlab/graphql/connections/keyset/legacy_keyset_connection_spec.rb +++ /dev/null @@ -1,127 +0,0 @@ -# frozen_string_literal: true - -# TODO https://gitlab.com/gitlab-org/gitlab/issues/35104 -require 'spec_helper' - -describe Gitlab::Graphql::Connections::Keyset::LegacyKeysetConnection do - describe 'old keyset_connection' do - let(:described_class) { Gitlab::Graphql::Connections::Keyset::Connection } - let(:nodes) { Project.all.order(id: :asc) } - let(:arguments) { {} } - subject(:connection) do - described_class.new(nodes, arguments, max_page_size: 3) - end - - before do - stub_feature_flags(graphql_keyset_pagination: false) - end - - def encoded_property(value) - Base64Bp.urlsafe_encode64(value.to_s, padding: false) - end - - describe '#cursor_from_nodes' do - let(:project) { create(:project) } - - it 'returns an encoded ID' do - expect(connection.cursor_from_node(project)) - .to eq(encoded_property(project.id)) - end - - context 'when an order was specified' do - let(:nodes) { Project.order(:updated_at) } - - it 'returns the encoded value of the order' do - expect(connection.cursor_from_node(project)) - .to eq(encoded_property(project.updated_at)) - end - end - end - - describe '#sliced_nodes' do - let(:projects) { create_list(:project, 4) } - - context 'when before is passed' do - let(:arguments) { { before: encoded_property(projects[1].id) } } - - it 'only returns the project before the selected one' do - expect(subject.sliced_nodes).to contain_exactly(projects.first) - end - - context 'when the sort order is descending' do - let(:nodes) { Project.all.order(id: :desc) } - - it 'returns the correct nodes' do - expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1]) - end - end - end - - context 'when after is passed' do - let(:arguments) { { after: encoded_property(projects[1].id) } } - - it 'only returns the project before the selected one' do - expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1]) - end - - context 'when the sort order is descending' do - let(:nodes) { Project.all.order(id: :desc) } - - it 'returns the correct nodes' do - expect(subject.sliced_nodes).to contain_exactly(projects.first) - end - end - end - - context 'when both before and after are passed' do - let(:arguments) do - { - after: encoded_property(projects[1].id), - before: encoded_property(projects[3].id) - } - end - - it 'returns the expected set' do - expect(subject.sliced_nodes).to contain_exactly(projects[2]) - end - end - end - - describe '#paged_nodes' do - let!(:projects) { create_list(:project, 5) } - - it 'returns the collection limited to max page size' do - expect(subject.paged_nodes.size).to eq(3) - end - - it 'is a loaded memoized array' do - expect(subject.paged_nodes).to be_an(Array) - expect(subject.paged_nodes.object_id).to eq(subject.paged_nodes.object_id) - end - - context 'when `first` is passed' do - let(:arguments) { { first: 2 } } - - it 'returns only the first elements' do - expect(subject.paged_nodes).to contain_exactly(projects.first, projects.second) - end - end - - context 'when `last` is passed' do - let(:arguments) { { last: 2 } } - - it 'returns only the last elements' do - expect(subject.paged_nodes).to contain_exactly(projects[3], projects[4]) - end - end - - context 'when both are passed' do - let(:arguments) { { first: 2, last: 2 } } - - it 'raises an error' do - expect { subject.paged_nodes }.to raise_error(Gitlab::Graphql::Errors::ArgumentError) - end - end - end - end -end diff --git a/spec/requests/api/graphql/mutations/issues/set_due_date_spec.rb b/spec/requests/api/graphql/mutations/issues/set_due_date_spec.rb new file mode 100644 index 00000000000..1efa9e16233 --- /dev/null +++ b/spec/requests/api/graphql/mutations/issues/set_due_date_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Setting Due Date of an issue' do + include GraphqlHelpers + + let(:current_user) { create(:user) } + let(:issue) { create(:issue) } + let(:project) { issue.project } + let(:input) { { due_date: 2.days.since } } + + let(:mutation) do + variables = { + project_path: project.full_path, + iid: issue.iid.to_s + } + graphql_mutation(:issue_set_due_date, variables.merge(input), + <<-QL.strip_heredoc + clientMutationId + errors + issue { + iid + dueDate + } + QL + ) + end + + def mutation_response + graphql_mutation_response(:issue_set_due_date) + end + + before do + project.add_developer(current_user) + end + + it 'returns an error if the user is not allowed to update the issue' do + error = "The resource that you are attempting to access does not exist or you don't have permission to perform this action" + post_graphql_mutation(mutation, current_user: create(:user)) + + expect(graphql_errors).to include(a_hash_including('message' => error)) + end + + it 'updates the issue due date' do + post_graphql_mutation(mutation, current_user: current_user) + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response['issue']['dueDate']).to eq(2.days.since.to_date.to_s) + end + + context 'when passing due date without a date value' do + let(:input) { { due_date: 'test' } } + + it 'returns internal server error' do + post_graphql_mutation(mutation, current_user: current_user) + + expect(graphql_errors).to include(a_hash_including('message' => 'Internal server error')) + end + end +end |