# frozen_string_literal: true

require "oob"

class OOBTest < Minitest::Test
	def test_new
		oob = OOB.new
		assert_kind_of OOB, oob
		assert_nil oob.url
		assert_nil oob.desc
	end

	def test_new_with_node
		assert_kind_of OOB, OOB.new(Blather::XMPPNode.new)
	end

	property(:new_with_attrs) { [string(:alnum), string] }
	def new_with_attrs(url, description)
		oob = OOB.new(url, desc: description)
		assert_kind_of OOB, oob
		assert_equal url, oob.url
		assert_equal description, oob.desc
	end

	def test_find_or_create_not_found
		assert_kind_of OOB, OOB.find_or_create(Blather::XMPPNode.new)
	end

	def test_find_or_create_found
		parent = Blather::XMPPNode.new
		parent << OOB.new("http://example.com")
		assert_kind_of OOB, OOB.find_or_create(parent)
		assert_equal "http://example.com", OOB.find_or_create(parent).url
	end

	property(:url) { string(:alnum) }
	def url(a_url)
		oob = OOB.new
		oob.url = a_url
		assert_equal a_url, oob.url
	end

	property(:desc) { string }
	def desc(description)
		oob = OOB.new
		oob.desc = description
		assert_equal description, oob.desc
	end
end
