require_relative 'helper' class DirectoriesTest < MiniTest::Unit::TestCase def setup @dirs = MxHero::API::Directories.new(domain, username: TEST_API_USER, password: TEST_API_PASSWORD, verbose: false, api_url: TEST_API_URL) end def domain 'test.com' end def test_directories_from_api directories = MxHero::API::Client.new(api_url: TEST_API_URL, username: TEST_API_USER, password: TEST_API_PASSWORD).directories(domain) assert directories.is_a? MxHero::API::Directories assert_equal domain, directories.instance_variable_get(:@domain) assert_equal TEST_API_URL, directories.instance_variable_get(:@service_url) assert_equal TEST_API_USER, directories.instance_variable_get(:@username) assert_equal TEST_API_PASSWORD, directories.instance_variable_get(:@password) assert ! directories.instance_variable_get(:@verbose) end def test_fetch VCR.use_cassette('fetch_directory') do directory = @dirs.fetch assert_equal domain, directory.domain assert_equal 'gapps', directory.type end end def test_create directory = MxHero::API::Directory.new(domain: 'test.com', type: 'gapps', user: 'user', password: 'password') VCR.use_cassette('create_directory') do response = @dirs.create directory assert response.success? # try to create again response = @dirs.create directory assert ! response.success? assert_equal 'domain.ldap.already.exists', response.error end end def test_update VCR.use_cassette('update_directory') do directory = @dirs.fetch directory.ssl = true directory.base = 'cn' directory.type = 'zimbra' directory.address = 'zertifikate.telekom.de' directory.port = '389' directory.user = 'user' directory.password = 'password' assert @dirs.update(directory).success? updated = @dirs.fetch assert_equal directory.ssl, updated.ssl assert_equal directory.base, updated.base assert_equal directory.type, updated.type assert_equal directory.address, updated.address assert_equal directory.port, updated.port assert_equal directory.user, updated.user assert_equal directory.password, updated.password end end def test_delete VCR.use_cassette('delete_directory') do deleted = @dirs.delete assert deleted.success? assert_nil @dirs.fetch # try to remove inexistent directory deleted = @dirs.delete assert ! deleted.success? assert_equal 'domain.ldap.not.found', deleted.error end end def test_updates_dates directory = MxHero::API::Directory.new directory.next_update = 1379949740000 directory.last_update = '1379949740000' expected = "2013-09-23T15:22:20+00:00" assert_equal expected, directory.next_update.to_s #23-09-2013 12:22 assert_equal expected, directory.last_update.to_s #23-09-2013 12:22 end end