Commit e0f2c52e authored by Patrick Bajao's avatar Patrick Bajao

Fix ResultsStore#read to return a CheckResult

`MergeRequests::Mergeability::RunChecksService#run_check` expects
that `MergeRequests::Mergeability::ResultsStore#read` to return
a `MergeRequests::Mergeability::CheckResult` object.

This fixes the `ResultsStore#read` to return a `CheckResult` object
once it received a result from cache (e.g. Redis).

This is behind the `mergeability_caching` feature flag.
parent ac28e3ae
......@@ -22,8 +22,8 @@ module Gitlab
def self.from_hash(data)
new(
status: data.fetch(:status),
payload: data.fetch(:payload))
status: data.fetch('status').to_sym,
payload: data.fetch('payload'))
end
def initialize(status:, payload: {})
......
......@@ -9,7 +9,11 @@ module Gitlab
end
def read(merge_check:)
interface.retrieve_check(merge_check: merge_check)
result_hash = interface.retrieve_check(merge_check: merge_check)
return if result_hash.blank?
CheckResult.from_hash(result_hash)
end
def write(merge_check:, result_hash:)
......
......@@ -70,8 +70,8 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::CheckResult do
let(:payload) { { test: 'test' } }
let(:hash) do
{
status: status,
payload: payload
'status' => status,
'payload' => payload
}
end
......
......@@ -10,10 +10,22 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::ResultsStore do
let(:merge_request) { double }
describe '#read' do
it 'calls #retrieve on the interface' do
expect(interface).to receive(:retrieve_check).with(merge_check: merge_check)
let(:result_hash) { { 'status' => 'success', 'payload' => {} } }
results_store.read(merge_check: merge_check)
it 'calls #retrieve_check on the interface' do
expect(interface).to receive(:retrieve_check).with(merge_check: merge_check).and_return(result_hash)
cached_result = results_store.read(merge_check: merge_check)
expect(cached_result.status).to eq(result_hash['status'].to_sym)
expect(cached_result.payload).to eq(result_hash['payload'])
end
context 'when #retrieve_check returns nil' do
it 'returns nil' do
expect(interface).to receive(:retrieve_check).with(merge_check: merge_check).and_return(nil)
expect(results_store.read(merge_check: merge_check)).to be_nil
end
end
end
......
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