mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Merged in ruby-api-testing-set-up (pull request #12)
Ruby api testing set up
This commit is contained in:
commit
e472984c0f
@ -45,7 +45,6 @@
|
||||
"morgan": "^1.6.1",
|
||||
"proxyquire": "^1.7.4",
|
||||
"react-addons-test-utils": "^15.0.1",
|
||||
"react-tools": "^0.13.3",
|
||||
"run-sequence": "^1.1.1",
|
||||
"sinon": "^1.17.3",
|
||||
"sinon-chai": "^2.8.0",
|
||||
|
3
server/api-test/Gemfile
Normal file
3
server/api-test/Gemfile
Normal file
@ -0,0 +1,3 @@
|
||||
source "https://rubygems.org"
|
||||
gem 'mysql'
|
||||
gem 'bacon'
|
27
server/api-test/libs.rb
Normal file
27
server/api-test/libs.rb
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
def request(path, data)
|
||||
uri = URI('http://localhost:8080' + path)
|
||||
response = Net::HTTP.post_form(uri, data)
|
||||
|
||||
return JSON.parse(response.body)
|
||||
end
|
||||
|
||||
class Database
|
||||
def initialize()
|
||||
mysqlUser = ENV['MYSQL_USER'] || 'root';
|
||||
mysqlPass = ENV['MYSQL_PASSWORD'] || '';
|
||||
@connection = Mysql.new('localhost', mysqlUser , mysqlPass, 'development')
|
||||
end
|
||||
|
||||
def close()
|
||||
@connection.close
|
||||
end
|
||||
|
||||
def getRow(table, value, field = 'id')
|
||||
queryResponse = @connection.query("select * from #{table} where #{field}='#{value.to_s}'")
|
||||
|
||||
return queryResponse.fetch_hash
|
||||
end
|
||||
end
|
||||
|
||||
$database = Database.new
|
10
server/api-test/run-test.rb
Normal file
10
server/api-test/run-test.rb
Normal 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'
|
11
server/api-test/scripts.rb
Normal file
11
server/api-test/scripts.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class Scripts
|
||||
def self.createUser(email = 'steve@jobs.com', password = 'custompassword')
|
||||
response = request('/user/signup', {
|
||||
'email' => email,
|
||||
'password' => password
|
||||
})
|
||||
|
||||
if response['status'] === 'fail'
|
||||
raise "Could not create user"
|
||||
end
|
||||
end
|
24
server/api-test/user/login.rb
Normal file
24
server/api-test/user/login.rb
Normal file
@ -0,0 +1,24 @@
|
||||
describe '/user/login' do
|
||||
before do
|
||||
@loginEmail = 'login@os4.com'
|
||||
@loginPass = 'loginpass'
|
||||
|
||||
Scripts.createUser(@loginEmail, @loginPass)
|
||||
end
|
||||
|
||||
it 'should fail if password is incorrect' do
|
||||
result = request('/user/login', {
|
||||
email: @loginEmail,
|
||||
pass: 'some_incorrect_password'
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail')
|
||||
end
|
||||
|
||||
it 'should login correctly' do
|
||||
|
||||
end
|
||||
|
||||
it 'should fail if already logged in' do
|
||||
|
||||
end
|
12
server/api-test/user/signup.rb
Normal file
12
server/api-test/user/signup.rb
Normal 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 = $database.getRow('users', response['data']['userId'])
|
||||
|
||||
(userRow['email']).should.equal('steve@jobs.com')
|
||||
end
|
||||
end
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
$mysql_host = 'localhost';
|
||||
$mysql_user = 'os_dev';
|
||||
$mysql_password = 'os_dev';
|
||||
$mysql_database = 'os_dev';
|
||||
$env['MYSQL_SERVER'] = getenv('MYSQL_SERVER');
|
||||
$env['MYSQL_USER'] = getenv('MYSQL_USER');
|
||||
$env['MYSQL_PASSWORD'] = getenv('MYSQL_PASSWORD');
|
||||
$env['MYSQL_DATABASE'] = getenv('MYSQL_DATABASE');
|
||||
|
||||
$mysql_host = ($env['MYSQL_SERVER']) ? $env['MYSQL_SERVER'] : 'localhost';
|
||||
$mysql_user = ($env['MYSQL_USER']) ? $env['MYSQL_USER'] : 'root';
|
||||
$mysql_password = ($env['MYSQL_PASSWORD']) ? $env['MYSQL_PASSWORD'] : '';
|
||||
$mysql_database = ($env['MYSQL_DATABASE']) ? $env['MYSQL_DATABASE'] : 'development';
|
||||
|
@ -5,7 +5,6 @@ abstract class DataStore {
|
||||
protected $_bean;
|
||||
|
||||
abstract protected function getDefaultProperties();
|
||||
abstract static protected function getProps();
|
||||
|
||||
public static function getDataStore($value, $property = 'id') {
|
||||
$bean = RedBean::findOne(static::TABLE, static::validateProp($property) . ' =:value', array(
|
||||
|
Loading…
x
Reference in New Issue
Block a user