Skip to content

Commit

Permalink
Add an end-to-end test for adding metadata to transcodes
Browse files Browse the repository at this point in the history
This test runs a WAV file through the TranscodeJob and then ensures
that the correct metadata has been added to the generated MP3 and FLAC
file using `ffprobe`.
  • Loading branch information
chrislo committed Oct 2, 2024
1 parent b1546ee commit e255eeb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/jobs/transcode_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,40 @@ class TranscodeJobTest < ActiveJob::TestCase

TranscodeJob.perform_now(build(:track))
end

test 'it adds metadata to the generated MP3 file' do
album = create(:album, released_on: Time.zone.today)
track = create(:track, album:)
TranscodeJob.perform_now(track)

track.transcodes.mp3v0.first.file.open do |file|
cmd = "ffprobe -i #{file.path} -v quiet -print_format json -show_format"
std_out, _status = Open3.capture2(cmd)
metadata = JSON.parse(std_out)

assert_equal track.title, metadata['format']['tags']['title']
assert_equal '01', metadata['format']['tags']['track']
assert_equal album.title, metadata['format']['tags']['album']
assert_equal album.artist.name, metadata['format']['tags']['artist']
assert_equal album.released_on.to_s, metadata['format']['tags']['date']
end
end

test 'it adds metadata to the generated flac file' do
album = create(:album, released_on: Time.zone.today)
track = create(:track, album:)
TranscodeJob.perform_now(track, format: :flac)

track.transcodes.flac.first.file.open do |file|
cmd = "ffprobe -i #{file.path} -v quiet -print_format json -show_format"
std_out, _status = Open3.capture2(cmd)
metadata = JSON.parse(std_out)

assert_equal track.title, metadata['format']['tags']['TITLE']
assert_equal '01', metadata['format']['tags']['track']
assert_equal album.title, metadata['format']['tags']['ALBUM']
assert_equal album.artist.name, metadata['format']['tags']['ARTIST']
assert_equal album.released_on.to_s, metadata['format']['tags']['DATE']
end
end
end

0 comments on commit e255eeb

Please sign in to comment.