|
@@ -5,6 +5,7 @@ class Api::V1::RecordsControllerTest < ActionDispatch::IntegrationTest
|
5
|
5
|
@record = records(:one)
|
6
|
6
|
@activity = activities(:one)
|
7
|
7
|
@task = tasks(:one)
|
|
8
|
+ @user_two = users(:two)
|
8
|
9
|
end
|
9
|
10
|
|
10
|
11
|
# INDEX
|
|
@@ -41,4 +42,31 @@ class Api::V1::RecordsControllerTest < ActionDispatch::IntegrationTest
|
41
|
42
|
assert_response :forbidden
|
42
|
43
|
end
|
43
|
44
|
|
|
45
|
+ # CREATE
|
|
46
|
+ test "should create task" do
|
|
47
|
+ assert_difference("Record.count") do
|
|
48
|
+ post api_v1_activity_task_records_url(@activity, @task),
|
|
49
|
+ params: { record: { duration: @record.duration, user_id: @record.user_id, task_id: @record.task_id } },
|
|
50
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @record.user_id) },
|
|
51
|
+ as: :json
|
|
52
|
+ end
|
|
53
|
+ assert_response :created
|
|
54
|
+ end
|
|
55
|
+
|
|
56
|
+ test "should not create task" do
|
|
57
|
+ assert_no_difference("Record.count") do
|
|
58
|
+ post api_v1_activity_task_records_url(@activity, @task),
|
|
59
|
+ params: { record: { duration: @record.duration, user_id: @record.user_id, task_id: @record.task_id } },
|
|
60
|
+ as: :json
|
|
61
|
+ end
|
|
62
|
+ assert_response :forbidden
|
|
63
|
+ end
|
|
64
|
+
|
|
65
|
+ # UPDATE
|
|
66
|
+ test "should update task" do
|
|
67
|
+ patch api_v1_activity_task_record_url(@activity, @task, @record),
|
|
68
|
+ params: { task: { is_handled: true } },
|
|
69
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user_two.id) },
|
|
70
|
+ as: :json
|
|
71
|
+ end
|
44
|
72
|
end
|