summaryrefslogtreecommitdiff
path: root/users/test
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-24 12:23:04 -0800
committerjessib <jessib@riseup.net>2013-12-24 12:36:42 -0800
commite4390e2ee5b2df20038f12865db462cf1e208ee6 (patch)
tree459db7c00d99d4182a4793a22623364cb931b2a6 /users/test
parenta9ff52501e9c04edacd250dd94ee3f3ad28cd73d (diff)
Add API tests and some refactoring of messages so we can get a user's messages within the webapp.
Diffstat (limited to 'users/test')
-rw-r--r--users/test/functional/v1/messages_controller_test.rb44
1 files changed, 44 insertions, 0 deletions
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