[Ivan Diaz] - Ruby API testing
This commit is contained in:
parent
4f726f524d
commit
661502051c
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
BUNDLE_NO_INSTALL: false
|
|
@ -0,0 +1,5 @@
|
|||
source "https://rubygems.org"
|
||||
gem 'mysql'
|
||||
gem 'bacon'
|
||||
gem 'net/http'
|
||||
gem 'uri'
|
|
@ -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
|
|
@ -0,0 +1,10 @@
|
|||
# LIBRARIES
|
||||
require 'bacon'
|
||||
require 'net/http'
|
||||
require 'uri'
|
||||
require 'mysql'
|
||||
require 'json'
|
||||
require './libs.rb'
|
||||
|
||||
# TESTS
|
||||
require './user/signup.rb'
|
|
@ -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
|
Loading…
Reference in New Issue