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.

memberships_controller_test.rb 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. require "test_helper"
  2. class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
  3. setup do
  4. @membership = memberships(:one)
  5. @user = users(:one)
  6. @user2 = users(:two)
  7. @team = teams(:one)
  8. @team2 = teams(:two)
  9. end
  10. # INDEX
  11. test "should access Membership index" do
  12. get api_v1_memberships_url,
  13. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  14. as: :json
  15. assert_response :success
  16. end
  17. test "should forbid Membership index" do
  18. get api_v1_memberships_url,
  19. as: :json
  20. assert_response :forbidden
  21. end
  22. # SHOW
  23. test "should show Membership" do
  24. get api_v1_memberships_url(@membership),
  25. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  26. as: :json
  27. assert_response :success
  28. end
  29. test "should forbid show Membership" do
  30. get api_v1_memberships_url(@membership),
  31. as: :json
  32. assert_response :forbidden
  33. end
  34. # CREATE
  35. # test "should create membership" do
  36. # assert_difference("Membership.count") do
  37. # post api_v1_memberships_url,
  38. # params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
  39. # headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  40. # as: :json
  41. # end
  42. # assert_response :created
  43. # end
  44. test "should forbid create membership" do
  45. assert_no_difference("Membership.count") do
  46. post api_v1_memberships_url,
  47. params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
  48. as: :json
  49. end
  50. assert_response :forbidden
  51. end
  52. # UPDATE
  53. test "should update membership" do
  54. patch api_v1_membership_url(@membership),
  55. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  56. params: { membership: { can_edit: true } },
  57. as: :json
  58. assert_response :success
  59. end
  60. test "should forbid update membership" do
  61. patch api_v1_membership_url(@membership),
  62. params: { membership: { can_edit: true } },
  63. as: :json
  64. assert_response :forbidden
  65. end
  66. test "should forbid update read_only attributes - team_id" do
  67. patch api_v1_membership_url(@membership),
  68. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  69. params: { membership: { team_id: @team2.id, member_id: @user2.id } },
  70. as: :json
  71. assert_response :unprocessable_entity
  72. end
  73. # DESTROY
  74. test "should destroy membership" do
  75. assert_difference('Membership.count', -1) do
  76. delete api_v1_membership_url(@membership),
  77. headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
  78. as: :json
  79. end
  80. assert_response :no_content
  81. end
  82. test "should forbid destroy membership" do
  83. assert_no_difference('Membership.count') do
  84. delete api_v1_membership_url(@membership), as: :json
  85. end
  86. assert_response :forbidden
  87. end
  88. end