|
@@ -34,4 +34,34 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
|
34
|
34
|
as: :json
|
35
|
35
|
assert_response :forbidden
|
36
|
36
|
end
|
|
37
|
+
|
|
38
|
+ # CREATE
|
|
39
|
+ test "should create task" do
|
|
40
|
+ assert_difference("Task.count") do
|
|
41
|
+ post api_v1_activity_tasks_url(@activity),
|
|
42
|
+ params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
|
|
43
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
44
|
+ as: :json
|
|
45
|
+ end
|
|
46
|
+ assert_response :created
|
|
47
|
+ end
|
|
48
|
+
|
|
49
|
+ test "should forbid create task - not logged in" do
|
|
50
|
+ assert_no_difference("Task.count") do
|
|
51
|
+ post api_v1_activity_tasks_url(@activity),
|
|
52
|
+ params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
|
|
53
|
+ as: :json
|
|
54
|
+ end
|
|
55
|
+ assert_response :forbidden
|
|
56
|
+ 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
|
37
|
67
|
end
|