@@ -8,10 +8,16 @@ class ExpoPushTokensTest < Redmine::ApiTest::Base
8
8
@jsmith = User . find_by_login 'jsmith'
9
9
10
10
@creds = { 'X-Redmine-API-Key' => @user . api_key }
11
+ @jsmith_creds = { 'X-Redmine-API-Key' => @jsmith . api_key }
12
+ @admin_creds = { 'X-Redmine-API-Key' => User . find_by_login ( 'admin' ) . api_key }
11
13
@payload = <<-JSON
12
14
{ "token": "asdf1234" }
13
15
JSON
14
16
17
+ @user_id_payload = <<-JSON
18
+ { "token": "asdf1234", "user_id": "#{ @user . id } " }
19
+ JSON
20
+
15
21
@t1 = ExpoPushToken . create! user : @user , token : "asdf.1234"
16
22
@t2 = ExpoPushToken . create! user : User . find_by_login ( 'jsmith' ) , token : "asdf.1234"
17
23
end
@@ -99,4 +105,26 @@ class ExpoPushTokensTest < Redmine::ApiTest::Base
99
105
end
100
106
@t1 . reload
101
107
end
108
+
109
+
110
+ test 'admin should be able to create token with optional user id' do
111
+ assert_difference "ExpoPushToken.count" do
112
+ post "/expo_push_tokens.json" ,
113
+ params : @user_id_payload ,
114
+ headers : { "CONTENT_TYPE" => 'application/json' } . merge ( @admin_creds )
115
+ assert_response 201
116
+ end
117
+ assert_equal @user . id , ExpoPushToken . last . user_id
118
+ end
119
+
120
+ test 'non-admin should not able to create token with optional user id' do
121
+ assert_difference "ExpoPushToken.count" do
122
+ post "/expo_push_tokens.json" ,
123
+ params : @user_id_payload ,
124
+ headers : { "CONTENT_TYPE" => 'application/json' } . merge ( @jsmith_creds )
125
+ assert_response 201
126
+ end
127
+ assert_equal @jsmith . id , ExpoPushToken . last . user_id
128
+ end
129
+
102
130
end
0 commit comments