このコミットが含まれているのは:
@@ -14,6 +14,47 @@ RSpec.describe MaterialSyncRunner do
|
||||
let(:drive_client) { instance_double(GoogleDrive::ApiClient) }
|
||||
|
||||
describe '#sync!' do
|
||||
it 'groups created and updated materials across sync sources into one event' do
|
||||
existing = Material.create!(
|
||||
source_kind: 'google_drive_file', source_file_id: 'existing-file',
|
||||
source_path: 'old.png', url: 'https://example.com/existing',
|
||||
created_by_user: user, updated_by_user: user)
|
||||
source
|
||||
MaterialSyncSource.create!(
|
||||
name: 'Second Drive source', source_kind: 'google_drive_path',
|
||||
source_file_id: 'folder-456', profile: 'legacy_drive',
|
||||
created_by_user: user, updated_by_user: user)
|
||||
allow(GoogleDrive::ApiClient).to receive(:new).and_return(drive_client)
|
||||
allow(drive_client).to receive(:each_material_file_under_folder) do |folder_id, &block|
|
||||
id = folder_id == 'folder-123' ? 'existing-file' : 'new-file'
|
||||
block.call(id:, name: "#{ id }.png", mime_type: 'image/png',
|
||||
relative_path: "素材/#{ id }.png", sha256_checksum: nil,
|
||||
web_view_link: "https://drive.google.com/file/d/#{ id }/view")
|
||||
end
|
||||
allow(drive_client).to receive(:download_to_tempfile) do |id, **|
|
||||
Tempfile.new(['sync-event', '.png']).tap do |file|
|
||||
file.binmode
|
||||
file.write(id)
|
||||
file.rewind
|
||||
end
|
||||
end
|
||||
allow(MaterialThumbnailGenerator).to receive(:generate!)
|
||||
previous_ids = MaterialVersion.pluck(:id)
|
||||
|
||||
result = nil
|
||||
expect { result = described_class.sync_enabled! }
|
||||
.to change { event_rows.length }.by(1)
|
||||
|
||||
expect(result).to have_attributes(imported: 1, updated: 1, failed: 0)
|
||||
event = event_rows.last
|
||||
expect(event.fetch('event_type')).to eq('materials.sync')
|
||||
created = Material.find_by!(source_file_id: 'new-file')
|
||||
versions = MaterialVersion.where.not(id: previous_ids)
|
||||
expect(versions.pluck(:material_id).uniq).to contain_exactly(existing.id, created.id)
|
||||
expect(versions.pluck(:event_type)).to include('create', 'update')
|
||||
expect(versions.pluck(:event_id).uniq).to eq([event.fetch('id')])
|
||||
end
|
||||
|
||||
it 'imports google drive path candidates as they are yielded' do
|
||||
first_entry = { id: 'file-1',
|
||||
name: 'a.png',
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする