Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 5b0c119

Browse files
committed
more specs
1 parent 70b9078 commit 5b0c119

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

spec/fixtures/images/1x1.jpg

160 Bytes
Loading

spec/fixtures/images/1x1.webp

44 Bytes
Loading
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
# frozen_string_literal: true
22

33
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") }
57

68
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)
810
encoded = described_class.encode(upload_ids: [upload.id], max_pixels: 1_048_576)
911
expect(encoded.length).to eq(1)
1012
expect(encoded[0][:base64]).to be_present
1113
expect(encoded[0][:mime_type]).to eq("image/png")
1214
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
1331
end

0 commit comments

Comments
 (0)