From 661502051cbbb9b1e5a97056515d477cc4d4b12b Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Wed, 4 May 2016 23:25:01 -0300 Subject: [PATCH] [Ivan Diaz] - Ruby API testing --- server/api-test/.bundle/config | 2 ++ server/api-test/Gemfile | 5 +++++ server/api-test/libs.rb | 16 ++++++++++++++++ server/api-test/run-test.rb | 10 ++++++++++ server/api-test/user/login.rb | 0 server/api-test/user/signup.rb | 12 ++++++++++++ 6 files changed, 45 insertions(+) create mode 100644 server/api-test/.bundle/config create mode 100644 server/api-test/Gemfile create mode 100644 server/api-test/libs.rb create mode 100644 server/api-test/run-test.rb create mode 100644 server/api-test/user/login.rb create mode 100644 server/api-test/user/signup.rb diff --git a/server/api-test/.bundle/config b/server/api-test/.bundle/config new file mode 100644 index 00000000..3a3091eb --- /dev/null +++ b/server/api-test/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_NO_INSTALL: false diff --git a/server/api-test/Gemfile b/server/api-test/Gemfile new file mode 100644 index 00000000..f1acdc46 --- /dev/null +++ b/server/api-test/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" +gem 'mysql' +gem 'bacon' +gem 'net/http' +gem 'uri' diff --git a/server/api-test/libs.rb b/server/api-test/libs.rb new file mode 100644 index 00000000..a072a1f7 --- /dev/null +++ b/server/api-test/libs.rb @@ -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 diff --git a/server/api-test/run-test.rb b/server/api-test/run-test.rb new file mode 100644 index 00000000..d54a219f --- /dev/null +++ b/server/api-test/run-test.rb @@ -0,0 +1,10 @@ +# LIBRARIES +require 'bacon' +require 'net/http' +require 'uri' +require 'mysql' +require 'json' +require './libs.rb' + +# TESTS +require './user/signup.rb' diff --git a/server/api-test/user/login.rb b/server/api-test/user/login.rb new file mode 100644 index 00000000..e69de29b diff --git a/server/api-test/user/signup.rb b/server/api-test/user/signup.rb new file mode 100644 index 00000000..5fdc5adc --- /dev/null +++ b/server/api-test/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