Commit 95325c6a authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'refactor-verify-pages-domain-specs' into 'master'

Refactor verify_pages_domain_service specs

See merge request gitlab-org/gitlab-ce!26178
parents 775ae9f9 c29f4416
...@@ -9,7 +9,6 @@ describe VerifyPagesDomainService do ...@@ -9,7 +9,6 @@ describe VerifyPagesDomainService do
subject(:service) { described_class.new(domain) } subject(:service) { described_class.new(domain) }
describe '#execute' do describe '#execute' do
context 'verification code recognition (verified domain)' do
where(:domain_sym, :code_sym) do where(:domain_sym, :code_sym) do
:domain | :verification_code :domain | :verification_code
:domain | :keyed_verification_code :domain | :keyed_verification_code
...@@ -19,80 +18,123 @@ describe VerifyPagesDomainService do ...@@ -19,80 +18,123 @@ describe VerifyPagesDomainService do
end end
with_them do with_them do
set(:domain) { create(:pages_domain) }
let(:domain_name) { domain.send(domain_sym) } let(:domain_name) { domain.send(domain_sym) }
let(:verification_code) { domain.send(code_sym) } let(:verification_code) { domain.send(code_sym) }
shared_examples 'verifies and enables the domain' do
it 'verifies and enables the domain' do it 'verifies and enables the domain' do
stub_resolver(domain_name => ['something else', verification_code])
expect(service.execute).to eq(status: :success) expect(service.execute).to eq(status: :success)
expect(domain).to be_verified expect(domain).to be_verified
expect(domain).to be_enabled expect(domain).to be_enabled
end end
end
shared_examples 'successful enablement and verification' do
context 'when txt record contains verification code' do
before do
stub_resolver(domain_name => ['something else', verification_code])
end
include_examples 'verifies and enables the domain'
end
it 'verifies and enables when the code is contained partway through a TXT record' do context 'when txt record contains verification code with other text' do
before do
stub_resolver(domain_name => "something #{verification_code} else") stub_resolver(domain_name => "something #{verification_code} else")
end
expect(service.execute).to eq(status: :success) include_examples 'verifies and enables the domain'
expect(domain).to be_verified end
expect(domain).to be_enabled
end end
it 'does not verify when the code is not present' do context 'when domain is disabled(or new)' do
stub_resolver(domain_name => 'something else') let(:domain) { create(:pages_domain, :disabled) }
include_examples 'successful enablement and verification'
shared_examples 'unverifies and disables domain' do
it 'unverifies and disables domain' do
expect(service.execute).to eq(error_status) expect(service.execute).to eq(error_status)
expect(domain).not_to be_verified expect(domain).not_to be_verified
expect(domain).to be_enabled expect(domain).not_to be_enabled
end
end
context 'when txt record does not contain verification code' do
before do
stub_resolver(domain_name => 'something else')
end
include_examples 'unverifies and disables domain'
end
context 'when no txt records are present' do
before do
stub_resolver
end
include_examples 'unverifies and disables domain'
end end
end end
context 'verified domain' do context 'when domain is verified' do
set(:domain) { create(:pages_domain) } let(:domain) { create(:pages_domain) }
it 'unverifies (but does not disable) when the right code is not present' do include_examples 'successful enablement and verification'
stub_resolver(domain.domain => 'something else')
context 'when txt record does not contain verification code' do
before do
stub_resolver(domain_name => 'something else')
end
it 'unverifies but does not disable domain' do
expect(service.execute).to eq(error_status) expect(service.execute).to eq(error_status)
expect(domain).not_to be_verified expect(domain).not_to be_verified
expect(domain).to be_enabled expect(domain).to be_enabled
end end
end
it 'unverifies (but does not disable) when no records are present' do context 'when no txt records are present' do
before do
stub_resolver stub_resolver
end
it 'unverifies but does not disable domain' do
expect(service.execute).to eq(error_status) expect(service.execute).to eq(error_status)
expect(domain).not_to be_verified expect(domain).not_to be_verified
expect(domain).to be_enabled expect(domain).to be_enabled
end end
end end
end
context 'expired domain' do context 'when domain is expired' do
set(:domain) { create(:pages_domain, :expired) } let(:domain) { create(:pages_domain, :expired) }
it 'verifies and enables when the right code is present' do context 'when the right code is present' do
stub_resolver(domain.domain => domain.keyed_verification_code) before do
stub_resolver(domain_name => domain.keyed_verification_code)
end
expect(service.execute).to eq(status: :success) include_examples 'verifies and enables the domain'
end
expect(domain).to be_verified context 'when the right code is not present' do
expect(domain).to be_enabled before do
stub_resolver
end end
it 'disables when the right code is not present' do it 'disables domain' do
error_status[:message] += '. It is now disabled.' error_status[:message] += '. It is now disabled.'
stub_resolver
expect(service.execute).to eq(error_status) expect(service.execute).to eq(error_status)
expect(domain).not_to be_verified expect(domain).not_to be_verified
expect(domain).not_to be_enabled expect(domain).not_to be_enabled
end end
end end
end
context 'invalid domain' do context 'invalid domain' do
let(:domain) { build(:pages_domain, :expired, :with_missing_chain) } let(:domain) { build(:pages_domain, :expired, :with_missing_chain) }
......
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