diff --git a/lib/decidim/accountability_simple/api/types/result_type_extensions.rb b/lib/decidim/accountability_simple/api/types/result_type_extensions.rb index 10ea758..8bc238a 100644 --- a/lib/decidim/accountability_simple/api/types/result_type_extensions.rb +++ b/lib/decidim/accountability_simple/api/types/result_type_extensions.rb @@ -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 diff --git a/spec/types/decidim/accountability/result_type_spec.rb b/spec/types/decidim/accountability/result_type_spec.rb index ab8b71c..1d218fa 100644 --- a/spec/types/decidim/accountability/result_type_spec.rb +++ b/spec/types/decidim/accountability/result_type_spec.rb @@ -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 } } }) }