Browse Source

Fix test (remove it), and add other unit test on def show

Lou 3 years ago
parent
commit
3e6506c7d7
1 changed files with 6 additions and 11 deletions
  1. 6
    11
      test/controllers/api/v1/tasks_controller_test.rb

+ 6
- 11
test/controllers/api/v1/tasks_controller_test.rb View File

27
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
27
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
28
     as: :json
28
     as: :json
29
     assert_response :success
29
     assert_response :success
30
+
31
+    json_response = JSON.parse(self.response.body)
32
+    assert_equal @task.name, json_response['data']['attributes']['name']
33
+    assert_equal @task.user_id, json_response['data']['attributes']['user_id']
34
+    assert_equal @task.activity_id, json_response['data']['attributes']['activity_id']
30
   end
35
   end
31
 
36
 
32
   test "should not access show" do
37
   test "should not access show" do
46
     assert_response :created
51
     assert_response :created
47
   end
52
   end
48
 
53
 
49
-  test "should forbid create task - not logged in" do
54
+  test "should forbid create task" do
50
     assert_no_difference("Task.count") do
55
     assert_no_difference("Task.count") do
51
       post api_v1_activity_tasks_url(@activity),
56
       post api_v1_activity_tasks_url(@activity),
52
       params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
57
       params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
54
     end
59
     end
55
     assert_response :forbidden
60
     assert_response :forbidden
56
   end
61
   end
57
-
58
-  test "should forbid create task - missing user or activity id" do
59
-    assert_no_difference("Task.count") do
60
-      post api_v1_activity_tasks_url(@activity),
61
-      params: { task: { name: @task.name, description: @task.description } },
62
-      headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
63
-      as: :json
64
-    end
65
-    assert_response :forbidden
66
-  end
67
 end
62
 end

Loading…
Cancel
Save