API de comptabilité horaire.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tasks_controller_test.rb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. require "test_helper"
  2. class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
  3. setup do
  4. @task = tasks(:one)
  5. @activity = activities(:one)
  6. @user = users(:one)
  7. end
  8. # INDEX
  9. test "should access index" do
  10. get api_v1_activity_tasks_url(@activity),
  11. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  12. as: :json
  13. assert_response :success
  14. end
  15. test "should not access index" do
  16. get api_v1_activity_tasks_url(@activity),
  17. as: :json
  18. assert_response :forbidden
  19. end
  20. # SHOW
  21. test "should access show" do
  22. get api_v1_activity_task_url(@activity, @task),
  23. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  24. as: :json
  25. assert_response :success
  26. end
  27. test "should not access show" do
  28. get api_v1_activity_task_url(@activity, @task),
  29. as: :json
  30. assert_response :forbidden
  31. end
  32. # CREATE
  33. test "should create task" do
  34. assert_difference("Task.count") do
  35. post api_v1_activity_tasks_url(@activity),
  36. params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
  37. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  38. as: :json
  39. end
  40. assert_response :created
  41. end
  42. test "should forbid create task - not logged in" do
  43. assert_no_difference("Task.count") do
  44. post api_v1_activity_tasks_url(@activity),
  45. params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
  46. as: :json
  47. end
  48. assert_response :forbidden
  49. end
  50. test "should forbid create task - missing user or activity id" do
  51. assert_no_difference("Task.count") do
  52. post api_v1_activity_tasks_url(@activity),
  53. params: { task: { name: @task.name, description: @task.description } },
  54. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  55. as: :json
  56. end
  57. assert_response :forbidden
  58. end
  59. end