-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from alphagov/fix-payload-version-check
Fix incorrect document locking version check
- Loading branch information
Showing
6 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
RSpec.describe DiscoveryEngine::Sync::Locking do | ||
subject(:lockable) { Class.new.include(described_class).new } | ||
|
||
let(:content_id) { "some-content-id" } | ||
let(:payload_version) { 10 } | ||
|
||
let(:redis_client) { double("Redis Client") } | ||
|
||
before do | ||
allow(Rails.application.config.redis_pool).to receive(:with).and_yield(redis_client) | ||
end | ||
|
||
describe "#outdated_payload_version?" do | ||
subject(:outdated_payload_version) { lockable.outdated_payload_version?(content_id, payload_version:) } | ||
|
||
let(:remote_version) { 42 } | ||
|
||
before do | ||
allow(redis_client).to receive(:get) | ||
.with("search_api_v2:latest_synced_version:some-content-id") | ||
.and_return(remote_version.to_s) | ||
end | ||
|
||
context "when payload_version is nil" do | ||
let(:payload_version) { nil } | ||
|
||
it { is_expected.to be(false) } | ||
end | ||
|
||
context "when there is no remote version" do | ||
let(:remote_version) { nil } | ||
|
||
it { is_expected.to be(false) } | ||
end | ||
|
||
context "when remote version is equal to payload version" do | ||
let(:remote_version) { payload_version } | ||
|
||
it { is_expected.to be(true) } | ||
end | ||
|
||
context "when remote version is greater than payload version" do | ||
let(:remote_version) { payload_version + 1 } | ||
|
||
it { is_expected.to be(true) } | ||
end | ||
|
||
context "when remote version is less than payload version" do | ||
let(:remote_version) { payload_version - 1 } | ||
|
||
it { is_expected.to be(false) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters