fix(graphql): return empty array when no attachments
This commit is contained in:
parent
9ead0daf32
commit
4ba3c0e650
2 changed files with 26 additions and 1 deletions
|
@ -45,7 +45,7 @@ module Extensions
|
|||
else
|
||||
attachment = after_resolve_attachment(value)
|
||||
if options[:as] == :multiple
|
||||
[attachment]
|
||||
[attachment].compact
|
||||
else
|
||||
attachment
|
||||
end
|
||||
|
|
|
@ -210,6 +210,18 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
}
|
||||
end
|
||||
|
||||
describe 'dossier with message with no attachments' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
let(:query) { DOSSIER_WITH_MESSAGE_QUERY }
|
||||
let(:variables) { { number: dossier.id } }
|
||||
|
||||
before { create(:commentaire, dossier: dossier) }
|
||||
|
||||
it {
|
||||
expect(data[:dossier][:messages]).not_to be_nil
|
||||
}
|
||||
end
|
||||
|
||||
DOSSIER_QUERY = <<-GRAPHQL
|
||||
query($number: Int!) {
|
||||
dossier(number: $number) {
|
||||
|
@ -351,4 +363,17 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
}
|
||||
}
|
||||
GRAPHQL
|
||||
|
||||
DOSSIER_WITH_MESSAGE_QUERY = <<-GRAPHQL
|
||||
query($number: Int!) {
|
||||
dossier(number: $number) {
|
||||
messages {
|
||||
body
|
||||
attachments {
|
||||
filename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue