fix(app-store): address review sync comments
This commit is contained in:
@@ -4,7 +4,15 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe Inboxes::FetchAppStoreReviewsJob do
|
||||
let(:channel) { create(:channel_app_store, last_synced_at: nil) }
|
||||
let(:review_payload) { { 'review' => { 'id' => 'review-1' }, 'response' => nil } }
|
||||
let(:review_payload) do
|
||||
{
|
||||
'review' => {
|
||||
'id' => 'review-1',
|
||||
'attributes' => { 'createdDate' => '2026-05-20T10:00:00-00:00' }
|
||||
},
|
||||
'response' => nil
|
||||
}
|
||||
end
|
||||
let(:review_builder) { instance_double(AppStore::ReviewBuilder, perform: true) }
|
||||
|
||||
before do
|
||||
@@ -24,7 +32,23 @@ RSpec.describe Inboxes::FetchAppStoreReviewsJob do
|
||||
described_class.perform_now(channel)
|
||||
|
||||
expect(review_builder).to have_received(:perform)
|
||||
expect(channel.reload.last_synced_at).to be_present
|
||||
expect(channel.reload.last_synced_at).to eq(Time.zone.parse('2026-05-20T10:00:00-00:00'))
|
||||
end
|
||||
|
||||
it 'updates the sync timestamp to the latest fetched review date' do
|
||||
older_payload = review_payload.deep_dup
|
||||
newer_payload = review_payload.deep_dup
|
||||
older_payload['review']['id'] = 'review-1'
|
||||
older_payload['review']['attributes']['createdDate'] = '2026-05-20T10:00:00-00:00'
|
||||
newer_payload['review']['id'] = 'review-2'
|
||||
newer_payload['review']['attributes']['createdDate'] = '2026-05-20T11:00:00-00:00'
|
||||
|
||||
allow(channel).to receive(:fetch_reviews).and_return([newer_payload, older_payload])
|
||||
allow(AppStore::ReviewBuilder).to receive(:new).and_return(review_builder)
|
||||
|
||||
described_class.perform_now(channel)
|
||||
|
||||
expect(channel.reload.last_synced_at).to eq(Time.zone.parse('2026-05-20T11:00:00-00:00'))
|
||||
end
|
||||
|
||||
it 'captures per-review errors and continues syncing' do
|
||||
|
||||
@@ -74,6 +74,18 @@ RSpec.describe AppStore::ReviewBuilder do
|
||||
expect(review_message.content).to include('★★★★☆ (4/5)')
|
||||
end
|
||||
|
||||
it 'clamps the review rating before building the message content' do
|
||||
invalid_rating_payload = review_payload.deep_dup
|
||||
invalid_rating_payload['review']['attributes']['rating'] = 7
|
||||
invalid_rating_payload['response'] = nil
|
||||
|
||||
described_class.new(review_payload: invalid_rating_payload, channel: channel).perform
|
||||
|
||||
review_message = inbox.conversations.last.messages.incoming.find_by(source_id: 'review-1')
|
||||
expect(review_message.content).to include('★★★★★ (5/5)')
|
||||
expect(review_message.content_attributes['app_store']).to include('rating' => 5)
|
||||
end
|
||||
|
||||
it 'falls back to current time when Apple timestamps are blank' do
|
||||
blank_timestamp_payload = review_payload.deep_dup
|
||||
blank_timestamp_payload['review']['attributes']['createdDate'] = ''
|
||||
|
||||
Reference in New Issue
Block a user