parent
53ecf8718f
commit
c303d2b4ca
@ -0,0 +1,24 @@
|
|||||||
|
require File.expand_path('../../test_helper.rb',__FILE__)
|
||||||
|
|
||||||
|
class AuthTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
ApiKey.delete_all
|
||||||
|
end
|
||||||
|
|
||||||
|
test "login success when use correct password" do
|
||||||
|
post('/api/v1/auth/login.json', {login: 'guange', password: '123456'})
|
||||||
|
o = ActiveSupport::JSON.decode response.body
|
||||||
|
puts o
|
||||||
|
puts o["token"]
|
||||||
|
assert_not_nil o["token"]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "login failure when incorrect password" do
|
||||||
|
post('/api/v1/auth/login.json', {login: 'guange', password: 'wrongpass'})
|
||||||
|
o = ActiveSupport::JSON.decode response.body
|
||||||
|
assert_nil o["token"]
|
||||||
|
assert_equal o["error"], 'Unauthorized.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
require File.expand_path('../../test_helper.rb',__FILE__)
|
||||||
|
|
||||||
|
class UsersTest < ActionDispatch::IntegrationTest
|
||||||
|
test "register a user" do
|
||||||
|
end
|
||||||
|
test "get all users" do
|
||||||
|
get '/api/v1/users.json'
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue