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.
25 lines
653 B
25 lines
653 B
6 years ago
|
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
|
||
|
|
||
|
|