anchor.diff:      {ok, UserId} = rpc:call(Node, user_logic, create, [#user{name = UserName}]),
       UserId.
   
  -read_user(ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Response = do_request(RestAddress ++ "/user", Headers, get,[], Options),
  -    get_body_val([userId, name], Response).
  -
  -update_user(NewUserName, ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Body = jiffy:encode({[
  -        {name, NewUserName}
  -    ]}),
  -    do_request(RestAddress ++ "/user", Headers, patch, Body, Options).
  -
  -delete_user(ReqParams) ->
  -     {RestAddress, Headers, Options} = ReqParams,
  -     do_request(RestAddress ++ "/user", Headers, delete, [], Options).
  -
  -get_user_spaces(ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Response = do_request(RestAddress ++ "/user/spaces", Headers, get, [], Options),
  -    get_body_val([spaces, default], Response).
  -
  -get_user_space(SID, ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Response =
  -        do_request(RestAddress ++ "/user/spaces/" ++ binary_to_list(SID), Headers, get, [], Options),
  -    get_body_val([spaceId, name], Response).
  -
  -get_user_default_space(ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Response = do_request(RestAddress ++ "/user/spaces/default", Headers, get, [], Options),
  -    [DefSpace] = get_body_val([spaceId], Response),
  -    DefSpace.
  -
  -create_space_for_user(SpaceName, ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Body = jiffy:encode({[
  -        {name, SpaceName}
  -    ]}),
  -    Response = do_request(RestAddress ++ "/user/spaces", Headers, post, Body, Options),
  -    get_header_val("spaces", Response).
  -
  -set_default_space_for_user(SID, ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Body = jiffy:encode({[
  -        {spaceId, SID}
  -    ]}),
  -    do_request(RestAddress ++ "/user/spaces/default", Headers, put, Body, Options).
  -
  -get_user_merge_token(ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    Response = do_request(RestAddress ++ "/user/merge/token", Headers, get, [], Options),
  -    [Token] = get_body_val([token], Response),
  -    Token.
  -
  -merge_users(Token, ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -     Body = jiffy:encode({[
  -        {token, Token}
  -    ]}),
  -    do_request(RestAddress ++ "/user/merge", Headers, post, Body, Options).
  -
  -delete_user_space(SID, ReqParams) ->
  -    {RestAddress, Headers, Options} = ReqParams,
  -    do_request(RestAddress ++ "/user/spaces/" ++ binary_to_list(SID), Headers, delete, [], Options).
  -
   %% returns macaroons headers
   auth_user(UserId, ProviderId, ReqParams, Node) ->
       SerializedMacaroon = rpc:call(Node, auth_logic, gen_token, [UserId, ProviderId]),
  
positive.code: 
      %% check other user privileges
      ?assertMatch(true,
          is_included([group_view_data], get_group_user_privileges(GID, UserId2, UserReqParams1))),
  
      SID = create_space_for_user(?SPACE_NAME1, UserReqParams2),
  
      Users = [{UserId1, UserReqParams1}, {UserId2, UserReqParams2}, {UserId3, UserReqParams3}],
      ?assertMatch(ok, group_privileges_check(?GROUP_PRIVILEGES, Users, GID, SID)).
  
  group_spaces_test(Config) ->
      RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderId, ProviderReqParams} =
          register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
       %% create user
      UserId1 = create_user(?USER_NAME1, Node),
  
      %% authenticate user
      NewHeaders = auth_user(UserId1, ProviderId, ReqParams, Node),
      UserReqParams1 = update_req_params(ProviderReqParams, NewHeaders, headers),
  
      GID = create_group(?GROUP_NAME1, UserReqParams1),
      SID1 = create_space_for_group(?SPACE_NAME1, GID, UserReqParams1),
      
      ?assertMatch([SID1, ?SPACE_NAME1], get_group_space(GID, SID1, UserReqParams1)),
      
      SID2 = create_space_for_user(?SPACE_NAME2, UserReqParams1),
  
      InvitationToken = get_space_invitation_token(groups, SID2, UserReqParams1),
      SID_check = join_group_to_space(InvitationToken, GID, UserReqParams1),
  
      ?assertMatch(SID2, SID_check),
      ?assertMatch(true, is_included([SID1, SID2], get_group_spaces(GID, UserReqParams1))),
  
      DeleteResponse = group_leave_space(GID, SID2, UserReqParams1),
  
      ?assertMatch(ok, check_status(DeleteResponse)),
      ?assertMatch(false, is_included([SID2], get_group_spaces(GID, UserReqParams1))).
  
  %% spaces_rest_module_test_group =======================================
  
  spaces_crud_by_user_test(Config) ->
      RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
      
      {ProviderId, ProviderReqParams} =
          register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
      %% create user
      UserId = create_user(?USER_NAME1, Node),
  
      %% authenticate user
      NewHeaders = auth_user(UserId, ProviderId, ReqParams, Node),
      UserReqParams = update_req_params(ProviderReqParams, NewHeaders, headers),
  
      SID = create_space(?SPACE_NAME1, UserReqParams),
  
      ?assertMatch([SID, ?SPACE_NAME1],read_space(SID, UserReqParams)),
      ?assertMatch(ok, check_status(update_space(?SPACE_NAME2, SID, UserReqParams))),
      ?assertMatch([SID, ?SPACE_NAME2], read_space(SID, UserReqParams)),
      ?assertMatch(ok, check_status(delete_space(SID, UserReqParams))).
  
  spaces_crud_by_provider_test(Config) ->
      RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderId, ProviderReqParams} =
          register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
      %% create user
      UserId = create_user(?USER_NAME1, Node),
  
      %% authenticate user
      NewHeaders = auth_user(UserId, ProviderId, ReqParams, Node),
      UserReqParams = update_req_params(ProviderReqParams, NewHeaders, headers),
  
      Token = get_space_creation_token_for_user(UserReqParams),
      SID = create_space(Token, ?SPACE_NAME1, ?SPACE_SIZE1, ProviderReqParams),
  
      ?assertMatch([SID, ?SPACE_NAME1],read_space(SID, ProviderReqParams)),
      ?assertMatch(ok, check_status(delete_space(SID, UserReqParams))).
  
  spaces_user_test(Config) ->
  
      RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderId, ProviderReqParams} =
          register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
      %% create users
      UserId1 = create_user(?USER_NAME1, Node),
      UserId2 = create_user(?USER_NAME2, Node),
  
      %% authenticate users
      NewHeaders1 = auth_user(UserId1, ProviderId, ReqParams, Node),
      NewHeaders2 = auth_user(UserId2, ProviderId, ReqParams, Node),
      UserReqParams1 = update_req_params(ProviderReqParams, NewHeaders1, headers),
      UserReqParams2 = update_req_params(ProviderReqParams, NewHeaders2, headers),
  
      SID = create_space(?SPACE_NAME1, UserReqParams1),
  
      InvitationToken = get_space_invitation_token(users, SID, UserReqParams1),
  
      ?assertMatch(SID, join_user_to_space(InvitationToken, UserReqParams2)),
      ?assertMatch(true, is_included([UserId1, UserId2], get_space_users(SID, UserReqParams1))),
      ?assertMatch([UserId2, ?USER_NAME2], get_space_user(SID, UserId2, UserReqParams2)),
      ?assertMatch(ok, check_status(delete_space_user(SID, UserId2, UserReqParams1))),
      ?assertMatch(false, is_included([UserId2], get_space_users(SID, UserReqParams1))).
  
  spaces_group_test(Config) ->
      RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderId, ProviderReqParams} =
          register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
      %% create users
      UserId = create_user(?USER_NAME1, Node),
  
      %% authenticate users
      NewHeaders = auth_user(UserId, ProviderId, ReqParams, Node),
      UserReqParams = update_req_params(ProviderReqParams, NewHeaders, headers),
  
      GID1 = create_group(?GROUP_NAME1, UserReqParams),
      GID2 = create_group(?GROUP_NAME2, UserReqParams),
      SID = create_space_for_group(?SPACE_NAME1, GID1, UserReqParams),
      InvitationToken = get_space_invitation_token(groups, SID, UserReqParams),
  
      ?assertMatch(SID, join_group_to_space(InvitationToken, GID2, UserReqParams)),
      ?assertMatch(true, is_included([GID1, GID2], get_space_groups(SID, UserReqParams))),
      ?assertMatch([GID2, ?GROUP_NAME2], get_space_group(SID, GID2, UserReqParams)),
      ?assertMatch(ok, check_status(delete_space_group(SID, GID1, UserReqParams))),
      ?assertMatch(false, is_included([GID1], get_space_groups(SID, UserReqParams))).
  
  spaces_provider_test(Config) ->
   RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderId, ProviderReqParams} =
          register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
      %% create users
      UserId = create_user(?USER_NAME1, Node),
  
      %%  authenticate users
      NewHeaders = auth_user(UserId, ProviderId, ReqParams, Node),
      UserReqParams = update_req_params(ProviderReqParams, NewHeaders, headers),
      Token = get_space_creation_token_for_user(UserReqParams),
      SID = create_space_for_provider(Token, ?SPACE_NAME1, ?SPACE_SIZE1, ProviderReqParams),
  
      ?assertMatch(
          [ProviderId],
          get_space_providers(SID, UserReqParams)
      ),
  
      ?assertMatch(
          [?CLIENT_NAME1, ProviderId, ?URLS1, ?REDIRECTION_POINT1],
          get_space_provider(SID, ProviderId, UserReqParams)
      ),
  
      ?assertMatch(
          ok,
          check_status(delete_space_provider(SID, ProviderId, UserReqParams))
      ),
  
      ?assertMatch(
          [],
          get_space_providers(SID, UserReqParams)
      ).
  
  spaces_privileges_test(Config) ->
      RestAddress = ?config(restAddress, Config),
      [Node] = ?config(gr_nodes, Config),
      ReqParams = {RestAddress, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderId, ProviderReqParams} =
              register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, Config, ReqParams),
  
       %% create users
      UserId1 = create_user(?USER_NAME1, Node),
      UserId2 = create_user(?USER_NAME2, Node),
      UserId3 = create_user(?USER_NAME3, Node),
  
      %% authenticate users
      NewHeaders = auth_user(UserId1, ProviderId, ReqParams, Node),
      UserReqParams1 = update_req_params(ProviderReqParams, NewHeaders, headers),
      NewHeaders2 = auth_user(UserId2, ProviderId, ReqParams, Node),
      UserReqParams2 = update_req_params(ProviderReqParams, NewHeaders2, headers),
      NewHeaders3 = auth_user(UserId3, ProviderId, ReqParams, Node),
      UserReqParams3 = update_req_params(ProviderReqParams, NewHeaders3, headers),
  
      GID = create_group(?GROUP_NAME1, UserReqParams2),
      SID = create_space_for_user(?SPACE_NAME1, UserReqParams1),
      InvitationToken = get_space_invitation_token(users, SID, UserReqParams1),
      join_user_to_space(InvitationToken, UserReqParams2),
  
negative.code:     ?assertMatch(ok, check_status(delete_group(SID, UserReqParams2))).
  
  clean_space_privileges(SID, UserId, ReqParams) ->
      set_space_privileges(users, SID, UserId, [space_view_data], ReqParams).