[Ivan Diaz] - Ruby API testing

This commit is contained in:
Ivan Diaz 2016-05-04 23:25:01 -03:00
parent 4f726f524d
commit 661502051c
6 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,2 @@
---
BUNDLE_NO_INSTALL: false

5
server/api-test/Gemfile Normal file
View File

@ -0,0 +1,5 @@
source "https://rubygems.org"
gem 'mysql'
gem 'bacon'
gem 'net/http'
gem 'uri'

16
server/api-test/libs.rb Normal file
View File

@ -0,0 +1,16 @@
def request(path, data)
uri = URI('http://localhost:8080' + path)
response = Net::HTTP.post_form(uri, data)
return JSON.parse(response.body)
end
def getRow(table, id)
database = Mysql.new('localhost', 'root', '', 'os_dev')
queryResponse = database.query("select * from #{table} where id='#{id.to_s}'")
database.close
return queryResponse.fetch_hash
end

View File

@ -0,0 +1,10 @@
# LIBRARIES
require 'bacon'
require 'net/http'
require 'uri'
require 'mysql'
require 'json'
require './libs.rb'
# TESTS
require './user/signup.rb'

View File

View File

@ -0,0 +1,12 @@
describe '/user/signup' do
it 'should create user in database' do
response = request('/user/signup', {
'email' => 'steve@jobs.com',
'password' => 'custom'
})
userRow = getRow('users', response['data']['userId'])
(userRow['email']).should.equal('steve@jobs.com')
end
end