|
9 | 9 | describe 'Integration tests' do |
10 | 10 | before(:all) do |
11 | 11 | @client = Stream::Client.new(ENV.fetch('STREAM_API_KEY'), ENV.fetch('STREAM_API_SECRET'), nil, location: ENV.fetch('STREAM_REGION', nil), default_timeout: 10) |
| 12 | + @url = @client.get_http_client.conn.url_prefix.to_s.gsub(%r{/+$}, '') |
12 | 13 | @feed42 = @client.feed('flat', generate_uniq_feed_name) |
13 | 14 | @feed43 = @client.feed('flat', generate_uniq_feed_name) |
14 | 15 |
|
|
363 | 364 | example 'add incomplete activity' do |
364 | 365 | expect do |
365 | 366 | @feed42.add_activity({}) |
366 | | - end.to raise_error Stream::StreamApiResponseException |
| 367 | + end.to raise_error Stream::StreamApiResponseInputException |
367 | 368 | end |
368 | 369 |
|
369 | 370 | it 'should be able to follow many feeds in one request' do |
|
379 | 380 | { source: 'badfeed:1', target: 'alsobad:1' }, |
380 | 381 | { source: 'extrabadfeed:1', target: 'reallybad:3' } |
381 | 382 | ] |
382 | | - url = @client.get_http_client.conn.url_prefix.to_s.gsub(%r{/+$}, '') |
383 | 383 | expect do |
384 | 384 | @client.follow_many(follows, 5000) |
385 | 385 | end.to raise_error( |
386 | | - Stream::StreamApiResponseException, |
387 | | - %r{^POST #{url}/follow_many/\?activity_copy_limit=5000&api_key=[^:]+: 400: InputException details: activity_copy_limit must be a non-negative number not greater than 1000$} |
| 386 | + Stream::StreamApiResponseInputException, |
| 387 | + %r{^POST #{@url}/follow_many/\?activity_copy_limit=5000&api_key=[^:]+: 400: InputException details: activity_copy_limit must be a non-negative number not greater than 1000$} |
388 | 388 | ) |
389 | 389 | end |
390 | 390 |
|
|
401 | 401 | { source: 'user:1', target: 'timeline:1' }, |
402 | 402 | { source: 'user:2', target: 42, keep_history: false } |
403 | 403 | ] |
404 | | - url = @client.get_http_client.conn.url_prefix.to_s.gsub(%r{/+$}, '') |
405 | 404 | expect do |
406 | 405 | @client.unfollow_many(unfollows) |
407 | 406 | end.to raise_error( |
408 | | - Stream::StreamApiResponseException, |
409 | | - %r{^POST #{url}/unfollow_many/\?api_key=[^:]+: 400: InputException details: invalid request payload$} |
| 407 | + Stream::StreamApiResponseInputException, |
| 408 | + %r{^POST #{@url}/unfollow_many/\?api_key=[^:]+: 400: InputException details: invalid request payload$} |
410 | 409 | ) |
411 | 410 | end |
412 | 411 |
|
|
416 | 415 | @client.add_to_many(activity_data, feeds) |
417 | 416 | end |
418 | 417 |
|
| 418 | + # Create a `invalid_aggregation_format` aggregated feed group with the aggregation format |
| 419 | + # `{{test[]}}`. |
| 420 | + it 'should return an error if the aggregation format is invalid' do |
| 421 | + feed_name = generate_uniq_feed_name |
| 422 | + feed = @client.feed('invalid_aggregation_format', feed_name) |
| 423 | + feed.add_activity(actor: 1, verb: 'tweet', object: 1) |
| 424 | + |
| 425 | + expect do |
| 426 | + feed.get(limit: 5) |
| 427 | + end.to raise_error( |
| 428 | + Stream::StreamApiResponseJinjaRuntimeException, |
| 429 | + %r{^GET #{@url}/feed/invalid_aggregation_format/#{feed_name}/\?api_key=[^&]+&limit=5: 400: JinjaRuntimeException details: the format contains syntax errors$} |
| 430 | + ) |
| 431 | + end |
| 432 | + |
| 433 | + it 'should return an error if the api key is invalid' do |
| 434 | + client = Stream::Client.new('invalid', 'invalid', nil, location: ENV.fetch('STREAM_REGION', nil), default_timeout: 10) |
| 435 | + feed_name = generate_uniq_feed_name |
| 436 | + feed = client.feed('notification', feed_name) |
| 437 | + expect do |
| 438 | + feed.get(limit: 5) |
| 439 | + end.to raise_error( |
| 440 | + Stream::StreamApiResponseApiKeyException, |
| 441 | + %r{^GET #{@url}/feed/notification/#{feed_name}/\?api_key=[^&]+&limit=5: 401: Bad feed$} |
| 442 | + ) |
| 443 | + end |
| 444 | + |
| 445 | + it 'should return an error if the api secret is invalid' do |
| 446 | + client = Stream::Client.new(ENV.fetch('STREAM_API_KEY'), 'invalid', nil, location: ENV.fetch('STREAM_REGION', nil), default_timeout: 10) |
| 447 | + feed_name = generate_uniq_feed_name |
| 448 | + feed = client.feed('notification', feed_name) |
| 449 | + expect do |
| 450 | + feed.get(limit: 5) |
| 451 | + end.to raise_error( |
| 452 | + Stream::StreamApiResponseNotAllowedException, |
| 453 | + %r{^GET #{@url}/feed/notification/#{feed_name}/\?api_key=[^&]+&limit=5: 403: Bad auth/headers$} |
| 454 | + ) |
| 455 | + end |
| 456 | + |
419 | 457 | example 'updating many feed activities' do |
420 | 458 | activities = [] |
421 | | - (0..10).each do |i| |
| 459 | + 11.times do |i| |
422 | 460 | activities << { |
423 | 461 | actor: 'user:1', |
424 | 462 | verb: 'do', |
|
464 | 502 | end |
465 | 503 | example 'add object to collection twice' do |
466 | 504 | @client.collections.add('animals', { type: 'bear' }, id: @item_id) |
467 | | - expect { @client.collections.add('animals', {}, id: @item_id) }.to raise_error Stream::StreamApiResponseException |
| 505 | + expect { @client.collections.add('animals', {}, id: @item_id) }.to raise_error Stream::StreamApiResponseInputException |
468 | 506 | end |
469 | 507 | example 'get collection item' do |
470 | 508 | @client.collections.add('animals', { type: 'fox' }, id: @item_id) |
|
482 | 520 | example 'collection item delete' do |
483 | 521 | @client.collections.add('animals', { type: 'snake' }, id: @item_id) |
484 | 522 | @client.collections.delete('animals', @item_id) |
485 | | - expect { @client.collections.get('animals', @item_id) }.to raise_error Stream::StreamApiResponseException |
| 523 | + expect { @client.collections.get('animals', @item_id) }.to raise_error Stream::StreamApiResponseDoesNotExistException |
486 | 524 | end |
487 | 525 | end |
488 | 526 |
|
|
604 | 642 | }) |
605 | 643 | activity.delete('duration') |
606 | 644 |
|
607 | | - expect { @client.get_activities }.to raise_error Stream::StreamApiResponseException |
| 645 | + expect { @client.get_activities }.to raise_error Stream::StreamApiResponseInputException |
608 | 646 |
|
609 | 647 | # get by ID |
610 | 648 | by_id = @client.get_activities( |
|
837 | 875 | end |
838 | 876 | example 'add user twice with error' do |
839 | 877 | @client.users.add(@user_id) |
840 | | - expect { @client.users.add(@user_id) }.to raise_error Stream::StreamApiResponseException |
| 878 | + expect { @client.users.add(@user_id) }.to raise_error Stream::StreamApiResponseConflictException |
841 | 879 | end |
842 | 880 | example 'get user' do |
843 | 881 | create_response = @client.users.add(@user_id, data: { animal: 'wolf' }) |
|
848 | 886 |
|
849 | 887 | expect(get_response).to eq create_response |
850 | 888 | end |
| 889 | + example 'get user with does not exist error' do |
| 890 | + expect do |
| 891 | + @client.users.get(@user_id) |
| 892 | + end.to raise_error( |
| 893 | + Stream::StreamApiResponseDoesNotExistException, |
| 894 | + %r{^GET #{@url}/user/#{@user_id}/\?api_key=[^:]+: 404: url not found$} |
| 895 | + ) |
| 896 | + end |
851 | 897 | example 'update user' do |
852 | 898 | @client.users.add(@user_id) |
853 | 899 | response = @client.users.update(@user_id, data: { animal: 'dog' }) |
|
857 | 903 | example 'delete user' do |
858 | 904 | @client.users.add(@user_id) |
859 | 905 | @client.users.delete(@user_id) |
860 | | - expect { @client.users.get(@user_id) }.to raise_error Stream::StreamApiResponseException |
| 906 | + expect { @client.users.get(@user_id) }.to raise_error Stream::StreamApiResponseDoesNotExistException |
861 | 907 | end |
862 | 908 | end |
863 | 909 |
|
|
903 | 949 | example 'delete reaction' do |
904 | 950 | reaction = @client.reactions.add('like', @activity['id'], 'jim') |
905 | 951 | @client.reactions.delete(reaction['id']) |
906 | | - expect { @client.reactions.get(reaction['id']) }.to raise_error Stream::StreamApiResponseException |
| 952 | + expect { @client.reactions.get(reaction['id']) }.to raise_error Stream::StreamApiResponseDoesNotExistException |
907 | 953 | end |
908 | 954 | example 'filter reactions' do |
909 | 955 | parent = @client.reactions.add('like', @activity['id'], 'jim') |
|
0 commit comments