Commit 8ea4b646 authored by Marc Shaw's avatar Marc Shaw

Merge branch 'pb-mergeability-framework-caching-fix' into 'master'

Fix ResultsStore#read to return a CheckResult

See merge request gitlab-org/gitlab!82792
parents 9a9d78b8 e0f2c52e
...@@ -22,8 +22,8 @@ module Gitlab ...@@ -22,8 +22,8 @@ module Gitlab
def self.from_hash(data) def self.from_hash(data)
new( new(
status: data.fetch(:status), status: data.fetch('status').to_sym,
payload: data.fetch(:payload)) payload: data.fetch('payload'))
end end
def initialize(status:, payload: {}) def initialize(status:, payload: {})
......
...@@ -9,7 +9,11 @@ module Gitlab ...@@ -9,7 +9,11 @@ module Gitlab
end end
def read(merge_check:) 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 end
def write(merge_check:, result_hash:) def write(merge_check:, result_hash:)
......
...@@ -70,8 +70,8 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::CheckResult do ...@@ -70,8 +70,8 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::CheckResult do
let(:payload) { { test: 'test' } } let(:payload) { { test: 'test' } }
let(:hash) do let(:hash) do
{ {
status: status, 'status' => status,
payload: payload 'payload' => payload
} }
end end
......
...@@ -10,10 +10,22 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::ResultsStore do ...@@ -10,10 +10,22 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::ResultsStore do
let(:merge_request) { double } let(:merge_request) { double }
describe '#read' do describe '#read' do
it 'calls #retrieve on the interface' do let(:result_hash) { { 'status' => 'success', 'payload' => {} } }
expect(interface).to receive(:retrieve_check).with(merge_check: merge_check)
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
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