require 'rubygems' require "test/unit" require "zencoder" require 'shoulda' require 'mocha' require 'ruby-debug' class TestZencoder < Test::Unit::TestCase context "the zn lib" do setup do @src='s3://gkt_sophia_development/spark.avi' @api = 'https://app.zencoder.com' @apikey = ENV['ZC_APIKEY'] @base_url = 's3://gkt_sophia_development/zencoder_asset' @recipe = ZencoderAPI::Recipes.iphone('base_url' =>@base_url) @recipe2 = ZencoderAPI::Recipes.web('base_url' =>@base_url) assert_not_nil @apikey, "export ZC_APIKEY before you run the tests" end context "posting a new job" do setup do end should "be able to submit a job" do RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z| assert_equal x, 'https://app.zencoder.com/api/jobs' body = JSON.parse(y) assert_equal body['input'], @src assert_equal body['output'][0]['base_url'], @base_url assert_equal body['output'][1]['base_url'], @base_url assert_equal body['output'][1]['label'], 'web' assert_equal body['output'][0]['label'], 'iphone' assert_equal body['api_key'], @apikey assert_equal z[:content_type], :json assert_equal z[:accept], :json true } Zencoder.submit_job(@apikey, @src, [@recipe, @recipe2]) end should "be able to muck the config " do RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z| body = JSON.parse(y) assert_equal body['foo'],'bar' true } Zencoder.submit_job(@apikey, @src, @recipe) do |config| config[:foo]='bar' end end should "be able to submit a job with 1 recipe" do RestClient.expects(:post).with(kind_of(String), kind_of(String), kind_of(Hash)){|x,y,z| assert_equal x, 'https://app.zencoder.com/api/jobs' body = JSON.parse(y) assert_equal body['input'], @src assert_equal body['output'][0]['base_url'], @base_url assert_equal body['output'][0]['label'], 'iphone' assert_equal body['api_key'], @apikey assert_equal z[:content_type], :json assert_equal z[:accept], :json true } Zencoder.submit_job(@apikey, @src, @recipe) end end end end