12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306 |
- require 'test_helper'
- class TicketsControllerTest < ActionDispatch::IntegrationTest
- setup do
- # set accept header
- @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
- # create agent
- roles = Role.where(name: %w[Admin Agent])
- groups = Group.all
- UserInfo.current_user_id = 1
- @admin = User.create!(
- login: 'tickets-admin',
- firstname: 'Tickets',
- lastname: 'Admin',
- email: 'tickets-admin@example.com',
- password: 'adminpw',
- active: true,
- roles: roles,
- groups: groups,
- )
- # create agent
- roles = Role.where(name: 'Agent')
- @agent = User.create!(
- login: 'tickets-agent@example.com',
- firstname: 'Tickets',
- lastname: 'Agent',
- email: 'tickets-agent@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: groups,
- )
- # create customer without org
- roles = Role.where(name: 'Customer')
- @customer_without_org = User.create!(
- login: 'tickets-customer1@example.com',
- firstname: 'Tickets',
- lastname: 'Customer1',
- email: 'tickets-customer1@example.com',
- password: 'customer1pw',
- active: true,
- roles: roles,
- )
- UserInfo.current_user_id = nil
- end
- test '01.01 ticket create with agent - missing group' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #1',
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'Customer',
- type: 'note',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Group can\'t be blank', result['error_human'])
- end
- test '01.02 ticket create with agent - wrong group' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #2',
- group: 'not_existing',
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'Customer',
- type: 'note',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('No lookup value found for \'group\': "not_existing"', result['error'])
- end
- test '01.03 ticket create with agent - missing article.body' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #3',
- group: 'Users',
- priority: '2 normal',
- state: 'new',
- customer_id: @customer_without_org.id,
- article: {},
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Need at least article: { body: "some text" }', result['error'])
- end
- test '01.03 ticket create with agent - minimal article' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #3',
- group: 'Users',
- priority: '2 normal',
- state: 'new',
- customer_id: @customer_without_org.id,
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #3', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.04 ticket create with agent - minimal article and customer.email' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #3',
- group: 'Users',
- priority: '2 normal',
- state: 'new',
- customer: @customer_without_org.email,
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #3', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.05 ticket create with agent - wrong owner_id - 0' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #4',
- group: 'Users',
- priority: '2 normal',
- owner_id: 0,
- state: 'new',
- customer_id: @customer_without_org.id,
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Invalid value for param \'owner_id\': 0', result['error'])
- end
- test '01.06 ticket create with agent - wrong owner_id - ""' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #5',
- group: 'Users',
- priority: '2 normal',
- owner_id: '',
- state: 'new',
- customer_id: @customer_without_org.id,
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- #assert_response(422)
- #result = JSON.parse(@response.body)
- #assert_equal(Hash, result.class)
- #assert_equal('Invalid value for param \'owner_id\': ""', result['error'])
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #5', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.07 ticket create with agent - wrong owner_id - 99999' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #6',
- group: 'Users',
- priority: '2 normal',
- owner_id: 99_999,
- state: 'new',
- customer_id: @customer_without_org.id,
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Invalid value for param \'owner_id\': 99999', result['error'])
- end
- test '01.08 ticket create with agent - wrong owner_id - nil' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #7',
- group: 'Users',
- priority: '2 normal',
- owner_id: nil,
- state: 'new',
- customer_id: @customer_without_org.id,
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #7', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.09 ticket create with agent - minimal article with guess customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #9',
- group: 'Users',
- priority: '2 normal',
- state: 'new',
- customer_id: 'guess:some_new_customer@example.com',
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #9', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.10 ticket create with agent - minimal article with guess customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #10',
- group: 'Users',
- customer_id: 'guess:some_new_customer@example.com',
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #10', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.11 ticket create with agent - minimal article with customer hash' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #11',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- body: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #11', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '01.11.1 ticket create with agent - minimal article with customer hash with article.origin_by' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #11.1',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- body: 'some test 123',
- origin_by: 'some_new_customer@example.com',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #11.1', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- article = ticket.articles.first
- assert_equal(@agent.id, article.updated_by_id)
- assert_equal(@agent.id, article.created_by_id)
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, article.origin_by_id)
- assert_equal('Customer', article.sender.name)
- assert_equal('note', article.type.name)
- assert_equal('some firstname some lastname', article.from)
- end
- test '01.11.2 ticket create with agent - minimal article with customer hash with article.origin_by' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #11.2',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- sender: 'Customer',
- body: 'some test 123',
- origin_by: 'some_new_customer@example.com',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #11.2', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- article = ticket.articles.first
- assert_equal(@agent.id, article.updated_by_id)
- assert_equal(@agent.id, article.created_by_id)
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, article.origin_by_id)
- assert_equal('Customer', article.sender.name)
- assert_equal('note', article.type.name)
- assert_equal('some firstname some lastname', article.from)
- end
- test '01.11.3 ticket create with agent - minimal article with customer hash with article.origin_by' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #11.3',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- sender: 'Agent',
- from: 'somebody',
- body: 'some test 123',
- origin_by: 'some_new_customer@example.com',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #11.3', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- article = ticket.articles.first
- assert_equal(@agent.id, article.updated_by_id)
- assert_equal(@agent.id, article.created_by_id)
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, article.origin_by_id)
- assert_equal('Customer', article.sender.name)
- assert_equal('note', article.type.name)
- assert_equal('some firstname some lastname', article.from)
- end
- test '01.11.4 ticket create with agent - minimal article with customer hash with article.origin_by' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #11.4',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- sender: 'Customer',
- body: 'some test 123',
- origin_by: @customer_without_org.login,
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #11.4', result['title'])
- assert_equal(User.lookup(email: 'some_new_customer@example.com').id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- article = ticket.articles.first
- assert_equal(@agent.id, article.updated_by_id)
- assert_equal(@agent.id, article.created_by_id)
- assert_equal(@customer_without_org.id, article.origin_by_id)
- assert_equal('Customer', article.sender.name)
- assert_equal('note', article.type.name)
- assert_equal('Tickets Customer1', article.from)
- end
- test '01.12 ticket create with agent - minimal article with missing body - with customer.id' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #12',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Need at least article: { body: "some text" }', result['error'])
- end
- test '01.13 ticket create with agent - minimal article and attachment with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #13',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => 'dGVzdCAxMjM=',
- 'mime-type' => 'text/plain',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #13', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- assert_equal(1, ticket.articles.count)
- assert_equal(1, ticket.articles.first.attachments.count)
- file = ticket.articles.first.attachments.first
- assert_equal('test 123', file.content)
- assert_equal('some_file.txt', file.filename)
- assert_equal('text/plain', file.preferences['Mime-Type'])
- assert_not(file.preferences['Content-ID'])
- end
- test '01.14 ticket create with agent - minimal article and attachment with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #14',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- {
- 'filename' => 'some_file1.txt',
- 'data' => 'dGVzdCAxMjM=',
- 'mime-type' => 'text/plain',
- },
- {
- 'filename' => 'some_file2.txt',
- 'data' => 'w6TDtsO8w58=',
- 'mime-type' => 'text/plain',
- },
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #14', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- assert_equal(1, ticket.articles.count)
- assert_equal(2, ticket.articles.first.attachments.count)
- file = ticket.articles.first.attachments.first
- assert_equal('test 123', file.content)
- assert_equal('some_file1.txt', file.filename)
- assert_equal('text/plain', file.preferences['Mime-Type'])
- assert_not(file.preferences['Content-ID'])
- end
- test '01.15 ticket create with agent - minimal article and simple invalid base64 attachment with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #15',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => 'ABC_INVALID_BASE64',
- 'mime-type' => 'text/plain',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Invalid base64 for attachment with index \'0\'', result['error'])
- end
- test '01.15a ticket create with agent - minimal article and large invalid base64 attachment with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #15a',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => "LARGE_INVALID_BASE64_#{'#' * 20_000_000}",
- 'mime-type' => 'text/plain',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Invalid base64 for attachment with index \'0\'', result['error'])
- end
- test '01.15b ticket create with agent - minimal article and valid multiline base64 with linebreaks attachment with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #15b',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => Base64.encode64('a' * 1_000),
- 'mime-type' => 'text/plain',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal('a new ticket #15b', result['title'])
- ticket = Ticket.find(result['id'])
- assert_equal(1, ticket.articles.count)
- assert_equal(1, ticket.articles.first.attachments.count)
- file = ticket.articles.first.attachments.first
- assert_equal('a' * 1_000, file.content)
- end
- test '01.15c ticket create with agent - minimal article and valid multiline base64 without linebreaks attachment with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #15c',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => Base64.strict_encode64('a' * 1_000),
- 'mime-type' => 'text/plain',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal('a new ticket #15c', result['title'])
- ticket = Ticket.find(result['id'])
- assert_equal(1, ticket.articles.count)
- assert_equal(1, ticket.articles.first.attachments.count)
- file = ticket.articles.first.attachments.first
- assert_equal('a' * 1_000, file.content)
- end
- test '01.16 ticket create with agent - minimal article and attachment invalid base64 with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #16',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => 'dGVzdCAxMjM=',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Attachment needs \'mime-type\' param for attachment with index \'0\'', result['error'])
- end
- test '01.17 ticket create with agent - minimal article and inline attachments with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #17',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- content_type: 'text/html',
- subject: 'some test 123',
- body: 'some test 123 <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
- AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
- 9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" /> <img src="data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAJAAD/4QMtaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzYgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6QzJCOTE2NzlGQUEwMTFFNjg0M0NGQjU0OUU4MTFEOEIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6QzJCOTE2N0FGQUEwMTFFNjg0M0NGQjU0OUU4MTFEOEIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpDMkI5MTY3N0ZBQTAxMUU2ODQzQ0ZCNTQ5RTgxMUQ4QiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpDMkI5MTY3OEZBQTAxMUU2ODQzQ0ZCNTQ5RTgxMUQ4QiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pv/uAA5BZG9iZQBkwAAAAAH/2wCEABQRERoTGioZGSo1KCEoNTEpKCgpMUE4ODg4OEFEREREREREREREREREREREREREREREREREREREREREREREREQBFhoaIh0iKRoaKTkpIik5RDktLTlEREREOERERERERERERERERERERERERERERERERERERERERERERERERERERP/AABEIABAADAMBIgACEQEDEQH/xABbAAEBAAAAAAAAAAAAAAAAAAAEBQEBAQAAAAAAAAAAAAAAAAAABAUQAAEEAgMAAAAAAAAAAAAAAAABAhIDESIxBAURAAICAwAAAAAAAAAAAAAAAAESABNRoQP/2gAMAwEAAhEDEQA/AJDq1rfF3Imeg/1+lFy2oR564DKWWWbweV+Buf/Z">',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #17', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- assert_equal(1, ticket.articles.count)
- assert_equal(2, ticket.articles.first.attachments.count)
- file = ticket.articles.first.attachments[0]
- assert_equal('d3c1e09bdefb92b6a06b791a24ca9599', Digest::MD5.hexdigest(file.content))
- assert_equal('image1.png', file.filename)
- assert_equal('image/png', file.preferences['Mime-Type'])
- assert_match(/#{ticket.id}\..+?@zammad.example.com/, file.preferences['Content-ID'])
- assert(file.preferences['Content-ID'])
- file = ticket.articles.first.attachments[1]
- assert_equal('006a2ca3793b550c8fe444acdeb39252', Digest::MD5.hexdigest(file.content))
- assert_equal('image2.jpeg', file.filename)
- assert_equal('image/jpeg', file.preferences['Mime-Type'])
- assert_match(/#{ticket.id}\..+?@zammad.example.com/, file.preferences['Content-ID'])
- assert(file.preferences['Content-ID'])
- end
- test '01.18 ticket create with agent - minimal article and inline attachments with customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #18',
- group: 'Users',
- customer_id: @customer_without_org.id,
- article: {
- content_type: 'text/html',
- subject: 'some test 123',
- body: 'some test 123 <img src="data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAJAAD/4QMtaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzYgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6QzJCOTE2NzlGQUEwMTFFNjg0M0NGQjU0OUU4MTFEOEIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6QzJCOTE2N0FGQUEwMTFFNjg0M0NGQjU0OUU4MTFEOEIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpDMkI5MTY3N0ZBQTAxMUU2ODQzQ0ZCNTQ5RTgxMUQ4QiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpDMkI5MTY3OEZBQTAxMUU2ODQzQ0ZCNTQ5RTgxMUQ4QiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pv/uAA5BZG9iZQBkwAAAAAH/2wCEABQRERoTGioZGSo1KCEoNTEpKCgpMUE4ODg4OEFEREREREREREREREREREREREREREREREREREREREREREREREQBFhoaIh0iKRoaKTkpIik5RDktLTlEREREOERERERERERERERERERERERERERERERERERERERERERERERERERERP/AABEIABAADAMBIgACEQEDEQH/xABbAAEBAAAAAAAAAAAAAAAAAAAEBQEBAQAAAAAAAAAAAAAAAAAABAUQAAEEAgMAAAAAAAAAAAAAAAABAhIDESIxBAURAAICAwAAAAAAAAAAAAAAAAESABNRoQP/2gAMAwEAAhEDEQA/AJDq1rfF3Imeg/1+lFy2oR564DKWWWbweV+Buf/Z"
- >',
- attachments: [
- 'filename' => 'some_file.txt',
- 'data' => 'dGVzdCAxMjM=',
- 'mime-type' => 'text/plain',
- ],
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #18', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- assert_equal(1, ticket.articles.count)
- assert_equal(2, ticket.articles.first.attachments.count)
- file = ticket.articles.first.attachments[0]
- assert_equal('006a2ca3793b550c8fe444acdeb39252', Digest::MD5.hexdigest(file.content))
- assert_equal('image1.jpeg', file.filename)
- assert_equal('image/jpeg', file.preferences['Mime-Type'])
- assert(file.preferences['Content-ID'])
- assert_match(/#{ticket.id}\..+?@zammad.example.com/, file.preferences['Content-ID'])
- file = ticket.articles.first.attachments[1]
- assert_equal('39d0d586a701e199389d954f2d592720', Digest::MD5.hexdigest(file.content))
- assert_equal('some_file.txt', file.filename)
- assert_equal('text/plain', file.preferences['Mime-Type'])
- assert_not(file.preferences['Content-ID'])
- end
- test '02.02 ticket create with agent' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a new ticket #1',
- state: 'new',
- priority: '2 normal',
- group: 'Users',
- customer: 'tickets-customer1@example.com',
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- },
- links: {
- Ticket: {
- parent: [1],
- }
- }
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #1', result['title'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- links = Link.list(
- link_object: 'Ticket',
- link_object_value: result['id'],
- )
- assert_equal('child', links[0]['link_type'])
- assert_equal('Ticket', links[0]['link_object'])
- assert_equal(1, links[0]['link_object_value'])
- end
- test '02.03 ticket with wrong ticket id' do
- group = Group.create!(
- name: "GroupWithoutPermission-#{rand(9_999_999_999)}",
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket = Ticket.create!(
- title: 'ticket with wrong ticket id',
- group_id: group.id,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/tickets/#{ticket.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- params = {
- title: 'ticket with wrong ticket id - 2',
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- delete "/api/v1/tickets/#{ticket.id}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- end
- test '02.04 ticket with correct ticket id' do
- title = "ticket with corret ticket id testagent#{rand(999_999_999)}"
- ticket = Ticket.create!(
- title: title,
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- preferences: {
- some_key1: 123,
- },
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/tickets/#{ticket.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal(title, result['title'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(1, result['updated_by_id'])
- assert_equal(1, result['created_by_id'])
- assert_equal(123, result['preferences']['some_key1'])
- params = {
- title: "#{title} - 2",
- customer_id: @agent.id,
- preferences: {
- some_key2: 'abc',
- },
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal("#{title} - 2", result['title'])
- assert_equal(@agent.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(1, result['created_by_id'])
- assert_equal(123, result['preferences']['some_key1'])
- assert_equal('abc', result['preferences']['some_key2'])
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- article_result = JSON.parse(@response.body)
- assert_equal(Hash, article_result.class)
- assert_equal(ticket.id, article_result['ticket_id'])
- assert_equal('Tickets Agent', article_result['from'])
- assert_equal('some subject', article_result['subject'])
- assert_equal('some body', article_result['body'])
- assert_equal('text/plain', article_result['content_type'])
- assert_equal(false, article_result['internal'])
- assert_equal(@agent.id, article_result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Agent').id, article_result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'note').id, article_result['type_id'])
- Scheduler.worker(true)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['tickets'][0])
- assert_equal(1, result['tickets_count'])
- params = {
- condition: {
- 'ticket.title' => {
- operator: 'contains',
- value: title,
- },
- },
- }
- post '/api/v1/tickets/search', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['tickets'][0])
- assert_equal(1, result['tickets_count'])
- delete "/api/v1/ticket_articles/#{article_result['id']}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- params = {
- from: 'something which should not be changed on server side',
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'email',
- internal: true,
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('"Tickets Agent via Zammad" <zammad@localhost>', result['from'])
- assert_equal('some subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(true, result['internal'])
- assert_equal(@agent.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Agent').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'email').id, result['type_id'])
- params = {
- subject: 'new subject',
- }
- put "/api/v1/ticket_articles/#{result['id']}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('"Tickets Agent via Zammad" <zammad@localhost>', result['from'])
- assert_equal('new subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(true, result['internal'])
- assert_equal(@agent.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Agent').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'email').id, result['type_id'])
- delete "/api/v1/ticket_articles/#{result['id']}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized (admin permission required)!', result['error'])
- delete "/api/v1/tickets/#{ticket.id}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized (admin permission required)!', result['error'])
- end
- test '02.05 ticket with correct ticket id' do
- ticket = Ticket.create!(
- title: 'ticket with corret ticket id',
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/#{ticket.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal('ticket with corret ticket id', result['title'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(1, result['updated_by_id'])
- assert_equal(1, result['created_by_id'])
- params = {
- title: 'ticket with corret ticket id - 2',
- customer_id: @agent.id,
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal('ticket with corret ticket id - 2', result['title'])
- assert_equal(@agent.id, result['customer_id'])
- assert_equal(@admin.id, result['updated_by_id'])
- assert_equal(1, result['created_by_id'])
- params = {
- from: 'something which should not be changed on server side',
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('Tickets Admin', result['from'])
- assert_equal('some subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(false, result['internal'])
- assert_equal(@admin.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Agent').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'note').id, result['type_id'])
- params = {
- subject: 'new subject',
- internal: true,
- }
- put "/api/v1/ticket_articles/#{result['id']}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('Tickets Admin', result['from'])
- assert_equal('new subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(true, result['internal'])
- assert_equal(@admin.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Agent').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'note').id, result['type_id'])
- delete "/api/v1/ticket_articles/#{result['id']}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'email',
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('"Tickets Admin via Zammad" <zammad@localhost>', result['from'])
- assert_equal('some subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(false, result['internal'])
- assert_equal(@admin.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Agent').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'email').id, result['type_id'])
- delete "/api/v1/ticket_articles/#{result['id']}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- delete "/api/v1/tickets/#{ticket.id}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- end
- test '02.05 ticket pagination' do
- title = "ticket pagination #{rand(999_999_999)}"
- tickets = []
- (1..20).each do |count|
- ticket = Ticket.create!(
- title: "#{title} - #{count}",
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- Ticket::Article.create!(
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- from: 'sender',
- subject: 'subject',
- body: 'some body',
- ticket_id: ticket.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- tickets.push ticket
- travel 2.seconds
- end
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(tickets[19].id, result['tickets'][0])
- assert_equal(tickets[0].id, result['tickets'][19])
- assert_equal(20, result['tickets_count'])
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=10", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(tickets[19].id, result['tickets'][0])
- assert_equal(tickets[10].id, result['tickets'][9])
- assert_equal(10, result['tickets_count'])
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40&page=1&per_page=5", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(tickets[19].id, result['tickets'][0])
- assert_equal(tickets[15].id, result['tickets'][4])
- assert_equal(5, result['tickets_count'])
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40&page=2&per_page=5", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(tickets[14].id, result['tickets'][0])
- assert_equal(tickets[10].id, result['tickets'][4])
- assert_equal(5, result['tickets_count'])
- get '/api/v1/tickets?limit=40&page=1&per_page=5', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Array, result.class)
- tickets = Ticket.order(:id).limit(5)
- assert_equal(tickets[0].id, result[0]['id'])
- assert_equal(tickets[4].id, result[4]['id'])
- assert_equal(5, result.count)
- get '/api/v1/tickets?limit=40&page=2&per_page=5', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Array, result.class)
- tickets = Ticket.order(:id).limit(10)
- assert_equal(tickets[5].id, result[0]['id'])
- assert_equal(tickets[9].id, result[4]['id'])
- assert_equal(5, result.count)
- end
- test '03.01 ticket create with customer minimal' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- params = {
- title: 'a new ticket #c1',
- state: 'new',
- priority: '2 normal',
- group: 'Users',
- article: {
- body: 'some body',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #c1', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@customer_without_org.id, result['updated_by_id'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- end
- test '03.02 ticket create with customer with wrong customer' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- params = {
- title: 'a new ticket #c2',
- state: 'new',
- priority: '2 normal',
- group: 'Users',
- customer_id: @agent.id,
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'System',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #c2', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@customer_without_org.id, result['updated_by_id'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- end
- test '03.03 ticket create with customer with wrong customer hash' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- params = {
- title: 'a new ticket #c2',
- state: 'new',
- priority: '2 normal',
- group: 'Users',
- customer: {
- firstname: @agent.firstname,
- lastname: @agent.lastname,
- email: @agent.email,
- },
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'System',
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #c2', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@customer_without_org.id, result['updated_by_id'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- end
- test '03.04 ticket with wrong ticket id' do
- ticket = Ticket.create!(
- title: 'ticket with wrong ticket id',
- group: Group.lookup(name: 'Users'),
- customer_id: @agent.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- get "/api/v1/tickets/#{ticket.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- params = {
- title: 'ticket with wrong ticket id - 2',
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- delete "/api/v1/tickets/#{ticket.id}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- end
- test '03.05 ticket with correct ticket id' do
- title = "ticket with corret ticket id testme#{rand(999_999_999)}"
- ticket = Ticket.create!(
- title: title,
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- get "/api/v1/tickets/#{ticket.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal(title, result['title'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(1, result['updated_by_id'])
- assert_equal(1, result['created_by_id'])
- params = {
- title: "#{title} - 2",
- customer_id: @agent.id,
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal("#{title} - 2", result['title'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(@customer_without_org.id, result['updated_by_id'])
- assert_equal(1, result['created_by_id'])
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- article_result = JSON.parse(@response.body)
- assert_equal(Hash, article_result.class)
- assert_equal(ticket.id, article_result['ticket_id'])
- assert_equal('Tickets Customer1', article_result['from'])
- assert_equal('some subject', article_result['subject'])
- assert_equal('some body', article_result['body'])
- assert_equal('text/plain', article_result['content_type'])
- assert_equal(@customer_without_org.id, article_result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Customer').id, article_result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'note').id, article_result['type_id'])
- Scheduler.worker(true)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['tickets'][0])
- assert_equal(1, result['tickets_count'])
- params = {
- condition: {
- 'ticket.title' => {
- operator: 'contains',
- value: title,
- },
- },
- }
- post '/api/v1/tickets/search', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['tickets'][0])
- assert_equal(1, result['tickets_count'])
- delete "/api/v1/ticket_articles/#{article_result['id']}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized (admin permission required)!', result['error'])
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'email',
- sender: 'Agent',
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('Tickets Customer1', result['from'])
- assert_equal('some subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Customer').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'note').id, result['type_id'])
- delete "/api/v1/ticket_articles/#{result['id']}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized (admin permission required)!', result['error'])
- params = {
- from: 'something which should not be changed on server side',
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'web',
- sender: 'Agent',
- internal: true,
- }
- post '/api/v1/ticket_articles', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['ticket_id'])
- assert_equal('Tickets Customer1 <tickets-customer1@example.com>', result['from'])
- assert_equal('some subject', result['subject'])
- assert_equal('some body', result['body'])
- assert_equal('text/plain', result['content_type'])
- assert_equal(false, result['internal'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- assert_equal(Ticket::Article::Sender.lookup(name: 'Customer').id, result['sender_id'])
- assert_equal(Ticket::Article::Type.lookup(name: 'web').id, result['type_id'])
- params = {
- subject: 'new subject',
- }
- put "/api/v1/ticket_articles/#{result['id']}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized (ticket.agent or admin permission required)!', result['error'])
- delete "/api/v1/tickets/#{ticket.id}", params: {}.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized (admin permission required)!', result['error'])
- end
- test '03.6 ticket create with agent - minimal article with customer hash with article.origin_by' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- params = {
- title: 'a new ticket #3.6',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- body: 'some test 123',
- origin_by: @agent.login,
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #3.6', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@customer_without_org.id, result['updated_by_id'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- article = ticket.articles.first
- assert_equal(@customer_without_org.id, article.updated_by_id)
- assert_equal(@customer_without_org.id, article.created_by_id)
- assert_equal(@customer_without_org.id, article.origin_by_id)
- assert_equal('Customer', article.sender.name)
- assert_equal('note', article.type.name)
- assert_equal('Tickets Customer1', article.from)
- end
- test '03.6.1 ticket create with agent - minimal article with customer hash with article.origin_by' do
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- params = {
- title: 'a new ticket #3.6.1',
- group: 'Users',
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- sender: 'Agent',
- body: 'some test 123',
- origin_by_id: @agent.id,
- },
- }
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Ticket::State.lookup(name: 'new').id, result['state_id'])
- assert_equal('a new ticket #3.6.1', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@customer_without_org.id, result['updated_by_id'])
- assert_equal(@customer_without_org.id, result['created_by_id'])
- ticket = Ticket.find(result['id'])
- article = ticket.articles.first
- assert_equal(@customer_without_org.id, article.updated_by_id)
- assert_equal(@customer_without_org.id, article.created_by_id)
- assert_equal(@customer_without_org.id, article.origin_by_id)
- assert_equal('Customer', article.sender.name)
- assert_equal('note', article.type.name)
- assert_equal('Tickets Customer1', article.from)
- end
- test '04.01 ticket show and response format' do
- title = "ticket testagent#{rand(999_999_999)}"
- ticket = Ticket.create!(
- title: title,
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent.id,
- created_by_id: @agent.id,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/tickets/#{ticket.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal(ticket.title, result['title'])
- assert_not(result['group'])
- assert_not(result['priority'])
- assert_not(result['owner'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- get "/api/v1/tickets/#{ticket.id}?expand=true", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal(ticket.title, result['title'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(ticket.group.name, result['group'])
- assert_equal(ticket.priority.name, result['priority'])
- assert_equal(ticket.owner.login, result['owner'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- get "/api/v1/tickets/#{ticket.id}?expand=false", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal(ticket.title, result['title'])
- assert_not(result['group'])
- assert_not(result['priority'])
- assert_not(result['owner'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- get "/api/v1/tickets/#{ticket.id}?full=true", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert_equal(ticket.id, result['assets']['Ticket'][ticket.id.to_s]['id'])
- assert_equal(ticket.title, result['assets']['Ticket'][ticket.id.to_s]['title'])
- assert_equal(ticket.customer_id, result['assets']['Ticket'][ticket.id.to_s]['customer_id'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@agent.id.to_s])
- assert_equal(@agent.id, result['assets']['User'][@agent.id.to_s]['id'])
- assert_equal(@agent.firstname, result['assets']['User'][@agent.id.to_s]['firstname'])
- assert_equal(@agent.lastname, result['assets']['User'][@agent.id.to_s]['lastname'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@customer_without_org.id.to_s])
- assert_equal(@customer_without_org.id, result['assets']['User'][@customer_without_org.id.to_s]['id'])
- assert_equal(@customer_without_org.firstname, result['assets']['User'][@customer_without_org.id.to_s]['firstname'])
- assert_equal(@customer_without_org.lastname, result['assets']['User'][@customer_without_org.id.to_s]['lastname'])
- get "/api/v1/tickets/#{ticket.id}?full=false", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(ticket.id, result['id'])
- assert_equal(ticket.title, result['title'])
- assert_not(result['group'])
- assert_not(result['priority'])
- assert_not(result['owner'])
- assert_equal(ticket.customer_id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- end
- test '04.02 ticket index and response format' do
- title = "ticket testagent#{rand(999_999_999)}"
- ticket = Ticket.create!(
- title: title,
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent.id,
- created_by_id: @agent.id,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get '/api/v1/tickets', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Array, result.class)
- assert_equal(Hash, result[0].class)
- assert_equal(1, result[0]['id'])
- assert_equal(ticket.id, result[1]['id'])
- assert_equal(ticket.title, result[1]['title'])
- assert_not(result[1]['group'])
- assert_not(result[1]['priority'])
- assert_not(result[1]['owner'])
- assert_equal(ticket.customer_id, result[1]['customer_id'])
- assert_equal(@agent.id, result[1]['updated_by_id'])
- assert_equal(@agent.id, result[1]['created_by_id'])
- get '/api/v1/tickets?expand=true', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Array, result.class)
- assert_equal(Hash, result[0].class)
- assert_equal(1, result[0]['id'])
- assert_equal(ticket.id, result[1]['id'])
- assert_equal(ticket.title, result[1]['title'])
- assert_equal(ticket.customer_id, result[1]['customer_id'])
- assert_equal(ticket.group.name, result[1]['group'])
- assert_equal(ticket.priority.name, result[1]['priority'])
- assert_equal(ticket.owner.login, result[1]['owner'])
- assert_equal(@agent.id, result[1]['updated_by_id'])
- assert_equal(@agent.id, result[1]['created_by_id'])
- get '/api/v1/tickets?expand=false', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Array, result.class)
- assert_equal(Hash, result[0].class)
- assert_equal(1, result[0]['id'])
- assert_equal(ticket.id, result[1]['id'])
- assert_equal(ticket.title, result[1]['title'])
- assert_not(result[1]['group'])
- assert_not(result[1]['priority'])
- assert_not(result[1]['owner'])
- assert_equal(ticket.customer_id, result[1]['customer_id'])
- assert_equal(@agent.id, result[1]['updated_by_id'])
- assert_equal(@agent.id, result[1]['created_by_id'])
- get '/api/v1/tickets?full=true', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal(Array, result['record_ids'].class)
- assert_equal(1, result['record_ids'][0])
- assert_equal(ticket.id, result['record_ids'][1])
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert_equal(ticket.id, result['assets']['Ticket'][ticket.id.to_s]['id'])
- assert_equal(ticket.title, result['assets']['Ticket'][ticket.id.to_s]['title'])
- assert_equal(ticket.customer_id, result['assets']['Ticket'][ticket.id.to_s]['customer_id'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@agent.id.to_s])
- assert_equal(@agent.id, result['assets']['User'][@agent.id.to_s]['id'])
- assert_equal(@agent.firstname, result['assets']['User'][@agent.id.to_s]['firstname'])
- assert_equal(@agent.lastname, result['assets']['User'][@agent.id.to_s]['lastname'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@customer_without_org.id.to_s])
- assert_equal(@customer_without_org.id, result['assets']['User'][@customer_without_org.id.to_s]['id'])
- assert_equal(@customer_without_org.firstname, result['assets']['User'][@customer_without_org.id.to_s]['firstname'])
- assert_equal(@customer_without_org.lastname, result['assets']['User'][@customer_without_org.id.to_s]['lastname'])
- get '/api/v1/tickets?full=false', params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Array, result.class)
- assert_equal(Hash, result[0].class)
- assert_equal(1, result[0]['id'])
- assert_equal(ticket.id, result[1]['id'])
- assert_equal(ticket.title, result[1]['title'])
- assert_not(result[1]['group'])
- assert_not(result[1]['priority'])
- assert_not(result[1]['owner'])
- assert_equal(ticket.customer_id, result[1]['customer_id'])
- assert_equal(@agent.id, result[1]['updated_by_id'])
- assert_equal(@agent.id, result[1]['created_by_id'])
- end
- test '04.03 ticket create and response format' do
- title = "ticket testagent#{rand(999_999_999)}"
- params = {
- title: title,
- group: 'Users',
- customer_id: @customer_without_org.id,
- state: 'new',
- priority: '2 normal',
- article: {
- body: 'some test 123',
- },
- }
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- post '/api/v1/tickets', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- ticket = Ticket.find(result['id'])
- assert_equal(ticket.state_id, result['state_id'])
- assert_not(result['state'])
- assert_equal(ticket.priority_id, result['priority_id'])
- assert_not(result['priority'])
- assert_equal(ticket.group_id, result['group_id'])
- assert_not(result['group'])
- assert_equal(title, result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- post '/api/v1/tickets?expand=true', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- ticket = Ticket.find(result['id'])
- assert_equal(ticket.state_id, result['state_id'])
- assert_equal(ticket.state.name, result['state'])
- assert_equal(ticket.priority_id, result['priority_id'])
- assert_equal(ticket.priority.name, result['priority'])
- assert_equal(ticket.group_id, result['group_id'])
- assert_equal(ticket.group.name, result['group'])
- assert_equal(title, result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- post '/api/v1/tickets?full=true', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(201)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- ticket = Ticket.find(result['id'])
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert_equal(ticket.id, result['assets']['Ticket'][ticket.id.to_s]['id'])
- assert_equal(title, result['assets']['Ticket'][ticket.id.to_s]['title'])
- assert_equal(ticket.customer_id, result['assets']['Ticket'][ticket.id.to_s]['customer_id'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@agent.id.to_s])
- assert_equal(@agent.id, result['assets']['User'][@agent.id.to_s]['id'])
- assert_equal(@agent.firstname, result['assets']['User'][@agent.id.to_s]['firstname'])
- assert_equal(@agent.lastname, result['assets']['User'][@agent.id.to_s]['lastname'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@customer_without_org.id.to_s])
- assert_equal(@customer_without_org.id, result['assets']['User'][@customer_without_org.id.to_s]['id'])
- assert_equal(@customer_without_org.firstname, result['assets']['User'][@customer_without_org.id.to_s]['firstname'])
- assert_equal(@customer_without_org.lastname, result['assets']['User'][@customer_without_org.id.to_s]['lastname'])
- end
- test '04.04 ticket update and response formats' do
- title = "ticket testagent#{rand(999_999_999)}"
- ticket = Ticket.create!(
- title: title,
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent.id,
- created_by_id: @agent.id,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- params = {
- title: 'a update ticket #1',
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- ticket = Ticket.find(result['id'])
- assert_equal(ticket.state_id, result['state_id'])
- assert_not(result['state'])
- assert_equal(ticket.priority_id, result['priority_id'])
- assert_not(result['priority'])
- assert_equal(ticket.group_id, result['group_id'])
- assert_not(result['group'])
- assert_equal('a update ticket #1', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- params = {
- title: 'a update ticket #2',
- }
- put "/api/v1/tickets/#{ticket.id}?expand=true", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- ticket = Ticket.find(result['id'])
- assert_equal(ticket.state_id, result['state_id'])
- assert_equal(ticket.state.name, result['state'])
- assert_equal(ticket.priority_id, result['priority_id'])
- assert_equal(ticket.priority.name, result['priority'])
- assert_equal(ticket.group_id, result['group_id'])
- assert_equal(ticket.group.name, result['group'])
- assert_equal('a update ticket #2', result['title'])
- assert_equal(@customer_without_org.id, result['customer_id'])
- assert_equal(@agent.id, result['updated_by_id'])
- assert_equal(@agent.id, result['created_by_id'])
- params = {
- title: 'a update ticket #3',
- }
- put "/api/v1/tickets/#{ticket.id}?full=true", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- ticket = Ticket.find(result['id'])
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert_equal(ticket.id, result['assets']['Ticket'][ticket.id.to_s]['id'])
- assert_equal('a update ticket #3', result['assets']['Ticket'][ticket.id.to_s]['title'])
- assert_equal(ticket.customer_id, result['assets']['Ticket'][ticket.id.to_s]['customer_id'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@agent.id.to_s])
- assert_equal(@agent.id, result['assets']['User'][@agent.id.to_s]['id'])
- assert_equal(@agent.firstname, result['assets']['User'][@agent.id.to_s]['firstname'])
- assert_equal(@agent.lastname, result['assets']['User'][@agent.id.to_s]['lastname'])
- assert(result['assets']['User'])
- assert(result['assets']['User'][@customer_without_org.id.to_s])
- assert_equal(@customer_without_org.id, result['assets']['User'][@customer_without_org.id.to_s]['id'])
- assert_equal(@customer_without_org.firstname, result['assets']['User'][@customer_without_org.id.to_s]['firstname'])
- assert_equal(@customer_without_org.lastname, result['assets']['User'][@customer_without_org.id.to_s]['lastname'])
- end
- test '05.01 ticket split with html - check attachments' do
- ticket = Ticket.create!(
- title: 'some title',
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent.id,
- created_by_id: @agent.id,
- )
- article = Ticket::Article.create!(
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- from: 'sender',
- subject: 'subject',
- body: '<b>test</b> <img src="cid:15.274327094.140938@ZAMMAD.example.com"/> test <img src="cid:15.274327094.140938.3@ZAMMAD.example.com"/>',
- content_type: 'text/html',
- ticket_id: ticket.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_image',
- filename: 'some_file1.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938@zammad.example.com',
- 'Content-Disposition' => 'inline',
- },
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file2_normally_should_be_an_image',
- filename: 'some_file2.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.2@zammad.example.com',
- 'Content-Disposition' => 'inline',
- },
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file3_normally_should_be_an_image',
- filename: 'some_file3.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.3@zammad.example.com',
- },
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file4_normally_should_be_an_image',
- filename: 'some_file4.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.4@zammad.example.com',
- },
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_pdf',
- filename: 'Rechnung_RE-2018-200.pdf',
- preferences: {
- 'Content-Type' => 'application/octet-stream; name="Rechnung_RE-2018-200.pdf"',
- 'Mime-Type' => 'application/octet-stream',
- 'Content-ID' => '8AB0BEC88984EE4EBEF643C79C8E0346@zammad.example.com',
- 'Content-Description' => 'Rechnung_RE-2018-200.pdf',
- 'Content-Disposition' => 'attachment',
- },
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert(result['assets']['TicketArticle'][article.id.to_s])
- assert(result['attachments'])
- assert_equal(result['attachments'].count, 3)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert(result['assets']['TicketArticle'][article.id.to_s])
- assert(result['attachments'])
- assert_equal(result['attachments'].count, 0)
- end
- test '05.02 ticket split with plain - check attachments' do
- ticket = Ticket.create!(
- title: 'some title',
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: @agent.id,
- created_by_id: @agent.id,
- )
- article = Ticket::Article.create!(
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- from: 'sender',
- subject: 'subject',
- body: '<b>test</b> <img src="cid:15.274327094.140938@zammad.example.com"/>',
- content_type: 'text/plain',
- ticket_id: ticket.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_image',
- filename: 'some_file1.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938@zammad.example.com',
- 'Content-Disposition' => 'inline',
- },
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_image',
- filename: 'some_file2.jpg',
- preferences: {
- 'Content-Type' => 'image/jpeg',
- 'Mime-Type' => 'image/jpeg',
- 'Content-ID' => '15.274327094.140938.2@zammad.example.com',
- 'Content-Disposition' => 'inline',
- },
- created_by_id: 1,
- )
- Store.add(
- object: 'Ticket::Article',
- o_id: article.id,
- data: 'content_file1_normally_should_be_an_pdf',
- filename: 'Rechnung_RE-2018-200.pdf',
- preferences: {
- 'Content-Type' => 'application/octet-stream; name="Rechnung_RE-2018-200.pdf"',
- 'Mime-Type' => 'application/octet-stream',
- 'Content-ID' => '8AB0BEC88984EE4EBEF643C79C8E0346@zammad.example.com',
- 'Content-Description' => 'Rechnung_RE-2018-200.pdf',
- 'Content-Disposition' => 'attachment',
- },
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert(result['assets']['TicketArticle'][article.id.to_s])
- assert(result['attachments'])
- assert_equal(result['attachments'].count, 3)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert(result['assets'])
- assert(result['assets']['Ticket'])
- assert(result['assets']['Ticket'][ticket.id.to_s])
- assert(result['assets']['TicketArticle'][article.id.to_s])
- assert(result['attachments'])
- assert_equal(result['attachments'].count, 0)
- end
- test '06.01 - ticket with follow up possible set to new_ticket' do
- group = Group.create!(
- name: "GroupWithNoFollowUp-#{rand(9_999_999_999)}",
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- follow_up_possible: 'new_ticket' # disable follow up possible
- )
- ticket = Ticket.create!(
- title: 'ticket with wrong ticket id',
- group_id: group.id,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'closed'), # set the ticket to closed
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- state = Ticket::State.find_by(name: 'open') # try to open a ticket from a closed state
- # customer
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-customer1@example.com', 'customer1pw')
- params = {
- state_id: state.id, # set the state id
- }
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Cannot follow up on a closed ticket. Please create a new ticket.', result['error'])
- ticket = Ticket.create!(
- title: 'ticket with wrong ticket id',
- group_id: group.id,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'closed'), # set the ticket to closed
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- # admin
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw')
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Cannot follow up on a closed ticket. Please create a new ticket.', result['error'])
- ticket = Ticket.create!(
- title: 'ticket with wrong ticket id',
- group_id: group.id,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'closed'), # set the ticket to closed
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- # agent
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- put "/api/v1/tickets/#{ticket.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
- assert_response(422)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Cannot follow up on a closed ticket. Please create a new ticket.', result['error'])
- end
- test '07.01 ticket merge' do
- group_no_permission = Group.create!(
- name: 'GroupWithNoPermission',
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket1 = Ticket.create!(
- title: 'ticket merge1',
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket2 = Ticket.create!(
- title: 'ticket merge2',
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket3 = Ticket.create!(
- title: 'ticket merge2',
- group: group_no_permission,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('failed', result['result'])
- assert_equal('No such master ticket number!', result['message'])
- get "/api/v1/ticket_merge/#{ticket3.id}/#{ticket1.number}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- assert_equal('Not authorized', result['error_human'])
- get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket3.number}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(401)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('Not authorized', result['error'])
- assert_equal('Not authorized', result['error_human'])
- get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('success', result['result'])
- assert_equal(ticket2.id, result['master_ticket']['id'])
- end
- test '07.02 ticket merge - change permission' do
- group_change_permission = Group.create!(
- name: 'GroupWithChangePermission',
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket1 = Ticket.create!(
- title: 'ticket merge1',
- group: group_change_permission,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket2 = Ticket.create!(
- title: 'ticket merge2',
- group: group_change_permission,
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- @agent.group_names_access_map = { group_change_permission.name => %w[read change] }
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-agent@example.com', 'agentpw')
- get "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal('success', result['result'])
- assert_equal(ticket2.id, result['master_ticket']['id'])
- end
- test '08.01 ticket search sorted' do
- title = "ticket pagination #{rand(999_999_999)}"
- tickets = []
- ticket1 = Ticket.create!(
- title: "#{title} A",
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2018-02-05 17:42:00',
- updated_at: '2018-02-05 20:42:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- Ticket::Article.create!(
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- from: 'sender',
- subject: 'subject',
- body: 'some body',
- ticket_id: ticket1.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket2 = Ticket.create!(
- title: "#{title} B",
- group: Group.lookup(name: 'Users'),
- customer_id: @customer_without_org.id,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '3 hoch'),
- created_at: '2018-02-05 19:42:00',
- updated_at: '2018-02-05 19:42:00',
- updated_by_id: 1,
- created_by_id: 1,
- )
- Ticket::Article.create!(
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- from: 'sender',
- subject: 'subject',
- body: 'some body',
- ticket_id: ticket2.id,
- updated_by_id: 1,
- created_by_id: 1,
- )
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: {}, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal([ticket1.id, ticket2.id], result['tickets'])
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'created_at', order_by: 'asc' }, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal([ticket1.id, ticket2.id], result['tickets'])
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'title', order_by: 'asc' }, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal([ticket1.id, ticket2.id], result['tickets'])
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'title', order_by: 'desc' }, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal([ticket2.id, ticket1.id], result['tickets'])
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[asc asc] }, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal([ticket1.id, ticket2.id], result['tickets'])
- credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[desc asc] }, headers: @headers.merge('Authorization' => credentials)
- assert_response(200)
- result = JSON.parse(@response.body)
- assert_equal(Hash, result.class)
- assert_equal([ticket2.id, ticket1.id], result['tickets'])
- end
- end
|