2020-05-05 05:09:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Resolvers::BranchCommitResolver do
|
2020-05-05 05:09:37 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
subject(:commit) { resolve(described_class, obj: branch) }
|
|
|
|
|
|
|
|
let_it_be(:repository) { create(:project, :repository).repository }
|
|
|
|
let(:branch) { repository.find_branch('master') }
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
it 'resolves commit' do
|
2021-03-12 16:09:12 -05:00
|
|
|
expect(sync(commit)).to eq(repository.commits('master', limit: 1).last)
|
2020-05-05 05:09:37 -04:00
|
|
|
end
|
|
|
|
|
2021-03-09 07:08:52 -05:00
|
|
|
it 'sets project container' do
|
2021-03-12 16:09:12 -05:00
|
|
|
expect(sync(commit).container).to eq(repository.project)
|
2021-03-09 07:08:52 -05:00
|
|
|
end
|
|
|
|
|
2020-05-05 05:09:37 -04:00
|
|
|
context 'when branch does not exist' do
|
|
|
|
let(:branch) { nil }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
2021-03-12 16:09:12 -05:00
|
|
|
|
|
|
|
it 'is N+1 safe' do
|
|
|
|
commit_a = repository.commits('master', limit: 1).last
|
|
|
|
commit_b = repository.commits('spooky-stuff', limit: 1).last
|
|
|
|
|
|
|
|
commits = batch_sync(max_queries: 1) do
|
|
|
|
[
|
|
|
|
resolve(described_class, obj: branch),
|
|
|
|
resolve(described_class, obj: repository.find_branch('spooky-stuff'))
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(commits).to contain_exactly(commit_a, commit_b)
|
|
|
|
end
|
2020-05-05 05:09:37 -04:00
|
|
|
end
|
|
|
|
end
|