|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | RSpec.describe DiscourseAi::Completions::UploadEncoder do |
4 | | - let(:file) { plugin_file_from_fixtures("1x1.gif") } |
| 4 | + let(:gif) { plugin_file_from_fixtures("1x1.gif") } |
| 5 | + let(:jpg) { plugin_file_from_fixtures("1x1.jpg") } |
| 6 | + let(:webp) { plugin_file_from_fixtures("1x1.webp") } |
5 | 7 |
|
6 | 8 | it "automatically converts gifs to pngs" do |
7 | | - upload = UploadCreator.new(file, "1x1.gif").create_for(Discourse.system_user.id) |
| 9 | + upload = UploadCreator.new(gif, "1x1.gif").create_for(Discourse.system_user.id) |
8 | 10 | encoded = described_class.encode(upload_ids: [upload.id], max_pixels: 1_048_576) |
9 | 11 | expect(encoded.length).to eq(1) |
10 | 12 | expect(encoded[0][:base64]).to be_present |
11 | 13 | expect(encoded[0][:mime_type]).to eq("image/png") |
12 | 14 | end |
| 15 | + |
| 16 | + it "automatically converts webp to pngs" do |
| 17 | + upload = UploadCreator.new(webp, "1x1.webp").create_for(Discourse.system_user.id) |
| 18 | + encoded = described_class.encode(upload_ids: [upload.id], max_pixels: 1_048_576) |
| 19 | + expect(encoded.length).to eq(1) |
| 20 | + expect(encoded[0][:base64]).to be_present |
| 21 | + expect(encoded[0][:mime_type]).to eq("image/png") |
| 22 | + end |
| 23 | + |
| 24 | + it "supports jpg" do |
| 25 | + upload = UploadCreator.new(jpg, "1x1.jpg").create_for(Discourse.system_user.id) |
| 26 | + encoded = described_class.encode(upload_ids: [upload.id], max_pixels: 1_048_576) |
| 27 | + expect(encoded.length).to eq(1) |
| 28 | + expect(encoded[0][:base64]).to be_present |
| 29 | + expect(encoded[0][:mime_type]).to eq("image/jpeg") |
| 30 | + end |
13 | 31 | end |
0 commit comments