Skip to content

Commit

Permalink
CV2-2897: fix return updated_objects for bulk read action (#1685)
Browse files Browse the repository at this point in the history
* CV2-2897: fix return updated_objects for bulk read action

* CV2-2897: fix tests
  • Loading branch information
melsawy authored Oct 8, 2023
1 parent a7de721 commit a52dacc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/graph/mutations/graphql_crud_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def self.apply_bulk_update_or_destroy(inputs, ctx, update_or_destroy, klass)
method_mapping = { update: :bulk_update, destroy: :bulk_destroy, mark_read: :bulk_mark_read }
method = method_mapping[update_or_destroy.to_sym]
result = klass.send(method, sql_ids, filtered_inputs, Team.current)
if update_or_destroy.to_s == "update"
if update_or_destroy.to_s != "destroy"
result.merge!({ updated_objects: klass.where(id: sql_ids) })
end
{ ids: processed_ids }.merge(result)
Expand Down
4 changes: 3 additions & 1 deletion test/controllers/graphql_controller_4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ def teardown
@pms.each { |pm| assert_not pm.read }
assert_search_finds_all({ read: 0 })
assert_search_finds_none({ read: 1 })
query = 'mutation { bulkProjectMediaMarkRead(input: { clientMutationId: "1", ids: ' + @ids + ', read: true }) { ids, team { dbid } } }'
query = 'mutation { bulkProjectMediaMarkRead(input: { clientMutationId: "1", ids: ' + @ids + ', read: true }) { updated_objects { id, is_read, dbid }, ids, team { dbid } } }'
post :create, params: { query: query, team: @t.slug }
assert_response :success
updated_objects = JSON.parse(@response.body)['data']['bulkProjectMediaMarkRead']['updated_objects']
assert_equal @pms.map(&:id).sort, updated_objects.collect{|obj| obj['dbid']}.sort
@pms.each { |pm| assert pm.reload.read }
assert_search_finds_all({ read: 1 })
assert_search_finds_none({ read: 0 })
Expand Down

0 comments on commit a52dacc

Please sign in to comment.