From 97ace0f06ab72b82ed0be4ca5c481f4f16a3c847 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 1 Apr 2016 02:25:36 -0700 Subject: api: added super simple motd, closes #7866 --- test/functional/v1/messages_controller_test.rb | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/functional/v1') diff --git a/test/functional/v1/messages_controller_test.rb b/test/functional/v1/messages_controller_test.rb index 720d862..67f34a1 100644 --- a/test/functional/v1/messages_controller_test.rb +++ b/test/functional/v1/messages_controller_test.rb @@ -2,6 +2,47 @@ require 'test_helper' class V1::MessagesControllerTest < ActionController::TestCase + setup do + @user = FactoryGirl.build(:user) + @user.save + end + + # NOTE: the available languages for test are :en and :de + # so :es will result in english response. + + test "get the motd" do + with_config("customization_directory" => Rails.root+'test/files') do + login @user + get :index, :locale => 'es' + body = JSON.parse(response.body) + p body + message1 = "

\"This\" is a very fine message. https://bitmask.net

\n" + assert_equal 2, body.size, 'there should be two messages' + assert_equal message1, body.first["text"], 'first message text should match files/motd/1.en.md' + end + end + + test "get localized motd" do + with_config("customization_directory" => Rails.root+'test/files') do + login @user + get :index, :locale => 'de' + body = JSON.parse(response.body) + message1 = "

Dies ist eine sehr feine Nachricht. https://bitmask.net

\n" + assert_equal message1, body.first["text"], 'first message text should match files/motd/1.de.md' + end + end + + test "get empty motd" do + login @user + get :index + assert_equal "[]", response.body, "motd response should be empty if no motd directory exists" + end + + ## + ## For now, only the static file MOTD is supported, not messages in the db. + ## so, this is disabled: + ## +=begin setup do InviteCodeValidator.any_instance.stubs(:validate) @user = FactoryGirl.build(:user) @@ -54,5 +95,6 @@ class V1::MessagesControllerTest < ActionController::TestCase get :index, :format => :json assert_login_required end +=end end -- cgit v1.2.3