|
@@ -0,0 +1,66 @@
|
|
1
|
+require "test_helper"
|
|
2
|
+
|
|
3
|
+class Api::V1::TeamsControllerTest < ActionDispatch::IntegrationTest
|
|
4
|
+ setup do
|
|
5
|
+ @team = teams(:one)
|
|
6
|
+ @user = users(:one)
|
|
7
|
+ end
|
|
8
|
+
|
|
9
|
+ # INDEX
|
|
10
|
+ test "should access team index" do
|
|
11
|
+ get api_v1_teams_url,
|
|
12
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
13
|
+ as: :json
|
|
14
|
+ assert_response :success
|
|
15
|
+ end
|
|
16
|
+
|
|
17
|
+ test "should forbid team index" do
|
|
18
|
+ get api_v1_teams_url, as: :json
|
|
19
|
+ assert_response :forbidden
|
|
20
|
+ end
|
|
21
|
+
|
|
22
|
+ # SHOW
|
|
23
|
+ test "should show team" do
|
|
24
|
+ get api_v1_team_url(@team),
|
|
25
|
+ headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
|
|
26
|
+ as: :json
|
|
27
|
+ assert_response :success
|
|
28
|
+ end
|
|
29
|
+
|
|
30
|
+ # SHOW
|
|
31
|
+ test "should forbid show team" do
|
|
32
|
+ get api_v1_team_url(@team),
|
|
33
|
+ as: :json
|
|
34
|
+ assert_response :forbidden
|
|
35
|
+ end
|
|
36
|
+
|
|
37
|
+ # CREATE
|
|
38
|
+ test "should create team" do
|
|
39
|
+ assert_difference('Team.count') do
|
|
40
|
+ post api_v1_teams_url, params: { team: { name: "Random name", description: "Random description" } }, headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, as: :json
|
|
41
|
+ end
|
|
42
|
+ assert_response :created
|
|
43
|
+ end
|
|
44
|
+
|
|
45
|
+ test "should not create team when not logged in" do
|
|
46
|
+ assert_no_difference('Team.count') do
|
|
47
|
+ post api_v1_teams_url, params: { team: { name: "Random name", description: "Random description" } }, as: :json
|
|
48
|
+ end
|
|
49
|
+ assert_response :forbidden
|
|
50
|
+ end
|
|
51
|
+
|
|
52
|
+ test "should not create team with taken name" do
|
|
53
|
+ assert_no_difference('Team.count') do
|
|
54
|
+ post api_v1_teams_url, params: { team: { name: @team.name, description: "Random description" } }, headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, as: :json
|
|
55
|
+ end
|
|
56
|
+ assert_response :unprocessable_entity
|
|
57
|
+ end
|
|
58
|
+
|
|
59
|
+ test "should not create team without name" do
|
|
60
|
+ assert_no_difference('Team.count') do
|
|
61
|
+ post api_v1_teams_url, params: { team: { description: "Random description"} }, headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, as: :json
|
|
62
|
+ end
|
|
63
|
+ assert_response :unprocessable_entity
|
|
64
|
+ end
|
|
65
|
+
|
|
66
|
+end
|