From 787bd9a42bbfddef9095ba520ffe9c75e1bb268e Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 12 Jul 2018 02:08:37 -0300 Subject: [PATCH 1/2] test of feature #101 --- tests/scripts.rb | 10 ++++++++++ tests/ticket/close.rb | 26 ++++++++++++++++++++++++-- tests/ticket/re-open.rb | 26 ++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/tests/scripts.rb b/tests/scripts.rb index 0c0d70be..50e0d8cb 100644 --- a/tests/scripts.rb +++ b/tests/scripts.rb @@ -69,6 +69,16 @@ class Scripts result['data'] end + def self.closeTicket(ticketNumber) + result = request('/ticket/close', { + ticketNumber:ticketNumber, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + result['data'] + end + def self.createAPIKey(name) request('/system/add-api-key', { csrf_userid: $csrf_userid, diff --git a/tests/ticket/close.rb b/tests/ticket/close.rb index 6c7d219d..d44c506e 100644 --- a/tests/ticket/close.rb +++ b/tests/ticket/close.rb @@ -2,8 +2,6 @@ describe '/ticket/close' do request('/user/logout') Scripts.login($staff[:email], $staff[:password], true) - #TODO: DO THINGS - it 'should close a ticket if everything is okey' do ticket = $database.getRow('ticket', 1 , 'id') @@ -21,5 +19,29 @@ describe '/ticket/close' do lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('CLOSE') + + request('/user/logout') + Scripts.createUser('closer@os4.com','closer','Closer') + Scripts.login('closer@os4.com','closer') + Scripts.createTicket('tickettoclose') + + ticket = $database.getRow('ticket', 'tickettoclose', 'title') + + result = request('/ticket/close', { + ticketNumber: ticket['ticket_number'], + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + + }) + + (result['status']).should.equal('success') + + ticket = $database.getRow('ticket', 'tickettoclose', 'title') + (ticket['closed']).should.equal('1') + (ticket['unread']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('CLOSE') + end end diff --git a/tests/ticket/re-open.rb b/tests/ticket/re-open.rb index df3288d7..96f42153 100644 --- a/tests/ticket/re-open.rb +++ b/tests/ticket/re-open.rb @@ -2,8 +2,6 @@ describe '/ticket/re-open' do request('/user/logout') Scripts.login($staff[:email], $staff[:password], true) - #TODO: DO THINGS - it 'should re open a ticket if everything is okey' do ticket = $database.getRow('ticket', 1 , 'id') @@ -21,5 +19,29 @@ describe '/ticket/re-open' do lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('RE_OPEN') + + request('/user/logout') + Scripts.createUser('reopener@os4.com','reopener','Reopener') + Scripts.login('reopener@os4.com','reopener') + Scripts.createTicket('tickettoreopen') + + ticket = $database.getRow('ticket', 'tickettoreopen', 'title') + + Scripts.closeTicket(ticket['ticketNumber']) + + result = request('/ticket/re-open', { + ticketNumber: ticket['ticket_number'], + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + ticket = $database.getRow('ticket', 'tickettoreopen', 'title') + (ticket['closed']).should.equal('0') + (ticket['unread']).should.equal('1') + + lastLog = $database.getLastRow('log') + (lastLog['type']).should.equal('RE_OPEN') end end From 52934bc473e5f8be714c94d58a9f34c6e3f3f92a Mon Sep 17 00:00:00 2001 From: Guillermo Date: Sat, 14 Jul 2018 15:11:38 -0300 Subject: [PATCH 2/2] fix some tests --- tests/staff/get-new-tickets.rb | 4 ++-- tests/system/disable-user-system.rb | 4 ++-- tests/ticket/close.rb | 1 - tests/ticket/re-open.rb | 3 +-- tests/user/get-users-test.rb | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/staff/get-new-tickets.rb b/tests/staff/get-new-tickets.rb index 2ecf7d1d..1d7caa1f 100644 --- a/tests/staff/get-new-tickets.rb +++ b/tests/staff/get-new-tickets.rb @@ -10,6 +10,6 @@ describe '/staff/get-new-tickets' do }) (result['status']).should.equal('success') - (result['data'].size).should.equal(7) + (result['data'].size).should.equal(9) end -end \ No newline at end of file +end diff --git a/tests/system/disable-user-system.rb b/tests/system/disable-user-system.rb index 44b1b287..b43a28da 100644 --- a/tests/system/disable-user-system.rb +++ b/tests/system/disable-user-system.rb @@ -19,7 +19,7 @@ describe'system/disable-user-system' do numberOftickets= $database.query("SELECT * FROM ticket WHERE author_id IS NULL AND author_email IS NOT NULL AND author_name IS NOT NULL") - (numberOftickets.num_rows).should.equal(36) + (numberOftickets.num_rows).should.equal(38) request('/user/logout') @@ -92,7 +92,7 @@ describe'system/disable-user-system' do numberOftickets= $database.query("SELECT * FROM ticket WHERE author_email IS NULL AND author_name IS NULL AND author_id IS NOT NULL" ) - (numberOftickets.num_rows).should.equal(37) + (numberOftickets.num_rows).should.equal(39) end diff --git a/tests/ticket/close.rb b/tests/ticket/close.rb index d44c506e..efea27d7 100644 --- a/tests/ticket/close.rb +++ b/tests/ticket/close.rb @@ -38,7 +38,6 @@ describe '/ticket/close' do ticket = $database.getRow('ticket', 'tickettoclose', 'title') (ticket['closed']).should.equal('1') - (ticket['unread']).should.equal('1') lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('CLOSE') diff --git a/tests/ticket/re-open.rb b/tests/ticket/re-open.rb index 96f42153..1d966152 100644 --- a/tests/ticket/re-open.rb +++ b/tests/ticket/re-open.rb @@ -36,10 +36,9 @@ describe '/ticket/re-open' do }) (result['status']).should.equal('success') - + ticket = $database.getRow('ticket', 'tickettoreopen', 'title') (ticket['closed']).should.equal('0') - (ticket['unread']).should.equal('1') lastLog = $database.getLastRow('log') (lastLog['type']).should.equal('RE_OPEN') diff --git a/tests/user/get-users-test.rb b/tests/user/get-users-test.rb index 522f18c5..a9049dac 100644 --- a/tests/user/get-users-test.rb +++ b/tests/user/get-users-test.rb @@ -36,7 +36,7 @@ describe '/user/get-users' do }) (result['status']).should.equal('success') - (result['data']['users'].size).should.equal(3) + (result['data']['users'].size).should.equal(5) end it 'should get users with order by tickets and asc' do