|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +app_require "fever_api/read_items" |
| 4 | + |
| 5 | +describe FeverAPI::ReadItems do |
| 6 | + let(:story_repository) { double('repo') } |
| 7 | + |
| 8 | + subject do |
| 9 | + FeverAPI::ReadItems.new(story_repository: story_repository) |
| 10 | + end |
| 11 | + |
| 12 | + it "returns a list of unread items including total count" do |
| 13 | + story_repository.should_receive(:unread).twice.and_return([ |
| 14 | + double('story', as_fever_json: { id: 5 } ), |
| 15 | + double('story', as_fever_json: { id: 7 } ), |
| 16 | + double('story', as_fever_json: { id: 11 } ) |
| 17 | + ]) |
| 18 | + subject.call('items' => nil).should == { |
| 19 | + items: [ |
| 20 | + { id: 5 }, |
| 21 | + { id: 7 }, |
| 22 | + { id: 11 } |
| 23 | + ], |
| 24 | + total_items: 3 |
| 25 | + } |
| 26 | + end |
| 27 | + |
| 28 | + it "returns a list of unread items since id including total count" do |
| 29 | + story_repository.should_receive(:unread_since_id).with(3).and_return([ |
| 30 | + double('story', as_fever_json: { id: 5 } ), |
| 31 | + double('story', as_fever_json: { id: 7 } ), |
| 32 | + ]) |
| 33 | + story_repository.should_receive(:unread).and_return([ |
| 34 | + double('story', as_fever_json: { id: 2 } ), |
| 35 | + double('story', as_fever_json: { id: 5 } ), |
| 36 | + double('story', as_fever_json: { id: 7 } ), |
| 37 | + ]) |
| 38 | + subject.call('items' => nil, since_id: 3).should == { |
| 39 | + items: [ |
| 40 | + { id: 5 }, |
| 41 | + { id: 7 }, |
| 42 | + ], |
| 43 | + total_items: 3 |
| 44 | + } |
| 45 | + end |
| 46 | + |
| 47 | + it "returns a list of specified items including total count" do |
| 48 | + story_repository.should_receive(:fetch_by_ids).with(['5', '11']).twice.and_return([ |
| 49 | + double('story', as_fever_json: { id: 5 } ), |
| 50 | + double('story', as_fever_json: { id: 11 } ) |
| 51 | + ]) |
| 52 | + subject.call('items' => nil, with_ids: '5,11').should == { |
| 53 | + items: [ |
| 54 | + { id: 5 }, |
| 55 | + { id: 11 } |
| 56 | + ], |
| 57 | + total_items: 2 |
| 58 | + } |
| 59 | + end |
| 60 | + |
| 61 | + it "returns an empty hash otherwise" do |
| 62 | + subject.call({}).should == {} |
| 63 | + end |
| 64 | +end |
0 commit comments