123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442 |
- # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe 'Ticket', type: :request do
- let!(:ticket_group) do
- create(:group, email_address: create(:email_address))
- end
- let!(:ticket_group_without_create) do
- create(:group, email_address: create(:email_address))
- end
- let(:admin) do
- create(:admin, groups: Group.all, firstname: 'Tickets', lastname: 'Admin')
- end
- let!(:agent) do
- create(:agent, groups: Group.all, firstname: 'Tickets', lastname: 'Agent')
- end
- let!(:agent_change_only) do
- user = create(:agent, groups: Group.all, firstname: 'Tickets', lastname: 'Agent')
- user.group_names_access_map = {
- ticket_group_without_create.name => %w[read change],
- }
- user
- end
- let!(:customer) do
- create(
- :customer,
- login: 'tickets-customer1@example.com',
- firstname: 'Tickets',
- lastname: 'Customer1',
- email: 'tickets-customer1@example.com',
- )
- end
- describe 'request handling' do
- it 'does ticket create with agent - missing group (01.01)' do
- params = {
- title: 'a new ticket #1',
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'Customer',
- type: 'note',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error_human']).to eq('Group can\'t be blank')
- end
- it 'does ticket create with agent - wrong group (01.02)' do
- params = {
- title: 'a new ticket #2',
- group: 'not_existing',
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'Customer',
- type: 'note',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('No lookup value found for \'group\': "not_existing"')
- end
- it 'does ticket create with agent - valid group but no create permissions (01.02a)' do
- params = {
- title: 'a new ticket #1',
- group: ticket_group_without_create.name,
- priority: '2 normal',
- state: 'new',
- customer_id: customer.id,
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'Customer',
- type: 'note',
- },
- }
- authenticated_as(agent_change_only)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- end
- it 'does ticket create with agent - missing article.body (01.03)' do
- params = {
- title: 'a new ticket #3',
- group: ticket_group.name,
- priority: '2 normal',
- state: 'new',
- customer_id: customer.id,
- article: {},
- }
- authenticated_as(agent)
- expect { post '/api/v1/tickets', params: params, as: :json }.not_to change(Ticket, :count)
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq("Need at least an 'article body' field.")
- end
- it 'does ticket create with agent - article.body set to empty string (01.03)' do
- params = {
- title: 'a new ticket #3',
- group: ticket_group.name,
- priority: '2 normal',
- state: 'new',
- customer_id: customer.id,
- article: { body: " \n " },
- }
- authenticated_as(agent)
- expect { post '/api/v1/tickets', params: params, as: :json }.not_to change(Ticket, :count)
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq("Need at least an 'article body' field.")
- end
- it 'does ticket create with agent - missing article (01.03)' do
- params = {
- title: 'a new ticket #3',
- group: ticket_group.name,
- priority: '2 normal',
- state: 'new',
- customer_id: customer.id
- }
- authenticated_as(agent)
- expect { post '/api/v1/tickets', params: params, as: :json }.to change(Ticket, :count).by(1)
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles).to be_empty
- end
- it 'does ticket create with agent - minimal article (01.03)' do
- params = {
- title: 'a new ticket #3',
- group: ticket_group.name,
- priority: '2 normal',
- state: 'new',
- customer_id: customer.id,
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #3')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - minimal article and customer.email (01.04)' do
- params = {
- title: 'a new ticket #3',
- group: ticket_group.name,
- priority: '2 normal',
- state: 'new',
- customer: customer.email,
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #3')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - wrong owner_id - 0 (01.05)' do
- params = {
- title: 'a new ticket #4',
- group: ticket_group.name,
- priority: '2 normal',
- owner_id: 0,
- state: 'new',
- customer_id: customer.id,
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Invalid value for param \'owner_id\': 0')
- end
- it 'does ticket create with agent - wrong owner_id - "" (01.06)' do
- params = {
- title: 'a new ticket #5',
- group: ticket_group.name,
- priority: '2 normal',
- owner_id: '',
- state: 'new',
- customer_id: customer.id,
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #5')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - wrong owner_id - 99999 (01.07)' do
- params = {
- title: 'a new ticket #6',
- group: ticket_group.name,
- priority: '2 normal',
- owner_id: 99_999,
- state: 'new',
- customer_id: customer.id,
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Invalid value for param \'owner_id\': 99999')
- end
- it 'does ticket create with agent - wrong owner_id - nil (01.08)' do
- params = {
- title: 'a new ticket #7',
- group: ticket_group.name,
- priority: '2 normal',
- owner_id: nil,
- state: 'new',
- customer_id: customer.id,
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #7')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - minimal article with guess customer (01.09)' do
- params = {
- title: 'a new ticket #9',
- group: ticket_group.name,
- priority: '2 normal',
- state: 'new',
- customer_id: 'guess:some_new_customer@example.com',
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #9')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - minimal article with guess customer (01.10)' do
- params = {
- title: 'a new ticket #10',
- group: ticket_group.name,
- customer_id: 'guess:some_new_customer@example.com',
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #10')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - minimal article with customer hash (01.11)' do
- params = {
- title: 'a new ticket #11',
- group: ticket_group.name,
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #11')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create with agent - minimal article with customer hash with article.origin_by (01.11)' do
- params = {
- title: 'a new ticket #11.1',
- group: ticket_group.name,
- 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',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #11.1')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- article = ticket.articles.first
- expect(article.updated_by_id).to eq(agent.id)
- expect(article.created_by_id).to eq(agent.id)
- expect(article.origin_by_id).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(article.sender.name).to eq('Customer')
- expect(article.type.name).to eq('note')
- expect(article.from).to eq('some firstname some lastname')
- end
- it 'does ticket create with agent - minimal article with customer hash with article.origin_by (01.11)' do
- params = {
- title: 'a new ticket #11.2',
- group: ticket_group.name,
- 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',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #11.2')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- article = ticket.articles.first
- expect(article.updated_by_id).to eq(agent.id)
- expect(article.created_by_id).to eq(agent.id)
- expect(article.origin_by_id).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(article.sender.name).to eq('Customer')
- expect(article.type.name).to eq('note')
- expect(article.from).to eq('some firstname some lastname')
- end
- it 'does ticket create with agent - minimal article with customer hash with article.origin_by (01.11)' do
- params = {
- title: 'a new ticket #11.3',
- group: ticket_group.name,
- 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',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #11.3')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- article = ticket.articles.first
- expect(article.updated_by_id).to eq(agent.id)
- expect(article.created_by_id).to eq(agent.id)
- expect(article.origin_by_id).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(article.sender.name).to eq('Customer')
- expect(article.type.name).to eq('note')
- expect(article.from).to eq('some firstname some lastname')
- end
- it 'does ticket create with agent - minimal article with customer hash with article.origin_by (01.11)' do
- params = {
- title: 'a new ticket #11.4',
- group: ticket_group.name,
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- sender: 'Customer',
- body: 'some test 123',
- origin_by: customer.login,
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #11.4')
- expect(json_response['customer_id']).to eq(User.lookup(email: 'some_new_customer@example.com').id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- article = ticket.articles.first
- expect(article.updated_by_id).to eq(agent.id)
- expect(article.created_by_id).to eq(agent.id)
- expect(article.origin_by_id).to eq(customer.id)
- expect(article.sender.name).to eq('Customer')
- expect(article.type.name).to eq('note')
- expect(article.from).to eq('Tickets Customer1')
- end
- it 'does ticket create with agent - minimal article with missing body - with customer.id (01.12)' do
- params = {
- title: 'a new ticket #12',
- group: ticket_group.name,
- customer_id: customer.id,
- article: {
- subject: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq("Need at least an 'article body' field.")
- end
- it 'does ticket create with agent - minimal article and attachment with customer (01.13)' do
- params = {
- title: 'a new ticket #13',
- group: ticket_group.name,
- customer_id: customer.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- { 'filename' => 'some_file.txt',
- 'data' => 'dGVzdCAxMjM=',
- 'mime-type' => 'text/plain' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #13')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles.count).to eq(1)
- expect(ticket.articles.first.attachments.count).to eq(1)
- file = ticket.articles.first.attachments.first
- expect(file.content).to eq('test 123')
- expect(file.filename).to eq('some_file.txt')
- expect(file.preferences['Mime-Type']).to eq('text/plain')
- expect(file.preferences['Content-ID']).to be_falsey
- end
- it 'does ticket create with agent - minimal article and attachment with customer (01.14)' do
- params = {
- title: 'a new ticket #14',
- group: ticket_group.name,
- customer_id: customer.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',
- },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #14')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles.count).to eq(1)
- expect(ticket.articles.first.attachments.count).to eq(2)
- file = ticket.articles.first.attachments.first
- expect(file.content).to eq('test 123')
- expect(file.filename).to eq('some_file1.txt')
- expect(file.preferences['Mime-Type']).to eq('text/plain')
- expect(file.preferences['Content-ID']).to be_falsey
- end
- it 'does ticket create with agent - minimal article and simple invalid base64 attachment with customer (01.15)' do
- params = {
- title: 'a new ticket #15',
- group: ticket_group.name,
- customer_id: customer.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- { 'filename' => 'some_file.txt',
- 'data' => 'ABC_INVALID_BASE64',
- 'mime-type' => 'text/plain' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Invalid base64 for attachment with index \'0\'')
- end
- it 'does ticket create with agent - minimal article and large invalid base64 attachment with customer (01.15a)' do
- params = {
- title: 'a new ticket #15a',
- group: ticket_group.name,
- customer_id: customer.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' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Invalid base64 for attachment with index \'0\'')
- end
- it 'does ticket create with agent - minimal article and valid multiline base64 with linebreaks attachment with customer (01.15b)' do
- params = {
- title: 'a new ticket #15b',
- group: ticket_group.name,
- customer_id: customer.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' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response['title']).to eq('a new ticket #15b')
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles.count).to eq(1)
- expect(ticket.articles.first.attachments.count).to eq(1)
- file = ticket.articles.first.attachments.first
- expect(file.content).to eq('a' * 1_000)
- end
- it 'does ticket create with agent - minimal article and valid multiline base64 without linebreaks attachment with customer (01.15c)' do
- params = {
- title: 'a new ticket #15c',
- group: ticket_group.name,
- customer_id: customer.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' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response['title']).to eq('a new ticket #15c')
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles.count).to eq(1)
- expect(ticket.articles.first.attachments.count).to eq(1)
- file = ticket.articles.first.attachments.first
- expect(file.content).to eq('a' * 1_000)
- end
- it 'does ticket create with agent - minimal article and attachment invalid base64 with customer (01.16)' do
- params = {
- title: 'a new ticket #16',
- group: ticket_group.name,
- customer_id: customer.id,
- article: {
- subject: 'some test 123',
- body: 'some test 123',
- attachments: [
- { 'filename' => 'some_file.txt',
- 'data' => 'dGVzdCAxMjM=' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Attachment needs \'mime-type\' param for attachment with index \'0\'')
- end
- it 'does ticket create with agent - minimal article and inline attachments with customer (01.17)' do
- params = {
- title: 'a new ticket #17',
- group: ticket_group.name,
- customer_id: customer.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">',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #17')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles.count).to eq(1)
- expect(ticket.articles.first.attachments.count).to eq(2)
- file = ticket.articles.first.attachments[0]
- expect(Digest::MD5.hexdigest(file.content)).to eq('d3c1e09bdefb92b6a06b791a24ca9599')
- expect(file.filename).to eq('image1.png')
- expect(file.preferences['Mime-Type']).to eq('image/png')
- expect(file.preferences['Content-ID']).to match(%r{#{ticket.id}\..+?@zammad.example.com})
- expect(file.preferences['Content-ID']).to be_truthy
- file = ticket.articles.first.attachments[1]
- expect(Digest::MD5.hexdigest(file.content)).to eq('006a2ca3793b550c8fe444acdeb39252')
- expect(file.filename).to eq('image2.jpeg')
- expect(file.preferences['Mime-Type']).to eq('image/jpeg')
- expect(file.preferences['Content-ID']).to match(%r{#{ticket.id}\..+?@zammad.example.com})
- expect(file.preferences['Content-ID']).to be_truthy
- end
- it 'does ticket create with agent - minimal article and inline attachments with customer (01.18)' do
- params = {
- title: 'a new ticket #18',
- group: ticket_group.name,
- customer_id: customer.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' },
- ],
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #18')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- ticket = Ticket.find(json_response['id'])
- expect(ticket.articles.count).to eq(1)
- expect(ticket.articles.first.attachments.count).to eq(2)
- file = ticket.articles.first.attachments[0]
- expect(Digest::MD5.hexdigest(file.content)).to eq('006a2ca3793b550c8fe444acdeb39252')
- expect(file.filename).to eq('image1.jpeg')
- expect(file.preferences['Mime-Type']).to eq('image/jpeg')
- expect(file.preferences['Content-ID']).to be_truthy
- expect(file.preferences['Content-ID']).to match(%r{#{ticket.id}\..+?@zammad.example.com})
- file = ticket.articles.first.attachments[1]
- expect(Digest::MD5.hexdigest(file.content)).to eq('39d0d586a701e199389d954f2d592720')
- expect(file.filename).to eq('some_file.txt')
- expect(file.preferences['Mime-Type']).to eq('text/plain')
- expect(file.preferences['Content-ID']).to be_falsey
- end
- it 'does ticket create with agent (02.02)' do
- params = {
- title: 'a new ticket #1',
- state: 'new',
- priority: '2 normal',
- group: ticket_group.name,
- customer: 'tickets-customer1@example.com',
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- },
- links: {
- Ticket: {
- parent: [1],
- }
- }
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #1')
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- links = Link.list(
- link_object: 'Ticket',
- link_object_value: json_response['id'],
- )
- expect(links[0]['link_type']).to eq('child')
- expect(links[0]['link_object']).to eq('Ticket')
- expect(links[0]['link_object_value']).to eq(1)
- end
- it 'does ticket with wrong ticket id (02.03)' do
- group = create(:group)
- ticket = create(
- :ticket,
- title: 'ticket with wrong ticket id',
- group_id: group.id,
- customer_id: customer.id,
- )
- authenticated_as(agent)
- get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- params = {
- title: 'ticket with wrong ticket id - 2',
- }
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- delete "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- end
- it 'does ticket with correct ticket id (02.04)' do
- title = "ticket with corret ticket id testagent#{SecureRandom.uuid}"
- ticket = create(
- :ticket,
- title: title,
- group: ticket_group,
- customer_id: customer.id,
- preferences: {
- some_key1: 123,
- },
- )
- authenticated_as(agent)
- get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq(title)
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(1)
- expect(json_response['created_by_id']).to eq(1)
- expect(json_response['preferences']['some_key1']).to eq(123)
- params = {
- title: "#{title} - 2",
- customer_id: agent.id,
- preferences: {
- some_key2: 'abc',
- },
- }
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq("#{title} - 2")
- expect(json_response['customer_id']).to eq(agent.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(1)
- expect(json_response['preferences']['some_key1']).to eq(123)
- expect(json_response['preferences']['some_key2']).to eq('abc')
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- article_json_response = json_response
- expect(article_json_response).to be_a_kind_of(Hash)
- expect(article_json_response['ticket_id']).to eq(ticket.id)
- expect(article_json_response['from']).to eq('Tickets Agent')
- expect(article_json_response['subject']).to eq('some subject')
- expect(article_json_response['body']).to eq('some body')
- expect(article_json_response['content_type']).to eq('text/plain')
- expect(article_json_response['internal']).to be(false)
- expect(article_json_response['created_by_id']).to eq(agent.id)
- expect(article_json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id)
- expect(article_json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id)
- Scheduler.worker(true)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(ticket.id)
- expect(json_response['tickets_count']).to eq(1)
- params = {
- condition: {
- 'ticket.title' => {
- operator: 'contains',
- value: title,
- },
- },
- }
- post '/api/v1/tickets/search', params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(ticket.id)
- expect(json_response['tickets_count']).to eq(1)
- delete "/api/v1/ticket_articles/#{article_json_response['id']}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- 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, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq(%("Tickets Agent via #{ticket_group.email_address.realname}" <#{ticket_group.email_address.email}>))
- expect(json_response['subject']).to eq('some subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['internal']).to be(true)
- expect(json_response['created_by_id']).to eq(agent.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'email').id)
- params = {
- subject: 'new subject',
- }
- put "/api/v1/ticket_articles/#{json_response['id']}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq(%("Tickets Agent via #{ticket_group.email_address.realname}" <#{ticket_group.email_address.email}>))
- expect(json_response['subject']).not_to eq('new subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['internal']).to be(true)
- expect(json_response['created_by_id']).to eq(agent.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'email').id)
- params = {
- from: 'something which should not be changed on server side',
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'email',
- internal: false,
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response['internal']).to be(false)
- delete "/api/v1/ticket_articles/#{json_response['id']}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized (communication articles cannot be deleted)!')
- delete "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized (admin permission required)!')
- end
- it 'does ticket with correct ticket id (02.05)' do
- ticket = create(
- :ticket,
- title: 'ticket with corret ticket id',
- group: ticket_group,
- customer_id: customer.id,
- )
- authenticated_as(admin)
- get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq('ticket with corret ticket id')
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(1)
- expect(json_response['created_by_id']).to eq(1)
- params = {
- title: 'ticket with corret ticket id - 2',
- customer_id: agent.id,
- }
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq('ticket with corret ticket id - 2')
- expect(json_response['customer_id']).to eq(agent.id)
- expect(json_response['updated_by_id']).to eq(admin.id)
- expect(json_response['created_by_id']).to eq(1)
- 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, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq('Tickets Admin')
- expect(json_response['subject']).to eq('some subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['internal']).to be(false)
- expect(json_response['created_by_id']).to eq(admin.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id)
- params = {
- subject: 'new subject',
- internal: true,
- }
- put "/api/v1/ticket_articles/#{json_response['id']}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq('Tickets Admin')
- expect(json_response['subject']).not_to eq('new subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['internal']).to be(true)
- expect(json_response['created_by_id']).to eq(admin.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id)
- delete "/api/v1/ticket_articles/#{json_response['id']}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'email',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq(%("Tickets Admin via #{ticket_group.email_address.realname}" <#{ticket_group.email_address.email}>))
- expect(json_response['subject']).to eq('some subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['internal']).to be(false)
- expect(json_response['created_by_id']).to eq(admin.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Agent').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'email').id)
- delete "/api/v1/ticket_articles/#{json_response['id']}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- delete "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- end
- it 'does ticket pagination (02.05)' do
- title = "ticket pagination #{SecureRandom.uuid}"
- tickets = []
- (1..20).each do |count|
- ticket = create(
- :ticket,
- title: "#{title} - #{count}",
- group: ticket_group,
- customer_id: customer.id,
- )
- create(
- :ticket_article,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- ticket_id: ticket.id,
- )
- tickets.push ticket
- travel 2.seconds
- end
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(tickets[19].id)
- expect(json_response['tickets'][19]).to eq(tickets[0].id)
- expect(json_response['tickets_count']).to eq(20)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=10", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(tickets[19].id)
- expect(json_response['tickets'][9]).to eq(tickets[10].id)
- expect(json_response['tickets_count']).to eq(10)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40&page=1&per_page=5", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(tickets[19].id)
- expect(json_response['tickets'][4]).to eq(tickets[15].id)
- expect(json_response['tickets_count']).to eq(5)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40&page=2&per_page=5", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(tickets[14].id)
- expect(json_response['tickets'][4]).to eq(tickets[10].id)
- expect(json_response['tickets_count']).to eq(5)
- get '/api/v1/tickets?limit=40&page=1&per_page=5', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Array)
- tickets = Ticket.order(:id).limit(5)
- expect(json_response[0]['id']).to eq(tickets[0].id)
- expect(json_response[4]['id']).to eq(tickets[4].id)
- expect(json_response.count).to eq(5)
- get '/api/v1/tickets?limit=40&page=2&per_page=5', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Array)
- tickets = Ticket.order(:id).limit(10)
- expect(json_response[0]['id']).to eq(tickets[5].id)
- expect(json_response[4]['id']).to eq(tickets[9].id)
- expect(json_response.count).to eq(5)
- end
- it 'does ticket create with customer minimal (03.01)' do
- params = {
- title: 'a new ticket #c1',
- state: 'new',
- priority: '2 normal',
- group: ticket_group.name,
- article: {
- body: 'some body',
- },
- }
- authenticated_as(customer)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #c1')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- end
- it 'does ticket create with customer with wrong customer (03.02)' do
- params = {
- title: 'a new ticket #c2',
- state: 'new',
- priority: '2 normal',
- group: ticket_group.name,
- customer_id: agent.id,
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'System',
- },
- }
- authenticated_as(customer)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #c2')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- end
- it 'does ticket create with customer with wrong customer hash (03.03)' do
- params = {
- title: 'a new ticket #c2',
- state: 'new',
- priority: '2 normal',
- group: ticket_group.name,
- customer: {
- firstname: agent.firstname,
- lastname: agent.lastname,
- email: agent.email,
- },
- article: {
- content_type: 'text/plain', # or text/html
- body: 'some body',
- sender: 'System',
- },
- }
- authenticated_as(customer)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #c2')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- end
- it 'does ticket with wrong ticket id (03.04)' do
- ticket = create(
- :ticket,
- title: 'ticket with wrong ticket id',
- group: ticket_group,
- customer_id: agent.id,
- )
- authenticated_as(customer)
- get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- params = {
- title: 'ticket with wrong ticket id - 2',
- }
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- delete "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- end
- it 'does ticket with correct ticket id (03.05)' do
- title = "ticket with corret ticket id testme#{SecureRandom.uuid}"
- ticket = create(
- :ticket,
- title: title,
- group: ticket_group,
- customer_id: customer.id,
- )
- authenticated_as(customer)
- get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq(title)
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(1)
- expect(json_response['created_by_id']).to eq(1)
- params = {
- title: "#{title} - 2",
- customer_id: agent.id,
- }
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq("#{title} - 2")
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(1)
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- article_json_response = json_response
- expect(article_json_response).to be_a_kind_of(Hash)
- expect(article_json_response['ticket_id']).to eq(ticket.id)
- expect(article_json_response['from']).to eq('Tickets Customer1')
- expect(article_json_response['subject']).to eq('some subject')
- expect(article_json_response['body']).to eq('some body')
- expect(article_json_response['content_type']).to eq('text/plain')
- expect(article_json_response['created_by_id']).to eq(customer.id)
- expect(article_json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Customer').id)
- expect(article_json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id)
- Scheduler.worker(true)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(ticket.id)
- expect(json_response['tickets_count']).to eq(1)
- params = {
- condition: {
- 'ticket.title' => {
- operator: 'contains',
- value: title,
- },
- },
- }
- post '/api/v1/tickets/search', params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets'][0]).to eq(ticket.id)
- expect(json_response['tickets_count']).to eq(1)
- delete "/api/v1/ticket_articles/#{article_json_response['id']}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized (agent permission required)!')
- params = {
- ticket_id: ticket.id,
- subject: 'some subject',
- body: 'some body',
- type: 'email',
- sender: 'Agent',
- }
- post '/api/v1/ticket_articles', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq('Tickets Customer1')
- expect(json_response['subject']).to eq('some subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['created_by_id']).to eq(customer.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Customer').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'note').id)
- delete "/api/v1/ticket_articles/#{json_response['id']}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized (agent permission required)!')
- 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, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['ticket_id']).to eq(ticket.id)
- expect(json_response['from']).to eq('Tickets Customer1 <tickets-customer1@example.com>')
- expect(json_response['subject']).to eq('some subject')
- expect(json_response['body']).to eq('some body')
- expect(json_response['content_type']).to eq('text/plain')
- expect(json_response['internal']).to be(false)
- expect(json_response['created_by_id']).to eq(customer.id)
- expect(json_response['sender_id']).to eq(Ticket::Article::Sender.lookup(name: 'Customer').id)
- expect(json_response['type_id']).to eq(Ticket::Article::Type.lookup(name: 'web').id)
- params = {
- subject: 'new subject',
- }
- put "/api/v1/ticket_articles/#{json_response['id']}", params: params, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized (ticket.agent or admin permission required)!')
- delete "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized (admin permission required)!')
- end
- it 'does ticket create with agent - minimal article with customer hash with article.origin_by (03.6)' do
- authenticated_as(customer)
- params = {
- title: 'a new ticket #3.6',
- group: ticket_group.name,
- 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, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #3.6')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- ticket = Ticket.find(json_response['id'])
- article = ticket.articles.first
- expect(article.updated_by_id).to eq(customer.id)
- expect(article.created_by_id).to eq(customer.id)
- expect(article.origin_by_id).to eq(customer.id)
- expect(article.sender.name).to eq('Customer')
- expect(article.type.name).to eq('note')
- expect(article.from).to eq('Tickets Customer1')
- end
- it 'does ticket create with agent - minimal article with customer hash with article.origin_by (03.6)' do
- authenticated_as(customer)
- params = {
- title: 'a new ticket #3.6.1',
- group: ticket_group.name,
- 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, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq('a new ticket #3.6.1')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(customer.id)
- expect(json_response['created_by_id']).to eq(customer.id)
- ticket = Ticket.find(json_response['id'])
- article = ticket.articles.first
- expect(article.updated_by_id).to eq(customer.id)
- expect(article.created_by_id).to eq(customer.id)
- expect(article.origin_by_id).to eq(customer.id)
- expect(article.sender.name).to eq('Customer')
- expect(article.type.name).to eq('note')
- expect(article.from).to eq('Tickets Customer1')
- end
- it 'does ticket show and response format (04.01)' do
- title = "ticket testagent#{SecureRandom.uuid}"
- ticket = create(
- :ticket,
- title: title,
- group: ticket_group,
- customer_id: customer.id,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- authenticated_as(agent)
- get "/api/v1/tickets/#{ticket.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq(ticket.title)
- expect(json_response['group']).to be_falsey
- expect(json_response['priority']).to be_falsey
- expect(json_response['owner']).to be_falsey
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- get "/api/v1/tickets/#{ticket.id}?expand=true", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq(ticket.title)
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['group']).to eq(ticket.group.name)
- expect(json_response['priority']).to eq(ticket.priority.name)
- expect(json_response['owner']).to eq(ticket.owner.login)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- get "/api/v1/tickets/#{ticket.id}?expand=false", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq(ticket.title)
- expect(json_response['group']).to be_falsey
- expect(json_response['priority']).to be_falsey
- expect(json_response['owner']).to be_falsey
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- get "/api/v1/tickets/#{ticket.id}?full=true", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['id']).to eq(ticket.id)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['title']).to eq(ticket.title)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id)
- expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname)
- expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id)
- expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname)
- expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname)
- get "/api/v1/tickets/#{ticket.id}?full=false", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['id']).to eq(ticket.id)
- expect(json_response['title']).to eq(ticket.title)
- expect(json_response['group']).to be_falsey
- expect(json_response['priority']).to be_falsey
- expect(json_response['owner']).to be_falsey
- expect(json_response['customer_id']).to eq(ticket.customer_id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- end
- it 'does ticket index and response format (04.02)' do
- title = "ticket testagent#{SecureRandom.uuid}"
- ticket = create(
- :ticket,
- title: title,
- group: ticket_group,
- customer_id: customer.id,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- authenticated_as(agent)
- get '/api/v1/tickets', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Array)
- expect(json_response[0]).to be_a_kind_of(Hash)
- expect(json_response[0]['id']).to eq(1)
- expect(json_response[1]['id']).to eq(ticket.id)
- expect(json_response[1]['title']).to eq(ticket.title)
- expect(json_response[1]['group']).to be_falsey
- expect(json_response[1]['priority']).to be_falsey
- expect(json_response[1]['owner']).to be_falsey
- expect(json_response[1]['customer_id']).to eq(ticket.customer_id)
- expect(json_response[1]['updated_by_id']).to eq(agent.id)
- expect(json_response[1]['created_by_id']).to eq(agent.id)
- get '/api/v1/tickets?expand=true', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Array)
- expect(json_response[0]).to be_a_kind_of(Hash)
- expect(json_response[0]['id']).to eq(1)
- expect(json_response[1]['id']).to eq(ticket.id)
- expect(json_response[1]['title']).to eq(ticket.title)
- expect(json_response[1]['customer_id']).to eq(ticket.customer_id)
- expect(json_response[1]['group']).to eq(ticket.group.name)
- expect(json_response[1]['priority']).to eq(ticket.priority.name)
- expect(json_response[1]['owner']).to eq(ticket.owner.login)
- expect(json_response[1]['updated_by_id']).to eq(agent.id)
- expect(json_response[1]['created_by_id']).to eq(agent.id)
- get '/api/v1/tickets?expand=false', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Array)
- expect(json_response[0]).to be_a_kind_of(Hash)
- expect(json_response[0]['id']).to eq(1)
- expect(json_response[1]['id']).to eq(ticket.id)
- expect(json_response[1]['title']).to eq(ticket.title)
- expect(json_response[1]['group']).to be_falsey
- expect(json_response[1]['priority']).to be_falsey
- expect(json_response[1]['owner']).to be_falsey
- expect(json_response[1]['customer_id']).to eq(ticket.customer_id)
- expect(json_response[1]['updated_by_id']).to eq(agent.id)
- expect(json_response[1]['created_by_id']).to eq(agent.id)
- get '/api/v1/tickets?full=true', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['record_ids'].class).to eq(Array)
- expect(json_response['record_ids'][0]).to eq(1)
- expect(json_response['record_ids'][1]).to eq(ticket.id)
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['id']).to eq(ticket.id)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['title']).to eq(ticket.title)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id)
- expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname)
- expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id)
- expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname)
- expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname)
- get '/api/v1/tickets?full=false', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Array)
- expect(json_response[0]).to be_a_kind_of(Hash)
- expect(json_response[0]['id']).to eq(1)
- expect(json_response[1]['id']).to eq(ticket.id)
- expect(json_response[1]['title']).to eq(ticket.title)
- expect(json_response[1]['group']).to be_falsey
- expect(json_response[1]['priority']).to be_falsey
- expect(json_response[1]['owner']).to be_falsey
- expect(json_response[1]['customer_id']).to eq(ticket.customer_id)
- expect(json_response[1]['updated_by_id']).to eq(agent.id)
- expect(json_response[1]['created_by_id']).to eq(agent.id)
- end
- it 'does ticket create and response format (04.03)' do
- title = "ticket testagent#{SecureRandom.uuid}"
- params = {
- title: title,
- group: ticket_group.name,
- customer_id: customer.id,
- state: 'new',
- priority: '2 normal',
- article: {
- body: 'some test 123',
- },
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['state_id']).to eq(ticket.state_id)
- expect(json_response['state']).to be_falsey
- expect(json_response['priority_id']).to eq(ticket.priority_id)
- expect(json_response['priority']).to be_falsey
- expect(json_response['group_id']).to eq(ticket.group_id)
- expect(json_response['group']).to be_falsey
- expect(json_response['title']).to eq(title)
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- post '/api/v1/tickets?expand=true', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['state_id']).to eq(ticket.state_id)
- expect(json_response['state']).to eq(ticket.state.name)
- expect(json_response['priority_id']).to eq(ticket.priority_id)
- expect(json_response['priority']).to eq(ticket.priority.name)
- expect(json_response['group_id']).to eq(ticket.group_id)
- expect(json_response['group']).to eq(ticket.group.name)
- expect(json_response['title']).to eq(title)
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- post '/api/v1/tickets?full=true', params: params, as: :json
- expect(response).to have_http_status(:created)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['id']).to eq(ticket.id)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['title']).to eq(title)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id)
- expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname)
- expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id)
- expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname)
- expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname)
- end
- it 'does ticket update and response formats (04.04)' do
- title = "ticket testagent#{SecureRandom.uuid}"
- ticket = create(
- :ticket,
- title: title,
- group: ticket_group,
- customer_id: customer.id,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- params = {
- title: 'a update ticket #1',
- }
- authenticated_as(agent)
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['state_id']).to eq(ticket.state_id)
- expect(json_response['state']).to be_falsey
- expect(json_response['priority_id']).to eq(ticket.priority_id)
- expect(json_response['priority']).to be_falsey
- expect(json_response['group_id']).to eq(ticket.group_id)
- expect(json_response['group']).to be_falsey
- expect(json_response['title']).to eq('a update ticket #1')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- params = {
- title: 'a update ticket #2',
- }
- put "/api/v1/tickets/#{ticket.id}?expand=true", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['state_id']).to eq(ticket.state_id)
- expect(json_response['state']).to eq(ticket.state.name)
- expect(json_response['priority_id']).to eq(ticket.priority_id)
- expect(json_response['priority']).to eq(ticket.priority.name)
- expect(json_response['group_id']).to eq(ticket.group_id)
- expect(json_response['group']).to eq(ticket.group.name)
- expect(json_response['title']).to eq('a update ticket #2')
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- params = {
- title: 'a update ticket #3',
- }
- put "/api/v1/tickets/#{ticket.id}?full=true", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['id']).to eq(ticket.id)
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['title']).to eq('a update ticket #3')
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['customer_id']).to eq(ticket.customer_id)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][agent.id.to_s]['id']).to eq(agent.id)
- expect(json_response['assets']['User'][agent.id.to_s]['firstname']).to eq(agent.firstname)
- expect(json_response['assets']['User'][agent.id.to_s]['lastname']).to eq(agent.lastname)
- expect(json_response['assets']['User']).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]).to be_truthy
- expect(json_response['assets']['User'][customer.id.to_s]['id']).to eq(customer.id)
- expect(json_response['assets']['User'][customer.id.to_s]['firstname']).to eq(customer.firstname)
- expect(json_response['assets']['User'][customer.id.to_s]['lastname']).to eq(customer.lastname)
- # it should be not possible to modify the ticket number
- expected_ticket_number = ticket.number
- params = {
- title: 'a update ticket #4',
- number: '77777',
- }
- put "/api/v1/tickets/#{ticket.id}?full=true", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- ticket = Ticket.find(json_response['id'])
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['title']).to eq('a update ticket #4')
- expect(json_response['assets']['Ticket'][ticket.id.to_s]['number']).to eq(expected_ticket_number)
- end
- it 'does ticket update with empty article param' do
- title = 'a new ticket'
- ticket = create(
- :ticket,
- title: title,
- group: ticket_group,
- customer_id: customer.id,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- params = {
- state: Ticket::State.lookup(name: 'close'),
- article: {}
- }
- authenticated_as(agent)
- put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['state_id']).to eq(ticket.state_id)
- expect(json_response['state']).to be_falsey
- expect(json_response['priority_id']).to eq(ticket.priority_id)
- expect(json_response['priority']).to be_falsey
- expect(json_response['group_id']).to eq(ticket.group_id)
- expect(json_response['group']).to be_falsey
- expect(json_response['customer_id']).to eq(customer.id)
- expect(json_response['updated_by_id']).to eq(agent.id)
- expect(json_response['created_by_id']).to eq(agent.id)
- expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
- expect(json_response['title']).to eq(ticket.title)
- expect(ticket.articles.count).to eq(0)
- end
- it 'does ticket split with html - check attachments (05.01)' do
- ticket = create(
- :ticket,
- title: 'some title',
- group: ticket_group,
- customer_id: customer.id,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- article = create(
- :ticket_article,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- 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,
- )
- 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,
- )
- authenticated_as(customer)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- authenticated_as(agent)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['TicketArticle'][article.id.to_s]).to be_truthy
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(3)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['TicketArticle'][article.id.to_s]).to be_truthy
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(0)
- end
- it 'does ticket split with plain - check attachments (05.02)' do
- ticket = create(
- :ticket,
- title: 'some title',
- group: ticket_group,
- customer_id: customer.id,
- updated_by_id: agent.id,
- created_by_id: agent.id,
- )
- article = create(
- :ticket_article,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- body: '<b>test</b> <img src="cid:15.274327094.140938@zammad.example.com"/>',
- content_type: 'text/plain',
- ticket_id: ticket.id,
- )
- 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,
- )
- authenticated_as(agent)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['TicketArticle'][article.id.to_s]).to be_truthy
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(3)
- get "/api/v1/ticket_split?ticket_id=#{ticket.id}&article_id=#{article.id}&form_id=new_form_id123", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['assets']).to be_truthy
- expect(json_response['assets']['Ticket']).to be_truthy
- expect(json_response['assets']['Ticket'][ticket.id.to_s]).to be_truthy
- expect(json_response['assets']['TicketArticle'][article.id.to_s]).to be_truthy
- expect(json_response['attachments']).to be_truthy
- expect(json_response['attachments'].count).to eq(0)
- end
- it 'does ticket merge (07.01)' do
- group_no_permission = create(:group)
- ticket1 = create(
- :ticket,
- title: 'ticket merge1',
- group: ticket_group,
- customer_id: customer.id,
- )
- ticket2 = create(
- :ticket,
- title: 'ticket merge2',
- group: ticket_group,
- customer_id: customer.id,
- )
- ticket3 = create(
- :ticket,
- title: 'ticket merge2',
- group: group_no_permission,
- customer_id: customer.id,
- )
- authenticated_as(customer)
- put "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- authenticated_as(agent)
- put "/api/v1/ticket_merge/#{ticket2.id}/#{ticket1.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['result']).to eq('failed')
- expect(json_response['message']).to eq('Could not find target ticket number!')
- put "/api/v1/ticket_merge/#{ticket3.id}/#{ticket1.number}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- expect(json_response['error_human']).to eq('Not authorized')
- put "/api/v1/ticket_merge/#{ticket1.id}/#{ticket3.number}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['error']).to eq('Not authorized')
- expect(json_response['error_human']).to eq('Not authorized')
- put "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['result']).to eq('success')
- expect(json_response['target_ticket']['id']).to eq(ticket2.id)
- end
- it 'does ticket merge - change permission (07.02)' do
- group_change_permission = Group.create!(
- name: 'GroupWithChangePermission',
- active: true,
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket1 = create(
- :ticket,
- title: 'ticket merge1',
- group: group_change_permission,
- customer_id: customer.id,
- )
- ticket2 = create(
- :ticket,
- title: 'ticket merge2',
- group: group_change_permission,
- customer_id: customer.id,
- )
- agent.group_names_access_map = { group_change_permission.name => %w[read change] }
- authenticated_as(agent)
- put "/api/v1/ticket_merge/#{ticket1.id}/#{ticket2.number}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['result']).to eq('success')
- expect(json_response['target_ticket']['id']).to eq(ticket2.id)
- end
- it 'does ticket search sorted (08.01)' do
- title = "ticket pagination #{SecureRandom.uuid}"
- ticket1 = create(
- :ticket,
- title: "#{title} A",
- group: ticket_group,
- customer_id: customer.id,
- created_at: '2018-02-05 17:42:00',
- updated_at: '2018-02-05 20:42:00',
- )
- create(
- :ticket_article,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- ticket_id: ticket1.id,
- )
- ticket2 = create(
- :ticket,
- title: "#{title} B",
- group: ticket_group,
- customer_id: customer.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',
- )
- create(
- :ticket_article,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- ticket_id: ticket2.id,
- )
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets']).to eq([ticket2.id, ticket1.id])
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'created_at', order_by: 'asc' }, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets']).to eq([ticket1.id, ticket2.id])
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'title', order_by: 'asc' }, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets']).to eq([ticket1.id, ticket2.id])
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: 'title', order_by: 'desc' }, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets']).to eq([ticket2.id, ticket1.id])
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[asc asc] }, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets']).to eq([ticket1.id, ticket2.id])
- authenticated_as(admin)
- get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[desc asc] }, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['tickets']).to eq([ticket2.id, ticket1.id])
- end
- it 'does ticket history' do
- ticket1 = create(
- :ticket,
- title: 'some title',
- group: ticket_group,
- customer_id: customer.id,
- )
- create(
- :ticket_article,
- type: Ticket::Article::Type.lookup(name: 'note'),
- sender: Ticket::Article::Sender.lookup(name: 'Customer'),
- ticket_id: ticket1.id,
- )
- authenticated_as(agent)
- get "/api/v1/ticket_history/#{ticket1.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to be_a_kind_of(Hash)
- expect(json_response['history'].class).to eq(Array)
- expect(json_response['assets'].class).to eq(Hash)
- expect(json_response['assets']['User'][customer.id.to_s]).not_to be_nil
- expect(json_response['assets']['Ticket'][ticket1.id.to_s]).not_to be_nil
- authenticated_as(customer)
- get "/api/v1/ticket_history/#{ticket1.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- end
- it 'does ticket related' do
- ticket1 = create(
- :ticket,
- title: 'some title',
- group: ticket_group,
- customer_id: customer.id,
- )
- authenticated_as(agent)
- get "/api/v1/ticket_related/#{ticket1.id}", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- authenticated_as(customer)
- get "/api/v1/ticket_related/#{ticket1.id}", params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- end
- it 'does ticket recent' do
- authenticated_as(agent)
- get '/api/v1/ticket_recent', params: {}, as: :json
- expect(response).to have_http_status(:ok)
- authenticated_as(customer)
- get '/api/v1/ticket_recent', params: {}, as: :json
- expect(response).to have_http_status(:forbidden)
- end
- end
- describe 'mentions' do
- let(:user1) { create(:agent, groups: [ticket_group]) }
- let(:user2) { create(:agent, groups: [ticket_group]) }
- let(:user3) { create(:agent, groups: [ticket_group]) }
- def new_ticket_with_mentions
- params = {
- title: 'a new ticket #11',
- group: ticket_group.name,
- customer: {
- firstname: 'some firstname',
- lastname: 'some lastname',
- email: 'some_new_customer@example.com',
- },
- article: {
- body: 'some test 123',
- },
- mentions: [user1.id, user2.id, user3.id]
- }
- authenticated_as(agent)
- post '/api/v1/tickets', params: params, as: :json
- expect(response).to have_http_status(:created)
- json_response
- end
- it 'create ticket with mentions' do
- new_ticket_with_mentions
- expect(Mention.all.count).to eq(3)
- end
- it 'check ticket get' do
- ticket = new_ticket_with_mentions
- get "/api/v1/tickets/#{ticket['id']}?all=true", params: {}, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response['mentions'].count).to eq(3)
- expect(json_response['assets']['Mention'].count).to eq(3)
- end
- end
- describe 'stats' do
- let(:ticket1) { create(:ticket, customer: customer, organization: organization, group: ticket_group) }
- let(:ticket2) { create(:ticket, customer: customer, organization: organization, group: ticket_group) }
- let(:ticket3) { create(:ticket, customer: customer, organization: organization, group: ticket_group) }
- let(:customer) { create(:customer, organization: organization) }
- let(:organization) { create(:organization, shared: false) }
- before do
- authenticated_as(admin)
- ticket1
- travel 2.minutes
- ticket2
- travel 2.minutes
- ticket3
- travel 2.minutes
- ticket2.touch
- end
- # https://github.com/zammad/zammad/issues/2296
- it 'orders tickets by created_at desc (#2296)' do
- get '/api/v1/ticket_stats', params: { organization_id: organization.id, user_id: customer.id }, as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response)
- .to be_a_kind_of(Hash)
- .and include('user' => hash_including('open_ids' => [ticket3.id, ticket2.id, ticket1.id]))
- .and include('organization' => hash_including('open_ids' => [ticket3.id, ticket2.id, ticket1.id]))
- end
- end
- describe '/api/v1/tickets' do
- subject(:ticket) { create(:ticket, state_name: 'closed') }
- let(:admin) { create(:admin, groups: [ticket.group]) }
- let(:agent) { create(:agent, groups: [ticket.group]) }
- let(:customer) { ticket.customer }
- describe 'reopening a ticket' do
- shared_examples 'successfully reopen a ticket' do
- it 'succeeds' do
- put "/api/v1/tickets/#{ticket.id}",
- params: { state_id: Ticket::State.find_by(name: 'open').id },
- as: :json
- expect(response).to have_http_status(:ok)
- expect(json_response).to include('state_id' => Ticket::State.find_by(name: 'open').id)
- end
- end
- shared_examples 'fail to reopen a ticket' do
- it 'fails' do
- put "/api/v1/tickets/#{ticket.id}",
- params: { state_id: Ticket::State.find_by(name: 'open').id },
- as: :json
- expect(response).to have_http_status(:unprocessable_entity)
- expect(json_response).to include('error' => 'Cannot follow-up on a closed ticket. Please create a new ticket.')
- end
- end
- context 'when ticket.group.follow_up_possible = "yes"' do
- before { ticket.group.update(follow_up_possible: 'yes') }
- context 'as admin', authenticated_as: -> { admin } do
- include_examples 'successfully reopen a ticket'
- end
- context 'as agent', authenticated_as: -> { agent } do
- include_examples 'successfully reopen a ticket'
- end
- context 'as customer', authenticated_as: -> { customer } do
- include_examples 'successfully reopen a ticket'
- end
- end
- context 'when ticket.group.follow_up_possible = "new_ticket"' do
- before { ticket.group.update(follow_up_possible: 'new_ticket') }
- context 'as admin', authenticated_as: -> { admin } do
- include_examples 'successfully reopen a ticket'
- end
- context 'as agent', authenticated_as: -> { agent } do
- include_examples 'successfully reopen a ticket'
- end
- context 'as customer', authenticated_as: -> { customer } do
- include_examples 'fail to reopen a ticket'
- end
- end
- end
- end
- describe 'GET /api/v1/tickets/:id' do
- subject!(:ticket) { create(:ticket) }
- let(:agent) { create(:agent, groups: [ticket.group]) }
- context 'links present', authenticated_as: -> { agent } do
- before do
- create(:link, from: ticket, to: linked)
- get "/api/v1/tickets/#{ticket.id}", params: { all: 'true' }, as: :json
- end
- let(:linked) { create(:ticket, group: ticket.group) }
- it 'is present in response' do
- expect(response).to have_http_status(:ok)
- expect(json_response['links']).to eq([
- {
- 'link_type' => 'normal',
- 'link_object' => 'Ticket',
- 'link_object_value' => linked.id
- }
- ])
- end
- context 'no permission to linked Ticket Group' do
- let(:linked) { create(:ticket) }
- it 'is not present in response' do
- expect(response).to have_http_status(:ok)
- expect(json_response['links']).to be_blank
- end
- end
- end
- end
- describe 'GET /api/v1/ticket_customer' do
- subject(:ticket) { create(:ticket, customer: customer_authorized) }
- let(:organization_authorized) { create(:organization) }
- let(:customer_authorized) { create(:customer, organization: organization_authorized) }
- let(:organization_unauthorized) { create(:organization) }
- let(:customer_unauthorized) { create(:customer, organization: organization_unauthorized) }
- let(:agent) { create(:agent, groups: [ticket.group]) }
- describe 'listing information' do
- before do
- ticket
- end
- shared_examples 'has access' do
- it 'succeeds' do
- get '/api/v1/ticket_customer',
- params: { customer_id: customer_authorized.id },
- as: :json
- expect(json_response['ticket_ids_open']).to include(ticket.id)
- expect(json_response['ticket_ids_closed']).to be_blank
- end
- end
- shared_examples 'has no access' do
- it 'fails' do
- get '/api/v1/ticket_customer',
- params: { customer_id: customer_authorized.id },
- as: :json
- expect(json_response['ticket_ids_open']).to be_blank
- expect(json_response['ticket_ids_closed']).to be_blank
- expect(json_response['assets']).to be_blank
- end
- end
- context 'as agent', authenticated_as: -> { agent } do
- include_examples 'has access'
- end
- context 'as authorized customer', authenticated_as: -> { customer_authorized } do
- include_examples 'has no access'
- end
- context 'as unauthorized customer', authenticated_as: -> { customer_unauthorized } do
- include_examples 'has no access'
- end
- end
- end
- end
|