Skip to content

Commit

Permalink
Fix the main image and list image URLs through the API
Browse files Browse the repository at this point in the history
  • Loading branch information
ahukkanen committed Dec 4, 2023
1 parent 2fab7e4 commit 0ad3cdd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def self.included(type)
type.field :links, [Decidim::AccountabilitySimple::ResultLinkType], "The links for this resource", method: :result_links, null: false
end

def main_image
return unless object.main_image.attached?

object.attached_uploader(:main_image).url
end

def list_image
return unless object.list_image.attached?

object.attached_uploader(:list_image).url
end

def default_details
context.scoped_context[:parent] = object

Expand Down
32 changes: 32 additions & 0 deletions spec/types/decidim/accountability/result_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@
end
end

describe "mainImage" do
let(:query) { "{ mainImage }" }

before do
model.main_image.attach(
io: File.open(Decidim::Dev.asset("city.jpeg")),
filename: "city.jpeg",
content_type: "image/jpeg"
)
end

it "returns the result's main image" do
expect(response["mainImage"]).to match(model.attached_uploader(:main_image).url)
end
end

describe "listImage" do
let(:query) { "{ listImage }" }

before do
model.list_image.attach(
io: File.open(Decidim::Dev.asset("city.jpeg")),
filename: "city.jpeg",
content_type: "image/jpeg"
)
end

it "returns the result's main image" do
expect(response["listImage"]).to match(model.attached_uploader(:list_image).url)
end
end

describe "defaultDetails" do
let(:query) { %({ defaultDetails { id values { id } } }) }

Expand Down

0 comments on commit 0ad3cdd

Please sign in to comment.