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