discourse/spec/lib/upload_markdown_spec.rb
Martin Brennan 4b4f2330da
DEV: Expand UploadMarkdown generation capabilities (#15930)
The chat quoting mechanism will need to be able to generate
markdown for all kinds of uploads. The UploadMarkdown class
was missing generation for video and audio uploads. This
commit adds that in, and also expands the server-side regex
recognition of FileHelper types to match those in uploads.js,
and adds a spec for UploadMarkdown
2022-02-14 15:48:27 +10:00

32 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe UploadMarkdown do
it "generates markdown for each different upload type (attachment, image, video, audio)" do
SiteSetting.authorized_extensions = "mp4|mp3|pdf|jpg|mmmppp444"
video = Fabricate(:upload, original_filename: "test_video.mp4", extension: "mp4")
audio = Fabricate(:upload, original_filename: "test_audio.mp3", extension: "mp3")
attachment = Fabricate(:upload, original_filename: "test_file.pdf", extension: "pdf")
image = Fabricate(:upload, width: 100, height: 200, original_filename: "test_img.jpg", extension: "jpg")
expect(UploadMarkdown.new(video).to_markdown).to eq(<<~MD.chomp)
![test_video.mp4|video](#{video.short_url})
MD
expect(UploadMarkdown.new(audio).to_markdown).to eq(<<~MD.chomp)
![test_audio.mp3|audio](#{audio.short_url})
MD
expect(UploadMarkdown.new(attachment).to_markdown).to eq(<<~MD.chomp)
[test_file.pdf|attachment](#{attachment.short_url}) (#{attachment.human_filesize})
MD
expect(UploadMarkdown.new(image).to_markdown).to eq(<<~MD.chomp)
![test_img.jpg|100x200](#{image.short_url})
MD
unknown = Fabricate(:upload, original_filename: "test_video.mmmppp444", extension: "mmmppp444")
expect(UploadMarkdown.new(unknown).playable_media_markdown).to eq(<<~MD.chomp)
[test_video.mmmppp444|attachment](#{unknown.short_url}) (#{unknown.human_filesize})
MD
end
end