|
@@ -0,0 +1,38 @@
|
|
1
|
+require "test_helper"
|
|
2
|
+
|
|
3
|
+class Api::V1::UsersControllerTest < ActionDispatch::IntegrationTest
|
|
4
|
+ setup do
|
|
5
|
+ @user = users(:one)
|
|
6
|
+ end
|
|
7
|
+
|
|
8
|
+ #SHOW
|
|
9
|
+ test "should show user" do
|
|
10
|
+ get api_v1_user_url(@user), as: :json
|
|
11
|
+ assert_response :success
|
|
12
|
+ # Test to ensure response contains the correct email
|
|
13
|
+ json_response = JSON.parse(self.response.body)
|
|
14
|
+ assert_equal @user.email, json_response['email']
|
|
15
|
+ end
|
|
16
|
+
|
|
17
|
+ #CREATE
|
|
18
|
+ test "should create user" do
|
|
19
|
+ assert_difference('User.count') do
|
|
20
|
+ post api_v1_users_url, params: { user: { email: 'test@test.org', username: 'new_user_name', password: '123456' } }, as: :json
|
|
21
|
+ end
|
|
22
|
+ assert_response :created
|
|
23
|
+ end
|
|
24
|
+
|
|
25
|
+ test "should not create user with taken email" do
|
|
26
|
+ assert_no_difference('User.count') do
|
|
27
|
+ post api_v1_users_url, params: { user: { email: @user.email, username: 'username_test', password: '123456' } }, as: :json
|
|
28
|
+ end
|
|
29
|
+ assert_response :unprocessable_entity
|
|
30
|
+ end
|
|
31
|
+
|
|
32
|
+ test "should not create user with taken username" do
|
|
33
|
+ assert_no_difference('User.count') do
|
|
34
|
+ post api_v1_users_url, params: { user: { email: "test@email.com", username: @user.username, password: '123456' } }, as: :json
|
|
35
|
+ end
|
|
36
|
+ assert_response :unprocessable_entity
|
|
37
|
+ end
|
|
38
|
+end
|