anchor.diff:              },
               <<"c">> => <<"d">>
           },
  -        elasticsearch_harvesting_backend:prepare_data(#{
  -            <<"fileId">> => <<"fileId">>,
  -            <<"fileName">> => <<"fileName">>,
  -            <<"payload">> => #{
  -                <<"json">> => <<"{\"a\":\"B\", \"c\":\"d\"}">>,
  -                <<"xattrs">> => #{<<"x">> => <<"y">>, <<"z">> => <<"b">>}
  -            },
  -            <<"spaceId">> => <<"spaceId">>
  -        }, IndexInfo, {[<<"a">>, <<"x">>, <<"__onedata.xattrs.z">>], <<"Rejection reason">>})
  +        call_prepare_data(#{
  +            <<"json">> => <<"{\"a\":\"B\", \"c\":\"d\"}">>,
  +            <<"xattrs">> => #{<<"x">> => <<"y">>, <<"z">> => <<"b">>}
  +        }, IndexInfo, [<<"a">>, <<"x">>, <<"__onedata.xattrs.z">>])
       ),
       
       ?assertEqual(
  
positive.code:                 <<"json">> => <<"{\"a\":\"B\", \"c\":\"d\"}">>,
                  <<"xattrs">> => #{<<"x">> => <<"y">>, <<"z">> => <<"b">>}
              },
              <<"spaceId">> => <<"spaceId">>
          }, IndexInfo, {all, <<"Rejection reason">>})
      ),
      
      ?assertEqual(
          #{
              <<"a">> => <<"B">>
          },
          elasticsearch_harvesting_backend:prepare_data(#{
              <<"fileId">> => <<"fileId">>,
              <<"fileName">> => <<"fileName">>,
              <<"payload">> => #{
                  <<"json">> => <<"{\"a\":\"B\"}">>,
                  <<"xattrs">> => #{<<"x">> => <<"y">>},
                  <<"rdf">> => <<"some rdf">>
              },
              <<"spaceId">> => <<"spaceId">>
          }, #harvester_index{include_metadata = [json]}, {[], <<>>})
      ),
      
      ?assertEqual(
          #{
              <<"__onedata">> => #{
                  <<"xattrs">> => #{<<"x">> => #{<<"__value">> => <<"y">>}}
              }
          },
          elasticsearch_harvesting_backend:prepare_data(#{
              <<"fileId">> => <<"fileId">>,
              <<"fileName">> => <<"fileName">>,
              <<"payload">> => #{
                  <<"json">> => <<"{\"a\":\"B\"}">>,
                  <<"xattrs">> => #{<<"x">> => <<"y">>},
                  <<"rdf">> => <<"some rdf">>
              },
              <<"spaceId">> => <<"spaceId">>
          }, #harvester_index{include_metadata = [xattrs]}, {[], <<>>})
      ),
      
      ?assertEqual(
          #{
              <<"__onedata">> => #{
                  <<"rdf">> => <<"some rdf">>
              }
          },
          elasticsearch_harvesting_backend:prepare_data(#{
              <<"fileId">> => <<"fileId">>,
              <<"fileName">> => <<"fileName">>,
              <<"payload">> => #{
                  <<"json">> => <<"{\"a\":\"B\"}">>,
                  <<"xattrs">> => #{<<"x">> => <<"y">>},
                  <<"rdf">> => <<"some rdf">>
              },
              <<"spaceId">> => <<"spaceId">>
          }, #harvester_index{include_metadata = [rdf]}, {[], <<>>})
      ),
      
      ?assertEqual(
          #{
              <<"__onedata.__rejected">> => <<"{\"c\":\"d\",\"a\":\"B\"}">>
          },
          elasticsearch_harvesting_backend:prepare_data(#{
              <<"fileId">> => <<"fileId">>,
              <<"fileName">> => <<"fileName">>,
              <<"payload">> => #{
                  <<"json">> => <<"{\"a\":\"B\", \"c\":\"d\"}">>,
                  <<"xattrs">> => #{<<"x">> => <<"y">>, <<"z">> => <<"b">>}
              },
              <<"spaceId">> => <<"spaceId">>},
              #harvester_index{include_metadata = [json], include_rejection_reason = false},
              {all, <<"Rejection reason">>}
          )
      ),
      
      ?assertEqual(
          #{
              <<"a">> => <<"B">>,
              <<"c">> => <<"d">>,
              <<"__onedata">> => #{<<"__rejected">> => [<<"x">>]}
          },
          elasticsearch_harvesting_backend:prepare_data(#{
              <<"fileId">> => <<"fileId">>,
              <<"fileName">> => <<"fileName">>,
              <<"payload">> => #{
                  <<"json">> => <<"{\"a\":\"B\", \"c\":\"d\"}">>,
                  <<"xattrs">> => #{<<"x">> => <<"y">>, <<"z">> => <<"b">>}
              },
              <<"spaceId">> => <<"spaceId">>},
              #harvester_index{include_metadata = [json], include_rejection_reason = false},
              {[<<"x">>], <<"Rejection reason">>}
  
negative.code:             },
              <<"a">> => <<"B">>
          },
          call_prepare_data(#{
              <<"json">> => <<"{\"a\":\"B\"}">>,
              <<"xattrs">> => #{<<"x">> => <<"y">>},
              <<"rdf">> => <<"some rdf">>
          }, IndexInfo, [])
      ),
      ok.
  
  prepare_data_with_rejected_fields_test() ->
      IndexInfo = #harvester_index{
          include_metadata = [json, xattrs, rdf],
          include_file_details = [fileName, spaceId, metadataExistenceFlags],
          include_rejection_reason = true
      },
      ?assertEqual(
          #{
              <<"__onedata">> => #{
  