From e4390e2ee5b2df20038f12865db462cf1e208ee6 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 24 Dec 2013 12:23:04 -0800 Subject: Add API tests and some refactoring of messages so we can get a user's messages within the webapp. --- .../test/functional/v1/messages_controller_test.rb | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 users/test/functional/v1/messages_controller_test.rb (limited to 'users/test/functional') diff --git a/users/test/functional/v1/messages_controller_test.rb b/users/test/functional/v1/messages_controller_test.rb new file mode 100644 index 0000000..de2182b --- /dev/null +++ b/users/test/functional/v1/messages_controller_test.rb @@ -0,0 +1,44 @@ +require 'test_helper' + + +class V1::MessagesControllerTest < ActionController::TestCase + + #TODO ensure authentication for all tests here + + setup do + @user = FactoryGirl.build(:user) + @user.save + @message = Message.new(:text => 'a test message') + @message.save + @user_message = UserMessage.new(:message_id => @message.id, :user_id => @user.id) + @user_message.save + end + + teardown do + @user_message.destroy + @user.destroy + @message.destroy + end + + test "get messages for user" do + get :user_messages, :user_id => @user.id + assert response.body.include? @message.text + assert response.body.include? @message.id + end + + test "mark message read for user" do + assert !@user_message.seen + put :mark_read, :user_id => @user.id, :message_id => @message.id + @user_message.reload + assert @user_message.seen + end + + test "do not get seen messages" do + @user_message.seen = true + @user_message.save + get :user_messages, :user_id => @user.id + assert !(response.body.include? @message.text) + assert !(response.body.include? @message.id) + end + +end -- cgit v1.2.3