-
Notifications
You must be signed in to change notification settings - Fork 6
Add spec for CanonicalMetadataSync service and fix multiple variable reference bugs #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64ef878
Initial plan
Copilot c5fa4ba
Create canonical_metadata_sync_spec.rb and fix service bug
Copilot 243d76a
Enhance canonical_metadata_sync_spec with additional edge case tests
Copilot 63d16ce
Update spec/services/canonical_metadata_sync_spec.rb
mcfiredrill c3edc6f
Update spec/services/canonical_metadata_sync_spec.rb
mcfiredrill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,156 @@ | ||
| require 'rails_helper' | ||
| # warning this was written by copilot | ||
|
|
||
| describe CanonicalMetadataSync do | ||
| include RedisConnection | ||
|
|
||
| let(:radio) { FactoryBot.create(:radio) } | ||
| let(:liquidsoap_requests) { instance_double("LiquidsoapRequests") } | ||
| let(:metadata) { "Test Song Title" } | ||
|
|
||
| before do | ||
| # Clear Redis before each test | ||
| redis.flushdb | ||
|
|
||
| # Mock LiquidsoapRequests | ||
| allow(LiquidsoapRequests).to receive(:new).with(radio.id).and_return(liquidsoap_requests) | ||
| end | ||
|
|
||
| describe '.perform' do | ||
| context 'with live_dj current source' do | ||
| before do | ||
| allow(liquidsoap_requests).to receive(:current_source).and_return('live_dj') | ||
| end | ||
|
|
||
| it 'sets canonical metadata with live_dj source and current show data' do | ||
| show_series = double('ShowSeries', slug: 'test-show-series') | ||
| current_show = double('ScheduledShow', show_series: show_series, slug: 'test-episode-123') | ||
|
|
||
| allow(Radio).to receive(:first).and_return(radio) | ||
| allow(radio).to receive(:current_scheduled_show).and_return(current_show) | ||
|
|
||
| CanonicalMetadataSync.perform(radio.id, metadata) | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Test Song Title") | ||
| expect(stored_data["current_source"]).to eq("live_dj") | ||
| expect(stored_data["show_series_id"]).to eq("test-show-series") | ||
| expect(stored_data["episode_id"]).to eq("test-episode-123") | ||
| end | ||
|
|
||
| it 'clears show data when no current show' do | ||
| allow(Radio).to receive(:first).and_return(radio) | ||
| allow(radio).to receive(:current_scheduled_show).and_return(nil) | ||
|
|
||
| CanonicalMetadataSync.perform(radio.id, metadata) | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Test Song Title") | ||
| expect(stored_data["current_source"]).to eq("live_dj") | ||
| expect(stored_data["show_series_id"]).to eq("") | ||
| expect(stored_data["episode_id"]).to eq("") | ||
| end | ||
| end | ||
|
|
||
| context 'with scheduled_shows current source' do | ||
| before do | ||
| allow(liquidsoap_requests).to receive(:current_source).and_return('scheduled_shows') | ||
| end | ||
|
|
||
| it 'sets canonical metadata with scheduled_shows source and current show data' do | ||
| show_series = double('ShowSeries', slug: 'scheduled-show-series') | ||
| current_show = double('ScheduledShow', show_series: show_series, slug: 'scheduled-episode-456') | ||
|
|
||
| allow(Radio).to receive(:first).and_return(radio) | ||
| allow(radio).to receive(:current_scheduled_show).and_return(current_show) | ||
|
|
||
| CanonicalMetadataSync.perform(radio.id, metadata) | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Test Song Title") | ||
| expect(stored_data["current_source"]).to eq("scheduled_shows") | ||
| expect(stored_data["show_series_id"]).to eq("scheduled-show-series") | ||
| expect(stored_data["episode_id"]).to eq("scheduled-episode-456") | ||
| end | ||
| end | ||
|
|
||
| context 'with backup_playlist current source' do | ||
| before do | ||
| allow(liquidsoap_requests).to receive(:current_source).and_return('backup_playlist') | ||
|
|
||
| # Set up archive metadata in Redis | ||
| redis.hset("#{radio.name}:current_archive", "show_series", "archive-show-series") | ||
| redis.hset("#{radio.name}:current_archive", "episode", "archive-episode-789") | ||
| end | ||
|
|
||
| it 'sets canonical metadata with backup_playlist source and archive data' do | ||
| CanonicalMetadataSync.perform(radio.id, metadata) | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Test Song Title") | ||
| expect(stored_data["current_source"]).to eq("backup_playlist") | ||
| expect(stored_data["show_series_id"]).to eq("archive-show-series") | ||
| expect(stored_data["episode_id"]).to eq("archive-episode-789") | ||
| end | ||
|
|
||
| it 'handles missing archive metadata gracefully' do | ||
| # Clear the archive data | ||
| redis.del("#{radio.name}:current_archive") | ||
|
|
||
| CanonicalMetadataSync.perform(radio.id, metadata) | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Test Song Title") | ||
| expect(stored_data["current_source"]).to eq("backup_playlist") | ||
| expect(stored_data["show_series_id"]).to be_nil | ||
| expect(stored_data["episode_id"]).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context 'with unknown current source' do | ||
| before do | ||
| allow(liquidsoap_requests).to receive(:current_source).and_return('unknown') | ||
| end | ||
|
|
||
| it 'sets canonical metadata with unknown source and archive data' do | ||
| redis.hset("#{radio.name}:current_archive", "show_series", "fallback-show-series") | ||
| redis.hset("#{radio.name}:current_archive", "episode", "fallback-episode-999") | ||
|
|
||
| CanonicalMetadataSync.perform(radio.id, metadata) | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Test Song Title") | ||
| expect(stored_data["current_source"]).to eq("unknown") | ||
| expect(stored_data["show_series_id"]).to eq("fallback-show-series") | ||
| expect(stored_data["episode_id"]).to eq("fallback-episode-999") | ||
| end | ||
| end | ||
|
|
||
| it 'strips whitespace from metadata title' do | ||
| allow(liquidsoap_requests).to receive(:current_source).and_return('backup_playlist') | ||
|
|
||
| CanonicalMetadataSync.perform(radio.id, " Spaced Title ") | ||
|
|
||
| stored_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Spaced Title") | ||
| end | ||
|
|
||
| it 'finds the correct radio by id' do | ||
| # Create a second radio to ensure we're finding the right one | ||
| radio2 = FactoryBot.create(:radio, name: 'second_radio') | ||
| liquidsoap_requests2 = instance_double("LiquidsoapRequests") | ||
| allow(LiquidsoapRequests).to receive(:new).with(radio2.id).and_return(liquidsoap_requests2) | ||
| allow(liquidsoap_requests2).to receive(:current_source).and_return('backup_playlist') | ||
|
|
||
| CanonicalMetadataSync.perform(radio2.id, "Radio 2 Song") | ||
|
|
||
| # Verify data is stored for the correct radio | ||
| stored_data = redis.hgetall("#{radio2.name}:canonical_metadata") | ||
| expect(stored_data["title"]).to eq("Radio 2 Song") | ||
|
|
||
| # Verify the first radio doesn't have this data | ||
| first_radio_data = redis.hgetall("#{radio.name}:canonical_metadata") | ||
| expect(first_radio_data["title"]).not_to eq("Radio 2 Song") | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.