require 'test_helper' require 'test/unit' require './lib/smtpapi' # # SmtpapiTest implementation # class SmtpapiTest < Test::Unit::TestCase def test_version assert_equal('0.1.8', Smtpapi::VERSION) end def test_empty header = Smtpapi::Header.new assert_equal('{}', header.json_string) end def test_add_to header = Smtpapi::Header.new header.add_to('you@youremail.com') header.add_to('other@otheremail.com', 'Other Name') assert_equal( '{"to":["you@youremail.com","Other Name "]}', header.json_string ) end def test_add_to_array header = Smtpapi::Header.new header.add_to(['you@youremail.com', 'my@myemail.com']) assert_equal( '{"to":["you@youremail.com","my@myemail.com"]}', header.json_string ) end def test_set_tos header = Smtpapi::Header.new header.set_tos(['you@youremail.com', 'other@otheremail.com']) assert_equal( '{"to":["you@youremail.com","other@otheremail.com"]}', header.json_string ) end def test_add_substitution header = Smtpapi::Header.new header.add_substitution('keep', ['secret']) header.add_substitution('other', %w(one two)) assert_equal( '{"sub":{"keep":["secret"],"other":["one","two"]}}', header.json_string ) end def test_set_substitutions header = Smtpapi::Header.new header.set_substitutions('keep' => ['secret']) assert_equal('{"sub":{"keep":["secret"]}}', header.json_string) end def test_add_section header = Smtpapi::Header.new header.add_section('-charge-', 'This ship is useless.') header.add_section('-bomber-', 'Only for sad vikings.') assert_equal( '{"section":'\ '{"-charge-":"This ship is useless.",'\ '"-bomber-":"Only for sad vikings."}}', header.json_string ) end def test_set_sections header = Smtpapi::Header.new header.set_sections('-charge-' => 'This ship is useless.') assert_equal( '{"section":{"-charge-":"This ship is useless."}}', header.json_string ) end def test_add_unique_arg header = Smtpapi::Header.new header.add_unique_arg('cat', 'dogs') assert_equal('{"unique_args":{"cat":"dogs"}}', header.json_string) end def test_set_unique_args header = Smtpapi::Header.new header.set_unique_args('cow' => 'chicken') header.set_unique_args('dad' => 'proud') assert_equal('{"unique_args":{"dad":"proud"}}', header.json_string) end def test_add_category header = Smtpapi::Header.new header.add_category('tactics') header.add_category('advanced') assert_equal('{"category":["tactics","advanced"]}', header.json_string) end def test_set_categories header = Smtpapi::Header.new header.set_categories(%w(tactics advanced)) assert_equal('{"category":["tactics","advanced"]}', header.json_string) end def test_add_filter header = Smtpapi::Header.new header.add_filter('footer', 'enable', 1) header.add_filter('footer', 'text/html', 'boo') assert_equal( '{"filters":'\ '{"footer":'\ '{"settings":'\ '{"enable":1,'\ '"text/html":"boo"'\ '}'\ '}'\ '}'\ '}', header.json_string ) end def test_set_filters header = Smtpapi::Header.new filter = { 'footer' => { 'setting' => { 'enable' => 1, 'text/plain' => 'You can haz footers!' } } } header.set_filters(filter) assert_equal( '{"filters":'\ '{"footer":'\ '{"setting":'\ '{"enable":1,"text/plain":"You can haz footers!"}'\ '}'\ '}'\ '}', header.json_string ) end def test_add_category_unicode header = Smtpapi::Header.new header.add_category('Martí') header.add_category('天破活殺') header.add_category('天翔十字鳳') assert_equal( '{"category":'\ '["Mart\\u00ed",'\ '"\\u5929\\u7834\\u6d3b\\u6bba",'\ '"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3"]}', header.json_string ) header.add_category('鼖') assert_equal( '{"category":'\ '["Mart\\u00ed",'\ '"\\u5929\\u7834\\u6d3b\\u6bba",'\ '"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3",'\ '"\\ud87e\\ude1b"]}', header.json_string ) end def test_sent_send_at header = Smtpapi::Header.new localtime = Time.local(2014, 8, 29, 17, 56, 35) header.set_send_at(localtime) assert_equal("{\"send_at\":#{localtime.to_i}}", header.json_string) end def test_send_each_at header = Smtpapi::Header.new localtime1 = Time.local(2014, 8, 29, 17, 56, 35) localtime2 = Time.local(2013, 12, 31, 0, 0, 0) localtime3 = Time.local(2015, 9, 1, 4, 5, 6) header.set_send_each_at([localtime1, localtime2, localtime3]) assert_equal( '{"send_each_at":'\ "[#{localtime1.to_i},#{localtime2.to_i},#{localtime3.to_i}]"\ '}', header.json_string ) end def test_asm_group_id header = Smtpapi::Header.new header.set_asm_group(2) assert_equal('{"asm_group_id":2}', header.json_string) end def test_ip_pool header = Smtpapi::Header.new header.set_ip_pool('test_pool') assert_equal('{"ip_pool":"test_pool"}', header.json_string) end # def test_docker_exists # assert(File.file?('./Dockerfile') || File.file?('./docker/Dockerfile')) # end # def test_docker_compose_exists # assert( # File.file?('./docker-compose.yml') || # File.file?('./docker/docker-compose.yml') # ) # end def test_env_sample_exists assert(File.file?('./.env_sample')) end def test_gitignore_exists assert(File.file?('./.gitignore')) end def test_travis_exists assert(File.file?('./.travis.yml')) end def test_codeclimate_exists assert(File.file?('./.codeclimate.yml')) end def test_changelog_exists assert(File.file?('./CHANGELOG.md')) end def test_code_of_conduct_exists assert(File.file?('./CODE_OF_CONDUCT.md')) end def test_contributing_exists assert(File.file?('./CONTRIBUTING.md')) end def test_issue_template_exists assert(File.file?('./ISSUE_TEMPLATE.md')) end def test_license_exists assert(File.file?('./LICENSE.md') || File.file?('./LICENSE.txt')) end def test_pull_request_template_exists assert(File.file?('./PULL_REQUEST_TEMPLATE.md')) end def test_readme_exists assert(File.file?('./README.md')) end def test_troubleshooting_exists assert(File.file?('./TROUBLESHOOTING.md')) end # def test_usage_exists # assert(File.file?('./USAGE.md')) # end # def test_use_cases_exists # assert(File.file?('./USE_CASES.md')) # end def test_license_date_is_updated license_year = IO.read('LICENSE.md').match( /Copyright \(C\) (\d{4}), Twilio SendGrid/ )[1] current_year = Time.new.year assert_equal(current_year, license_year.to_i) end end