# ********** Copyright Viacom, Inc. Apache 2.0 ********** require_relative "../test_helper.rb" module RokuBuilder class LinkerTest < Minitest::Test def setup Logger.set_testing RokuBuilder.class_variable_set(:@@dev, false) RokuBuilder.setup_plugins register_plugins(Linker) @requests = [] end def teardown @requests.each {|req| remove_request_stub(req)} end def test_linker_parse_options_long parser = OptionParser.new options = {} Linker.parse_options(parser: parser, options: options) argv = ["roku", "--deeplink", "options", "--app-list", "--app", "app"] parser.parse! argv assert_equal "options", options[:deeplink] assert options[:applist] assert_equal "app", options[:app_id] end def test_linker_parse_options_short parser = OptionParser.new options = {} Linker.parse_options(parser: parser, options: options) argv = ["roku", "-o", "options", "-A", "-a", "app"] parser.parse! argv assert_equal "options", options[:deeplink] assert options[:applist] assert_equal "app", options[:app_id] end def test_linker_link @requests.push(stub_request(:post, "http://192.168.0.100:8060/launch/dev?a=A&b=B:C&d=a%5Cb"). to_return(status: 200, body: "", headers: {})) options = {deeplink: 'a:A, b:B:C, d:a\b'} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.deeplink(options: options) end def test_linker_link_sideload @requests.push(stub_request(:post, "http://192.168.0.100:8060/launch/dev?a=A&b=B:C&d=a%5Cb"). to_return(status: 200, body: "", headers: {})) @requests.push(stub_request(:post, "http://192.168.0.100:8060/keypress/Home"). to_return(status: 200, body: "", headers: {})) @requests.push(stub_request(:post, "http://192.168.0.100/plugin_install"). to_return(status: 200, body: "Install Success", headers: {})) options = {deeplink: 'a:A, b:B:C, d:a\b', working: true} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.deeplink(options: options) end def test_linker_link_sideload_current @requests.push(stub_request(:post, "http://192.168.0.100:8060/launch/dev?a=A&b=B:C&d=a%5Cb"). to_return(status: 200, body: "", headers: {})) @requests.push(stub_request(:post, "http://192.168.0.100:8060/keypress/Home"). to_return(status: 200, body: "", headers: {})) @requests.push(stub_request(:post, "http://192.168.0.100/plugin_install"). to_return(status: 200, body: "Install Success", headers: {})) options = {deeplink: 'a:A, b:B:C, d:a\b', current: true} config = nil Pathname.stub(:pwd, test_files_path(LinkerTest)) do config, options = build_config_options_objects(LinkerTest, options, false) end linker = Linker.new(config: config) linker.deeplink(options: options) end def test_linker_link_app @requests.push(stub_request(:post, "http://192.168.0.100:8060/launch/1234?a=A&b=B:C&d=a%5Cb"). to_return(status: 200, body: "", headers: {})) options = {deeplink: 'a:A, b:B:C, d:a\b', app_id: "1234"} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.deeplink(options: options) end def test_linker_link_nothing @requests.push(stub_request(:post, "http://192.168.0.100:8060/launch/dev"). to_return(status: 200, body: "", headers: {})) options = {deeplink: ''} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.deeplink(options: options) end def test_linker_link_sideload_input @requests.push(stub_request(:post, "http://192.168.0.100:8060/input?a=A&b=B:C&d=a%5Cb"). to_return(status: 200, body: "", headers: {})) @requests.push(stub_request(:post, "http://192.168.0.100:8060/keypress/Home"). to_return(status: 200, body: "", headers: {})) @requests.push(stub_request(:post, "http://192.168.0.100/plugin_install"). to_return(status: 200, body: "Install Success", headers: {})) options = {input: 'a:A, b:B:C, d:a\b', working: true} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.input(options: options) end def test_linker_link_app_input @requests.push(stub_request(:post, "http://192.168.0.100:8060/input?a=A&b=B:C&d=a%5Cb"). to_return(status: 200, body: "", headers: {})) options = {input: 'a:A, b:B:C, d:a\b', app_id: "1234"} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.input(options: options) end def test_linker_link_nothing_input @requests.push(stub_request(:post, "http://192.168.0.100:8060/input"). to_return(status: 200, body: "", headers: {})) options = {input: ''} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) linker.input(options: options) end def test_linker_list body = "\n\n\t Movie Store and TV Store\n\t Roku Home News\n\t Nick\n\t Nick\n\t \n" @requests.push(stub_request(:get, "http://192.168.0.100:8060/query/apps"). to_return(status: 200, body: body, headers: {})) options = {applist: true} config, options = build_config_options_objects(LinkerTest, options, false) linker = Linker.new(config: config) print_count = 0 did_print = Proc.new { |msg| print_count+=1 } linker.stub(:printf, did_print) do linker.applist(options: options) end assert_equal 6, print_count end end end