test/story_test.rb in tracker_api-1.5.0 vs test/story_test.rb in tracker_api-1.6.0

- old
+ new

@@ -1,11 +1,14 @@ require_relative 'minitest_helper' describe TrackerApi::Resources::Story do - let(:pt_user) { PT_USER_1 } - let(:client) { TrackerApi::Client.new token: pt_user[:token] } - let(:project_id) { pt_user[:project_id] } + let(:pt_user_1) { PT_USER_1 } + let(:pt_user_1_id) { pt_user_1[:id] } + let(:pt_user_2) { PT_USER_2 } + let(:pt_user_2_id) { pt_user_2[:id] } + let(:client) { TrackerApi::Client.new token: pt_user_1[:token] } + let(:project_id) { pt_user_1[:project_id] } let(:project) { VCR.use_cassette('get project') { client.project(project_id) } } let(:story_id) { '66728004' } let(:another_story_id) { '66728000' } let(:story_id_no_existing_labels) { '82330712' } let(:story) { VCR.use_cassette('get story') { project.story(story_id) } } @@ -114,24 +117,75 @@ owner.must_be_instance_of TrackerApi::Resources::Person end end end - describe "updating owners" do - it do - owner_ids = [VCR.use_cassette("get me", record: :new_episodes) { client.me.id }] + describe '.owner_ids' do + it 'gets owner_ids for this story' do + VCR.use_cassette('get story', record: :new_episodes) do + story = project.story(story_id) + owner_ids = story.owner_ids - refute_equal story.owner_ids, owner_ids + owner_ids.wont_be_empty + owner_ids.first.must_be_instance_of Fixnum + end + end - story.owner_ids = owner_ids + it 'update owners for a story' do + VCR.use_cassette('get story', record: :new_episodes) do + story = project.story(story_id) - VCR.use_cassette("save story with owner_ids changed", record: :new_episodes) do - story.save + # save with one owner + one_owner = [pt_user_1_id] + story.owner_ids = one_owner + VCR.use_cassette('save story with one owner') { story.save } + + story.owner_ids.wont_be_empty + story.owner_ids.must_equal one_owner + + # save with two owners + two_owners = [pt_user_1_id, pt_user_2_id] + story.owner_ids = two_owners + VCR.use_cassette('save story with two owners') { story.save } + + story.owner_ids.wont_be_empty + story.owner_ids.must_equal two_owners end + end + end - story.owner_ids.must_equal owner_ids + describe '.add_owner' do + it 'add owner to a story' do + VCR.use_cassette('get story', record: :new_episodes) do + story = project.story(story_id) + + # clear current owners + story.owner_ids = [] + + story.add_owner(TrackerApi::Resources::Person.new(id: 123)) + + story.owner_ids.wont_be_empty + story.owner_ids.must_equal [123] + end end + + it 'add owners by id to a story' do + VCR.use_cassette('get story', record: :new_episodes) do + story = project.story(story_id) + + # clear current owners + story.owner_ids = [] + + story.add_owner(123) + story.add_owner(456) + # test dups are not added + story.add_owner(123) + + story.owner_ids.wont_be_empty + story.owner_ids.must_equal [123, 456] + end + end end describe '.tasks' do it 'gets all tasks for this story with eager loading' do VCR.use_cassette('get story with tasks', record: :new_episodes) do @@ -198,31 +252,33 @@ event.must_be_instance_of TrackerApi::Resources::Activity end end end - describe '.owners' do - it 'gets all owners of this story' do - VCR.use_cassette('get story owners', record: :new_episodes) do - owners = story.owners - - owners.wont_be_empty - owner = owners.first - owner.must_be_instance_of TrackerApi::Resources::Person - end - end - end - describe '.comments' do it 'gets all comments of story with just project_id and story_id' do VCR.use_cassette('get story comments', record: :new_episodes) do story = TrackerApi::Resources::Story.new( client: client, project_id: project_id, id: story_id) comments = story.comments comment = comments.first comment.must_be_instance_of TrackerApi::Resources::Comment + end + end + end + + describe '.transitions' do + it 'gets all story transitions with just project_id and story_id' do + VCR.use_cassette('get story transitions', record: :new_episodes) do + story = TrackerApi::Resources::Story.new( client: client, + project_id: project_id, + id: another_story_id) + + transitions = story.transitions + transition = transitions.first + transition.must_be_instance_of TrackerApi::Resources::StoryTransition end end end end