2014-04-07 18:41:34 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Campaign, 'associations' do
|
2014-04-09 18:37:46 +00:00
|
|
|
let(:campaign){ attributes_for :campaign }
|
2014-04-07 18:41:34 +00:00
|
|
|
it {should have_many(:videolistings) }
|
2014-04-09 18:37:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
it 'disallows duplicate listingcode' do
|
|
|
|
one = Campaign.new(campaign)
|
|
|
|
one.save
|
|
|
|
two = Campaign.new(campaign)
|
|
|
|
two.listingcode = one.listingcode
|
|
|
|
|
|
|
|
expect(two.valid?).to be false
|
|
|
|
end
|
|
|
|
|
2014-04-28 18:16:43 +00:00
|
|
|
|
|
|
|
it 'shows how complete the videos are by percentage' do
|
|
|
|
camp = Campaign.new(campaign)
|
|
|
|
video_1 = FactoryGirl.create(:videolisting)
|
|
|
|
video_2 = FactoryGirl.create(:videolisting)
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(0) # no associations
|
|
|
|
|
|
|
|
|
|
|
|
camp.videolistings << video_1
|
|
|
|
camp.videolistings << video_2
|
|
|
|
camp.save
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(0)
|
|
|
|
|
|
|
|
camp.videolistings.first.published = true
|
|
|
|
camp.videolistings.first.save
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(50)
|
|
|
|
|
|
|
|
camp.videolistings.last.published = true
|
|
|
|
camp.videolistings.last.save
|
|
|
|
|
|
|
|
expect(camp.video_completion_percent).to eq(100)
|
|
|
|
end
|
|
|
|
|
2014-05-06 16:20:19 +00:00
|
|
|
|
|
|
|
it 'gets the proper better video format' do
|
|
|
|
campaign = FactoryGirl.build(:campaign)
|
|
|
|
campaign.save
|
|
|
|
bv_fmt = campaign.to_bettervideo_format
|
|
|
|
|
|
|
|
expect(JSON.parse(bv_fmt)['key']).to eq("PRO1234")
|
|
|
|
expect(JSON.parse(bv_fmt)['campaigns'][0]["clientid"]).to eq(720)
|
|
|
|
expect(JSON.parse(bv_fmt)['campaigns'][0]["videolistings"].length).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends to better video and returns success' do
|
|
|
|
campaign = FactoryGirl.build(:campaign)
|
|
|
|
campaign.save
|
|
|
|
client = BetterVideo.new
|
|
|
|
bv_response = client.addVideo(campaign: campaign.to_bettervideo_format)
|
|
|
|
|
|
|
|
expect(bv_response[:success]).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'sends to better video and returns missing field' do
|
|
|
|
campaign = FactoryGirl.build(:campaign)
|
|
|
|
campaign.listingcode = "videolistingmissing"
|
|
|
|
campaign.save
|
|
|
|
client = BetterVideo.new
|
|
|
|
bv_response = client.addVideo(campaign: campaign.to_bettervideo_format)
|
|
|
|
|
|
|
|
expect(bv_response["errormessage"]).to eq("Required field [voiceoverselection] missing.")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends to better video and returns error' do
|
|
|
|
campaign = FactoryGirl.build(:campaign)
|
|
|
|
campaign.listingcode = "contactdev"
|
|
|
|
campaign.save
|
|
|
|
client = BetterVideo.new
|
|
|
|
bv_response = client.addVideo(campaign: campaign.to_bettervideo_format)
|
|
|
|
|
|
|
|
expect(bv_response[:message]).to include("Please Contact Dev")
|
|
|
|
end
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|