diff --git a/README.md b/README.md index ee61ee62..ad2df3cb 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Once you've installed dependencies for frontend and backend, you can run `./buil ##### BACKEND API RUBY TESTING 1. Go to tests folder: `cd opensupports/tests` -2. Run `make install` to install ruby and its the required dependencies +2. Run `make build` to install ruby container and its required dependencies - `make run` for running tests (database will be cleared) - `make clear` for clearing database diff --git a/server/Dockerfile b/server/Dockerfile index 1c385f5a..5e0afc79 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -7,10 +7,6 @@ RUN apt-get update && \ (curl -s https://getcomposer.org/installer | php) && \ mv composer.phar /usr/local/bin/composer -RUN echo 'LISTEN 8080' >> /etc/apache2/apache2.conf -RUN sed -i "1s/.*//" /etc/apache2/sites-enabled/000-default.conf -RUN sed -i "5s/.*/Listen 8080/" /etc/apache2/ports.conf - # ENVIRONMENT VARIABLES -ENV MYSQL_HOST 127.0.0.1 -ENV MYSQL_PORT 4040 +ENV MYSQL_HOST opensupports-db +ENV MYSQL_PORT 3306 diff --git a/server/Makefile b/server/Makefile index 678716cd..85280df9 100644 --- a/server/Makefile +++ b/server/Makefile @@ -9,14 +9,15 @@ build: @docker build -t opensupports-srv . || echo "A${red}An error occurred${reset}" install: + @docker network create os-net || true @docker exec -it opensupports-srv bash -c "cd /var/www/html && composer install" || echo "${red}Please execute 'make run' first${reset}" @docker exec -it opensupports-db bash -c "mysql -u root -e \"CREATE DATABASE IF NOT EXISTS development;\" " || echo "${red}Please execute 'make run' first${reset}" -run: - @docker run -d --name opensupports-db -p 4040:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v $(PWD)/.dbdata/:/var/lib/mysql mysql:5.6 - @docker run -d --name opensupports-myadmin --link opensupports-db:db -p 6060:80 phpmyadmin/phpmyadmin - @docker run -d --name opensupports-fakesmtp -p 7070:25 -v ${PWD}/.fakemail/:/var/mail munkyboy/fakesmtp - @docker run -d --name opensupports-srv --net=host --rm -e LOG_STDOUT=true -e LOG_STDERR=true -e LOG_LEVEL=debug -v ${PWD}:/var/www/html opensupports-srv +run: stop + @docker run -d --network os-net --name opensupports-db -p 4040:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v $(PWD)/.dbdata/:/var/lib/mysql mysql:5.6 + @docker run -d --network os-net --name opensupports-myadmin --link opensupports-db:db -p 6060:80 phpmyadmin/phpmyadmin + @docker run -d --network os-net --name opensupports-fakesmtp -p 7070:25 -v ${PWD}/.fakemail/:/var/mail munkyboy/fakesmtp + @docker run -d --network os-net --name opensupports-srv -p 8080:80 --link opensupports-db:mysql --rm -e LOG_STDOUT=true -e LOG_STDERR=true -e LOG_LEVEL=debug -v ${PWD}:/var/www/html opensupports-srv test: @./run-tests.sh diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 00000000..d93d0ae6 --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:18.04 + +RUN mkdir /app +WORKDIR /app + +RUN apt update +RUN apt install build-essential openssl curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison --yes +RUN apt install mysql-client --yes +RUN apt install ruby-full --yes +RUN apt install libmysqlclient-dev ruby-dev --yes +RUN gem install bundler + +COPY Gemfile /app +RUN bundle install \ No newline at end of file diff --git a/tests/Gemfile b/tests/Gemfile index 19730631..fde8db3e 100644 --- a/tests/Gemfile +++ b/tests/Gemfile @@ -1,5 +1,5 @@ source "https://rubygems.org" -gem 'mysql' +gem 'mysql2' gem 'bacon' gem 'mechanize' gem 'mailfactory' diff --git a/tests/Makefile b/tests/Makefile index b30f4e1c..c5f18c09 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,20 +1,24 @@ DB_HOST ?= `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' opensupports-db` -install: - @apt-get install ruby-full - @apt-get install libmysqlclient-dev ruby-dev - @gem install bundler - @bundle install +build: + @docker build -t opensupports-tests . -run: export MYSQL_HOST=127.0.0.1 -run: export MYSQL_PORT=4040 run: + @docker run -it --network os-net -v ${PWD}:/app -v ${PWD}/../server:/server opensupports-tests make test + +clear: + @docker run -it --network os-net -v ${PWD}:/app -v ${PWD}/../server:/server opensupports-tests make truncate-db + +test: export MYSQL_HOST=opensupports-db +test: export MYSQL_PORT=3306 +test: export API_URL=http://opensupports-srv +test: ./run-tests.sh -clear: export MYSQL_HOST=127.0.0.1 -clear: export MYSQL_PORT=4040 -clear: - ./clean_db.sh && \ - ./clean_db.sh && \ - ./clean_db.sh +truncate-db: export MYSQL_HOST=opensupports-db +truncate-db: export MYSQL_PORT=3306 +truncate-db: + ./truncate_db.sh && \ + ./truncate_db.sh && \ + ./truncate_db.sh diff --git a/tests/article/article.rb b/tests/article/article.rb index c6ad9d08..2b2e6d40 100644 --- a/tests/article/article.rb +++ b/tests/article/article.rb @@ -23,7 +23,7 @@ describe 'Article path' do row = $database.getRow('topic', 'Private Topic', 'name') result['status'].should.equal('success') - (row['private']).should.equal('1') + (row['private']).should.equal(1) end it 'should create article' do @@ -41,8 +41,8 @@ describe 'Article path' do article = $database.getRow('article', @article_id) (article['title']).should.equal('Some article') (article['content']).should.equal('This is an article about server management.') - (article['topic_id']).should.equal(@topic_id.to_s) - (article['position']).should.equal('1') + (article['topic_id']).should.equal(@topic_id) + (article['position']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('ADD_ARTICLE') @@ -60,8 +60,8 @@ describe 'Article path' do article = $database.getRow('article', @article_id) (article['title']).should.equal('Some article') (article['content']).should.equal('This is an article about server management2.') - (article['topic_id']).should.equal(@topic_id.to_s) - (article['position']).should.equal('1') + (article['topic_id']).should.equal(@topic_id) + (article['position']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('EDIT_ARTICLE') @@ -87,8 +87,8 @@ describe 'Article path' do article = $database.getRow('article', @article_id) (article['title']).should.equal('Some article') (article['content']).should.equal('This is an article about server management2.') - (article['topic_id']).should.equal((@topic_id+1).to_s) - (article['position']).should.equal('1') + (article['topic_id']).should.equal((@topic_id+1)) + (article['position']).should.equal(1) end it 'should delete article' do @@ -157,6 +157,5 @@ describe 'Article path' do (result['data'][1]['icon']).should.equal('photo') (result['data'][1]['iconColor']).should.equal('blue') (result['data'][1]['private']).should.equal('0') - end end diff --git a/tests/article/topic.rb b/tests/article/topic.rb index d264f89e..4c588424 100644 --- a/tests/article/topic.rb +++ b/tests/article/topic.rb @@ -18,7 +18,7 @@ describe 'Topic paths' do (topic['name']).should.equal('Server management') (topic['icon_color']).should.equal('red') (topic['icon']).should.equal('cogs') - (topic['private']).should.equal('0') + (topic['private']).should.equal(0) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('ADD_TOPIC') @@ -40,7 +40,7 @@ describe 'Topic paths' do (topic['name']).should.equal('Installation issues') (topic['icon_color']).should.equal('blue') (topic['icon']).should.equal('cogs') - (topic['private']).should.equal('1') + (topic['private']).should.equal(1) end it 'should delete topic correctly' do diff --git a/tests/init.rb b/tests/init.rb index 548150e0..78476d69 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -4,7 +4,7 @@ require 'net/http' require 'net/imap' require 'net/smtp' require 'uri' -require 'mysql' +require 'mysql2' require 'json' require 'mechanize' require 'mailfactory' diff --git a/tests/libs.rb b/tests/libs.rb index 178ed3e6..56f74190 100644 --- a/tests/libs.rb +++ b/tests/libs.rb @@ -1,7 +1,9 @@ $agent = Mechanize.new +$apiURL = ENV['API_URL'] || 'http://localhost:8080' + def plainRequest(path, data = {}, method = 'POST') - uri = 'http://localhost:8080' + path + uri = $apiURL + path if method == 'POST' @response = $agent.post(uri, data) @@ -13,7 +15,7 @@ def plainRequest(path, data = {}, method = 'POST') end def request(path, data = {}) - uri = 'http://localhost:8080' + path + uri = $apiURL + path response = $agent.post(uri, data) return JSON.parse(response.body) @@ -25,7 +27,13 @@ class Database mysqlPort = ENV['MYSQL_PORT'] || '3306' mysqlUser = ENV['MYSQL_USER'] || 'root' mysqlPass = ENV['MYSQL_PASSWORD'] || '' - @connection = Mysql.new(mysqlHost, mysqlUser, mysqlPass, 'development', mysqlPort.to_i) + @connection = Mysql2::Client.new( + host: mysqlHost, + username: mysqlUser, + password: mysqlPass, + port: mysqlPort.to_i, + database: 'development' + ) end def close() @@ -35,13 +43,13 @@ class Database def getRow(table, value, field = 'id') queryResponse = @connection.query("select * from #{table} where #{field}='#{value.to_s}'") - return queryResponse.fetch_hash + return queryResponse.first end def getLastRow(table) queryResponse = @connection.query("select * from #{table} order by id desc limit 1") - return queryResponse.fetch_hash + return queryResponse.first end def query(query_string) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 75e25dea..c20eaed3 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -1,4 +1,4 @@ -./clean_db.sh -./clean_db.sh -./clean_db.sh +./truncate_db.sh +./truncate_db.sh +./truncate_db.sh bacon init.rb diff --git a/tests/staff/assign-ticket.rb b/tests/staff/assign-ticket.rb index 64e612b4..594d610f 100644 --- a/tests/staff/assign-ticket.rb +++ b/tests/staff/assign-ticket.rb @@ -20,15 +20,15 @@ describe '/staff/assign-ticket' do ticket = $database.getRow('ticket', 1 , 'id') - (ticket['owner_id']).should.equal('1') + (ticket['owner_id']).should.equal(1) - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) staff_ticket = $database.getRow('staff_ticket', 1 , 'ticket_id') - (staff_ticket['staff_id']).should.equal('1') + (staff_ticket['staff_id']).should.equal(1) - (staff_ticket['ticket_id']).should.equal('1') + (staff_ticket['ticket_id']).should.equal(1) end it 'should assign ticket if a staff choose another to assing a ticket ' do staffId = $database.getRow('staff','ayra2@opensupports.com','email')['id'] @@ -46,7 +46,7 @@ describe '/staff/assign-ticket' do (ticket['owner_id']).should.equal(staffId) - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) end it 'should fail if ticket is already owned' do diff --git a/tests/staff/delete.rb b/tests/staff/delete.rb index 1fcc4ad4..e7a4f2a9 100644 --- a/tests/staff/delete.rb +++ b/tests/staff/delete.rb @@ -16,7 +16,7 @@ describe'/staff/delete' do (row).should.equal(nil) row = $database.getRow('department', 1, 'id') - (row['owners']).should.equal('4') + (row['owners']).should.equal(4) end @@ -31,6 +31,6 @@ describe'/staff/delete' do (result['message']).should.equal('INVALID_STAFF') row = $database.getRow('department', 1, 'id') - (row['owners']).should.equal('4') + (row['owners']).should.equal(4) end end diff --git a/tests/staff/edit.rb b/tests/staff/edit.rb index 3afc28a2..a7ce42aa 100644 --- a/tests/staff/edit.rb +++ b/tests/staff/edit.rb @@ -18,17 +18,17 @@ describe'/staff/edit' do row = $database.getRow('staff', staffId, 'id') (row['email']).should.equal('littlelannister@opensupports.com') - (row['level']).should.equal('1') + (row['level']).should.equal(1) rows = $database.getRow('department_staff', staffId, 'staff_id') - (rows['department_id']).should.equal('1') + (rows['department_id']).should.equal(1) row = $database.getRow('department', 1, 'id') - (row['owners']).should.equal('4') + (row['owners']).should.equal(4) row = $database.getRow('department', 2, 'id') - (row['owners']).should.equal('3') + (row['owners']).should.equal(3) end it 'should edit own data staff' do @@ -67,17 +67,17 @@ describe'/staff/edit' do row = $database.getRow('staff', 'Arya Stark', 'name') (row['email']).should.equal('ayra2@opensupports.com') - (row['level']).should.equal('2') - (row['send_email_on_new_ticket']).should.equal('0') + (row['level']).should.equal(2) + (row['send_email_on_new_ticket']).should.equal(0) row = $database.getRow('department', 1, 'id') - (row['owners']).should.equal('5') + (row['owners']).should.equal(5) row = $database.getRow('department', 2, 'id') - (row['owners']).should.equal('4') + (row['owners']).should.equal(4) row = $database.getRow('department', 3, 'id') - (row['owners']).should.equal('2') + (row['owners']).should.equal(2) Scripts.logout() Scripts.login('ayra2@opensupports.com', 'starkpassword', true) @@ -88,7 +88,7 @@ describe'/staff/edit' do }) (result['status']).should.equal('success') row = $database.getRow('staff', 'Arya Stark', 'name') - (row['send_email_on_new_ticket']).should.equal('1') + (row['send_email_on_new_ticket']).should.equal(1) end it 'should fail if is not staff logged' do @@ -106,7 +106,5 @@ describe'/staff/edit' do (result['status']).should.equal('fail') (result['message']).should.equal('NO_PERMISSION') - - end end diff --git a/tests/staff/invite.rb b/tests/staff/invite.rb index fd928e68..ce8ebf59 100644 --- a/tests/staff/invite.rb +++ b/tests/staff/invite.rb @@ -28,10 +28,10 @@ describe'/staff/invite' do (row['name']).should.equal('Tyrion Lannister') (row['email']).should.equal('tyrion@opensupports.com') (row['profile_pic']).should.equal('') - (row['level']).should.equal('2') + (row['level']).should.equal(2) row = $database.getRow('department', 1, 'id') - (row['owners']).should.equal('4') + (row['owners']).should.equal(4) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('INVITE') @@ -52,6 +52,6 @@ describe'/staff/invite' do (result['message']).should.equal('ALREADY_A_STAFF') row = $database.getRow('department', 1, 'id') - (row['owners']).should.equal('4') + (row['owners']).should.equal(4) end end diff --git a/tests/staff/un-assign-ticket.rb b/tests/staff/un-assign-ticket.rb index 91f1b436..4b0676bf 100644 --- a/tests/staff/un-assign-ticket.rb +++ b/tests/staff/un-assign-ticket.rb @@ -21,7 +21,7 @@ describe '/staff/un-assign-ticket' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['owner_id']).should.equal(nil) - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) staff_ticket = $database.getRow('staff_ticket', 1 , 'ticket_id') @@ -73,7 +73,7 @@ describe '/staff/un-assign-ticket' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['owner_id']).should.equal(nil) - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) staff_ticket = $database.getRow('staff_ticket', 1 , 'ticket_id') diff --git a/tests/system/add-department.rb b/tests/system/add-department.rb index 10ccfd57..881543ac 100644 --- a/tests/system/add-department.rb +++ b/tests/system/add-department.rb @@ -14,7 +14,7 @@ describe'system/add-department' do row = $database.getRow('department', 4, 'id') (row['name']).should.equal('Tech support') - (row['private']).should.equal("0") + (row['private']).should.equal(0) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('ADD_DEPARTMENT') @@ -32,7 +32,7 @@ describe'system/add-department' do row = $database.getRow('department', 6, 'id') (row['name']).should.equal('new department') - (row['private']).should.equal("0") + (row['private']).should.equal(0) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('ADD_DEPARTMENT') @@ -49,7 +49,7 @@ describe'system/add-department' do (result['status']).should.equal('success') row = $database.getRow('department', 'a private department', 'name') - (row['private']).should.equal('1') + (row['private']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('ADD_DEPARTMENT') diff --git a/tests/system/custom-fields.rb b/tests/system/custom-fields.rb index acce982b..ed79e5d5 100644 --- a/tests/system/custom-fields.rb +++ b/tests/system/custom-fields.rb @@ -97,8 +97,8 @@ describe 'Custom fields' do ($database.getRow('customfieldoption', 'option2', 'name')['customfield_id']).should.equal(custom_field_row_id) ($database.getRow('customfieldoption', 'option3', 'name')['customfield_id']).should.equal(custom_field_row_id) - quantity_of_options = $database.query("SELECT COUNT(*) as qt FROM customfieldoption WHERE customfield_id='#{custom_field_row_id}'").fetch_hash['qt'] - (quantity_of_options).should.equal("3") + quantity_of_options = $database.query("SELECT COUNT(*) as qt FROM customfieldoption WHERE customfield_id='#{custom_field_row_id}'").first['qt'] + (quantity_of_options).should.equal(3) end it 'should fail if field name already exists' do diff --git a/tests/system/delete-department.rb b/tests/system/delete-department.rb index bf9b3ba5..d6c2ec47 100644 --- a/tests/system/delete-department.rb +++ b/tests/system/delete-department.rb @@ -85,14 +85,14 @@ describe 'system/delete-department' do ticket2 = $database.getRow('ticket', ticket2, 'ticket_number') ticket3 = $database.getRow('ticket', ticket3, 'ticket_number') - (ticket1['department_id']).should.equal('3') + (ticket1['department_id']).should.equal(3) (ticket1['owner_id']).should.equal(nil) - (ticket2['department_id']).should.equal('3') + (ticket2['department_id']).should.equal(3) (ticket2['owner_id']).should.equal(nil) - (ticket3['department_id']).should.equal('3') - (ticket3['owner_id']).should.equal($csrf_userid) + (ticket3['department_id']).should.equal(3) + (ticket3['owner_id']).should.equal($csrf_userid.to_i) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('DELETE_DEPARTMENT') diff --git a/tests/system/edit-settings.rb b/tests/system/edit-settings.rb index efa14ba1..e88c58a0 100755 --- a/tests/system/edit-settings.rb +++ b/tests/system/edit-settings.rb @@ -65,31 +65,31 @@ describe'system/edit-settings' do (result['status']).should.equal('success') row = $database.getRow('language', 'en', 'code') - (row['supported']).should.equal('1') + (row['supported']).should.equal(1) row = $database.getRow('language', 'pt', 'code') - (row['supported']).should.equal('1') + (row['supported']).should.equal(1) row = $database.getRow('language', 'jp', 'code') - (row['supported']).should.equal('1') + (row['supported']).should.equal(1) row = $database.getRow('language', 'ru', 'code') - (row['supported']).should.equal('1') + (row['supported']).should.equal(1) row = $database.getRow('language', 'en', 'code') - (row['allowed']).should.equal('1') + (row['allowed']).should.equal(1) row = $database.getRow('language', 'pt', 'code') - (row['allowed']).should.equal('1') + (row['allowed']).should.equal(1) row = $database.getRow('language', 'jp', 'code') - (row['allowed']).should.equal('1') + (row['allowed']).should.equal(1) row = $database.getRow('language', 'ru', 'code') - (row['allowed']).should.equal('1') + (row['allowed']).should.equal(1) row = $database.getRow('language', 'de', 'code') - (row['allowed']).should.equal('1') + (row['allowed']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('EDIT_SETTINGS') diff --git a/tests/system/file-upload-download.rb b/tests/system/file-upload-download.rb index b8ceef02..6ce530d6 100644 --- a/tests/system/file-upload-download.rb +++ b/tests/system/file-upload-download.rb @@ -21,7 +21,7 @@ describe 'File Upload and Download' do ticket = $database.getLastRow('ticket') (ticket['file'].include? 'upload_3_.txt').should.equal(true) - (ticket['file'].include? ('' + ticket['ticket_number'] + '_')).should.equal(true) + (ticket['file'].include? ('' + ticket['ticket_number'].to_s + '_')).should.equal(true) (File.exist? ('../server/files/' + ticket['file'])).should.equal(true) end diff --git a/tests/system/mandatory-login.rb b/tests/system/mandatory-login.rb index 44776a61..7597be96 100644 --- a/tests/system/mandatory-login.rb +++ b/tests/system/mandatory-login.rb @@ -113,8 +113,8 @@ describe'system/mandatory-login' do (result['status']).should.equal('success') (result['data']['ticketNumber']).should.equal($ticketRow['ticket_number'].to_i) ($userRow['email']).should.equal('nonuser@os4.com') - ($userRow['not_registered']).should.equal('1') - ($userRow['tickets']).should.equal('1') + ($userRow['not_registered']).should.equal(1) + ($userRow['tickets']).should.equal(1) end it 'should allow the creator creates another ticket and not create another user' do @@ -133,7 +133,7 @@ describe'system/mandatory-login' do (result['status']).should.equal('success') (result['data']['ticketNumber']).should.equal($ticketRow['ticket_number'].to_i) ($userRow['email']).should.equal('nonuser@os4.com') - ($userRow['tickets']).should.equal('2') + ($userRow['tickets']).should.equal(2) end @@ -170,8 +170,8 @@ describe'system/mandatory-login' do }) (result['status']).should.equal('success') - (result['data']['userId']).should.equal($userRow['id']) - (result['data']['ticketNumber']).should.equal($ticketRow['ticket_number']) + (result['data']['userId']).should.equal($userRow['id'].to_s) + (result['data']['ticketNumber']).should.equal($ticketRow['ticket_number'].to_s) $sessionToken = result['data']['token'] $sessionId = result['data']['userId'] @@ -257,7 +257,7 @@ describe'system/mandatory-login' do ($ticketRow['title']).should.equal('new title of ticket created without login') ($ticketRow['content']).should.equal('this is the first edited-comment without login') - ($ticketRow['closed']).should.equal('1') + ($ticketRow['closed']).should.equal(1) result = request('/ticket/delete', { csrf_token: $sessionToken, diff --git a/tests/ticket/change-department.rb b/tests/ticket/change-department.rb index 4ef0cfa2..1b55942b 100644 --- a/tests/ticket/change-department.rb +++ b/tests/ticket/change-department.rb @@ -46,8 +46,8 @@ describe '/ticket/change-department' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 1 , 'id') - (ticket['unread']).should.equal('1') - (ticket['department_id']).should.equal('4') + (ticket['unread']).should.equal(1) + (ticket['department_id']).should.equal(4) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('DEPARTMENT_CHANGED') @@ -74,8 +74,8 @@ describe '/ticket/change-department' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 1 , 'id') - (ticket['unread']).should.equal('1') - (ticket['department_id']).should.equal('3') + (ticket['unread']).should.equal(1) + (ticket['department_id']).should.equal(3) (ticket['owner_id']).should.equal(nil) lastLog = $database.getLastRow('log') @@ -94,7 +94,7 @@ describe '/ticket/change-department' do }) (result['status']).should.equal('success') - (ticket['department_id']).should.equal('1') + (ticket['department_id']).should.equal(1) request('/staff/edit', { csrf_userid: $csrf_userid, diff --git a/tests/ticket/change-priority.rb b/tests/ticket/change-priority.rb index 8d42129c..cae555f1 100644 --- a/tests/ticket/change-priority.rb +++ b/tests/ticket/change-priority.rb @@ -18,7 +18,7 @@ describe '/ticket/change-priority' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['priority']).should.equal('high') - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('PRIORITY_CHANGED') @@ -38,7 +38,7 @@ describe '/ticket/change-priority' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['priority']).should.equal('medium') - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('PRIORITY_CHANGED') @@ -58,7 +58,7 @@ describe '/ticket/change-priority' do ticket = $database.getRow('ticket', 1 , 'id') (ticket['priority']).should.equal('low') - (ticket['unread']).should.equal('1') + (ticket['unread']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('PRIORITY_CHANGED') diff --git a/tests/ticket/close.rb b/tests/ticket/close.rb index e8d802e4..441a681a 100644 --- a/tests/ticket/close.rb +++ b/tests/ticket/close.rb @@ -23,7 +23,7 @@ describe '/ticket/close' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 'tickettoclose', 'title') - (ticket['closed']).should.equal('1') + (ticket['closed']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('CLOSE') @@ -50,7 +50,7 @@ describe '/ticket/close' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 'tickettoclose', 'title') - (ticket['closed']).should.equal('1') + (ticket['closed']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('CLOSE') @@ -71,7 +71,7 @@ describe '/ticket/close' do (result['message']).should.equal('NO_PERMISSION') ticket = $database.getRow('ticket', 'tickettoclose2', 'title') - (ticket['closed']).should.equal('0') + (ticket['closed']).should.equal(0) request('/staff/edit', { csrf_userid: $csrf_userid, @@ -95,7 +95,7 @@ describe '/ticket/close' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 'tickettoclose3', 'title') - (ticket['closed']).should.equal('1') + (ticket['closed']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('CLOSE') diff --git a/tests/ticket/comment.rb b/tests/ticket/comment.rb index 0eb9726f..b11734d6 100644 --- a/tests/ticket/comment.rb +++ b/tests/ticket/comment.rb @@ -44,8 +44,8 @@ describe '/ticket/comment/' do comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id') (comment['content']).should.equal('some comment content') (comment['type']).should.equal('COMMENT') - (comment['author_user_id']).should.equal($csrf_userid) - (ticket['unread_staff']).should.equal('1') + (comment['author_user_id']).should.equal($csrf_userid.to_i) + (ticket['unread_staff']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('COMMENT') @@ -67,8 +67,8 @@ describe '/ticket/comment/' do comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id') (comment['content']).should.equal('some comment content') (comment['type']).should.equal('COMMENT') - (comment['author_staff_id']).should.equal($csrf_userid) - (ticket['unread_staff']).should.equal('1') + (comment['author_staff_id']).should.equal($csrf_userid.to_i) + (ticket['unread_staff']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('COMMENT') @@ -100,7 +100,7 @@ describe '/ticket/comment/' do comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id') (comment['content']).should.equal('some comment content jeje') (comment['type']).should.equal('COMMENT') - (comment['author_staff_id']).should.equal($csrf_userid) + (comment['author_staff_id']).should.equal($csrf_userid.to_i) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('COMMENT') @@ -201,7 +201,7 @@ describe '/ticket/comment/' do (result['status']).should.equal('success') comment = $database.getRow('ticketevent', 'this is not a private comment', 'content') - (comment['private']).should.equal("0") + (comment['private']).should.equal(0) request('/user/logout') end @@ -227,6 +227,6 @@ describe '/ticket/comment/' do (result['status']).should.equal('success') comment = $database.getRow('ticketevent', 'this is a private comment', 'content') - (comment['private']).should.equal("1") + (comment['private']).should.equal(1) end end diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index 9429e174..e2eb8834 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -125,15 +125,15 @@ describe '/ticket/create' do ticket = $database.getRow('ticket','Winter is coming!','title') (ticket['content']).should.equal('The north remembers') - (ticket['unread']).should.equal('0') - (ticket['closed']).should.equal('0') + (ticket['unread']).should.equal(0) + (ticket['closed']).should.equal(0) (ticket['priority']).should.equal('low') - (ticket['department_id']).should.equal('1') - (ticket['author_id']).should.equal($csrf_userid) - (ticket['ticket_number'].size).should.equal(6) + (ticket['department_id']).should.equal(1) + (ticket['author_id']).should.equal($csrf_userid.to_i) + ((Math.log10(ticket['ticket_number'].to_i)).ceil).should.equal(6) ticket_user_relation = $database.getRow('ticket_user', ticket['id'],'ticket_id') - (ticket_user_relation['user_id']).should.equal($csrf_userid) + (ticket_user_relation['user_id']).should.equal($csrf_userid.to_i) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('CREATE_TICKET') @@ -191,7 +191,7 @@ describe '/ticket/create' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', result['data']['ticketNumber'], 'ticket_number') (ticket['author_id']).should.equal(nil) - (ticket['author_staff_id']).should.equal('1') + (ticket['author_staff_id']).should.equal(1) $ticketNumberByStaff = result['data']['ticketNumber'] request('/user/logout') diff --git a/tests/ticket/edit-title.rb b/tests/ticket/edit-title.rb index 2f1a3242..26ca6642 100644 --- a/tests/ticket/edit-title.rb +++ b/tests/ticket/edit-title.rb @@ -32,7 +32,7 @@ describe '/ticket/edit-title' do (result['status']).should.equal('success') (ticket['title']).should.equal('Valar dohaeris') - (ticket['edited_title']).should.equal('1') + (ticket['edited_title']).should.equal(1) end it 'should change the title of the ticket if staff is logged' do @@ -50,8 +50,7 @@ describe '/ticket/edit-title' do (result['status']).should.equal('success') (ticket['title']).should.equal('Valar dohaeris by Staff') - (ticket['edited_title']).should.equal('1') - + (ticket['edited_title']).should.equal(1) end it 'should not change the title if the user is not the author' do diff --git a/tests/ticket/get.rb b/tests/ticket/get.rb index 7ff97e4d..39ebf064 100644 --- a/tests/ticket/get.rb +++ b/tests/ticket/get.rb @@ -65,12 +65,12 @@ describe '/ticket/get/' do (result['status']).should.equal('success') - (result['data']['ticketNumber']).should.equal(ticket['ticket_number']) + (result['data']['ticketNumber']).should.equal(ticket['ticket_number'].to_s) (result['data']['title']).should.equal(ticket['title']) (result['data']['content']).should.equal(ticket['content']) (result['data']['department']['id']).should.equal('1') (result['data']['department']['name']).should.equal($database.getRow('department', 1)['name']) - (result['data']['date']).should.equal(ticket['date']) + (result['data']['date'].to_i).should.equal(ticket['date']) (result['data']['file']).should.equal(ticket['file']) (result['data']['language']).should.equal(ticket['language']) (result['data']['unread']).should.equal(false) @@ -98,7 +98,7 @@ describe '/ticket/get/' do }) (result['status']).should.equal('success') - (result['data']['ticketNumber']).should.equal(ticket['ticket_number']) + (result['data']['ticketNumber']).should.equal(ticket['ticket_number'].to_s) (result['data']['title']).should.equal('titleofticket87') (result['data']['content']).should.equal('contentoftheticket87') @@ -123,7 +123,7 @@ describe '/ticket/get/' do }) (result['status']).should.equal('success') - (result['data']['ticketNumber']).should.equal(ticket['ticket_number']) + (result['data']['ticketNumber'].to_i).should.equal(ticket['ticket_number']) (result['data']['title']).should.equal('titleoftheticket107') (result['data']['content']).should.equal('contentoftheticket107') end diff --git a/tests/ticket/re-open.rb b/tests/ticket/re-open.rb index f5771e36..8372cc47 100644 --- a/tests/ticket/re-open.rb +++ b/tests/ticket/re-open.rb @@ -14,8 +14,8 @@ describe '/ticket/re-open' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 1 , 'id') - (ticket['closed']).should.equal('0') - (ticket['unread']).should.equal('1') + (ticket['closed']).should.equal(0) + (ticket['unread']).should.equal(1) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('RE_OPEN') @@ -45,7 +45,7 @@ describe '/ticket/re-open' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 'contentoftheticketthatisgoingtosucces' , 'content') - (ticket['closed']).should.equal('0') + (ticket['closed']).should.equal(0) request('/staff/edit', { csrf_userid: $csrf_userid, @@ -76,7 +76,7 @@ describe '/ticket/re-open' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 'tickettoreopen', 'title') - (ticket['closed']).should.equal('0') + (ticket['closed']).should.equal(0) lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('RE_OPEN') diff --git a/tests/ticket/seen.rb b/tests/ticket/seen.rb index 8240bb6b..8b7058ad 100644 --- a/tests/ticket/seen.rb +++ b/tests/ticket/seen.rb @@ -15,7 +15,7 @@ describe '/ticket/seen' do }) (result['status']).should.equal('success') ticket = $database.getRow('ticket', 1, 'id') - (ticket['unread_staff']).should.equal('0') + (ticket['unread_staff']).should.equal(0) end end @@ -48,7 +48,7 @@ describe '/ticket/seen' do (result['status']).should.equal('success') ticket = $database.getRow('ticket', 1, 'id') - (ticket['unread']).should.equal('0') + (ticket['unread']).should.equal(0) end end diff --git a/tests/clean_db.sh b/tests/truncate_db.sh similarity index 100% rename from tests/clean_db.sh rename to tests/truncate_db.sh diff --git a/tests/user/get-user.rb b/tests/user/get-user.rb index ca9bf37c..ae27affb 100644 --- a/tests/user/get-user.rb +++ b/tests/user/get-user.rb @@ -21,9 +21,9 @@ describe '/user/get-user' do user = $database.getRow('user', 4 , 'id') (user['email']).should.equal(result['data']['email']) - (user['signup_date']).should.equal(result['data']['signupDate']) + (user['signup_date']).should.equal(result['data']['signupDate'].to_i) (user['name']).should.equal(result['data']['name']) - (user['tickets']).should.equal(result['data']['tickets'].size.to_s) + (user['tickets']).should.equal(result['data']['tickets'].size) end end \ No newline at end of file diff --git a/tests/user/get.rb b/tests/user/get.rb index 96030a4d..350253c7 100644 --- a/tests/user/get.rb +++ b/tests/user/get.rb @@ -40,12 +40,12 @@ describe '/user/get' do (result['data']['email']).should.equal('user_get@os4.com') ticketFromUser = result['data']['tickets'][0] - (ticketFromUser['ticketNumber']).should.equal(ticket['ticket_number']) + (ticketFromUser['ticketNumber']).should.equal(ticket['ticket_number'].to_s) (ticketFromUser['title']).should.equal(ticket['title']) (ticketFromUser['content']).should.equal(ticket['content']) (ticketFromUser['department']['id']).should.equal('1') (ticketFromUser['department']['name']).should.equal($database.getRow('department', 1)['name']) - (ticketFromUser['date']).should.equal(ticket['date']) + (ticketFromUser['date'].to_i).should.equal(ticket['date'].to_i) (ticketFromUser['file']).should.equal(ticket['file']) (ticketFromUser['language']).should.equal(ticket['language']) (ticketFromUser['unread']).should.equal(false)