|
@@ -1,72 +0,0 @@
|
1
|
|
-require "test_helper"
|
2
|
|
-
|
3
|
|
-class Api::V1::RecordsControllerTest < ActionDispatch::IntegrationTest
|
4
|
|
- setup do
|
5
|
|
- @record = records(:one)
|
6
|
|
- @activity = activities(:one)
|
7
|
|
- @task = tasks(:one)
|
8
|
|
- @user_two = users(:two)
|
9
|
|
- end
|
10
|
|
-
|
11
|
|
- # INDEX
|
12
|
|
- test "should access index" do
|
13
|
|
- get api_v1_activity_task_records_url(@activity, @task),
|
14
|
|
- headers: { Authorization: JsonWebToken.encode(user_id: @record.user_id) },
|
15
|
|
- as: :json
|
16
|
|
- assert_response :success
|
17
|
|
- end
|
18
|
|
-
|
19
|
|
- test "should not access index" do
|
20
|
|
- get api_v1_activity_task_records_url(@activity, @task),
|
21
|
|
- as: :json
|
22
|
|
- assert_response :forbidden
|
23
|
|
- end
|
24
|
|
-
|
25
|
|
- # SHOW
|
26
|
|
- test "should access show" do
|
27
|
|
- get api_v1_activity_task_record_url(@activity, @task, @record),
|
28
|
|
- headers: { Authorization: JsonWebToken.encode(user_id: @record.user_id) },
|
29
|
|
- as: :json
|
30
|
|
- assert_response :success
|
31
|
|
-
|
32
|
|
- json_response = JSON.parse(self.response.body)
|
33
|
|
- assert_equal @record.duration, json_response['data']['attributes']['duration']
|
34
|
|
- assert_equal @record.user_id, json_response['data']['attributes']['user_id']
|
35
|
|
- assert_equal @record.task_id, json_response['data']['attributes']['task_id']
|
36
|
|
- assert_equal @record.is_handled, json_response['data']['attributes']['is_handled']
|
37
|
|
- end
|
38
|
|
-
|
39
|
|
- test "should not access show" do
|
40
|
|
- get api_v1_activity_task_record_url(@activity, @task, @record),
|
41
|
|
- as: :json
|
42
|
|
- assert_response :forbidden
|
43
|
|
- end
|
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
|
72
|
|
-end
|