11import type { Page } from '@playwright/test' ;
2- import type { IRoom } from '@rocket.chat/core-typings' ;
32
43import { createFakeVisitor } from '../../mocks/data' ;
54import { IS_EE } from '../config/constants' ;
65import { createAuxContext } from '../fixtures/createAuxContext' ;
76import { Users } from '../fixtures/userStates' ;
87import { HomeOmnichannel } from '../page-objects' ;
9- import { OmnichannelLiveChat } from '../page-objects/omnichannel' ;
108import { setSettingValueById } from '../utils' ;
119import { createAgent } from '../utils/omnichannel/agents' ;
1210import { addAgentToDepartment , createDepartment } from '../utils/omnichannel/departments' ;
1311import { createManager } from '../utils/omnichannel/managers' ;
12+ import { createConversation } from '../utils/omnichannel/rooms' ;
1413import { test , expect } from '../utils/test' ;
1514
1615test . use ( { storageState : Users . user1 . state } ) ;
1716
18- test . describe ( 'OC - Forwarding to away agents (EE)' , ( ) => {
17+ test . describe ( 'OC - Forwarding to away departments (EE)' , ( ) => {
1918 test . skip ( ! IS_EE , 'Enterprise Edition Only' ) ;
2019
2120 let poHomeOmnichannelOnlineAgent : HomeOmnichannel ;
2221 let poHomeOmnichannelAwayAgent : HomeOmnichannel ;
23- let poLivechat : OmnichannelLiveChat ;
2422
25- let livechatPage : Page | undefined ;
2623 let omnichannelPage : Page | undefined ;
2724
2825 let manager : Awaited < ReturnType < typeof createManager > > ;
2926 let onlineAgent : Awaited < ReturnType < typeof createAgent > > ;
3027 let awayAgent : Awaited < ReturnType < typeof createAgent > > ;
3128 let initialDepartment : Awaited < ReturnType < typeof createDepartment > > ;
3229 let forwardToOfflineDepartment : Awaited < ReturnType < typeof createDepartment > > ;
30+ let conversation : Awaited < ReturnType < typeof createConversation > > ;
3331 let visitor : { name : string ; email : string } ;
3432
3533 test . beforeAll ( async ( { api } ) => {
@@ -66,10 +64,7 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
6664 await poHomeOmnichannelOnlineAgent . page . goto ( '/' ) ;
6765 await poHomeOmnichannelOnlineAgent . waitForHome ( ) ;
6866
69- ( { page : livechatPage } = await createAuxContext ( browser , Users . user1 , '/livechat' , false ) ) ;
70- poLivechat = new OmnichannelLiveChat ( livechatPage , api ) ;
71-
72- await expect ( setSettingValueById ( api , 'Accounts_Default_User_Preferences_idleTimeLimit' , 1 ) ) . resolves . toBeOK ( ) ;
67+ await expect ( await setSettingValueById ( api , 'Accounts_Default_User_Preferences_idleTimeLimit' , 1 ) ) . toBeOK ( ) ;
7368
7469 // Away Agent window opens with idleTimeLimit of 1, therefore after a second it will turn away
7570 ( { page : omnichannelPage } = await createAuxContext ( browser , Users . user2 , '/' , false ) ) ;
@@ -78,14 +73,12 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
7873 } ) ;
7974
8075 test . afterEach ( async ( { api } ) => {
81- if ( livechatPage ) {
82- await livechatPage . context ( ) . close ( ) ;
83- }
8476 if ( omnichannelPage ) {
8577 await omnichannelPage . context ( ) . close ( ) ;
8678 }
8779
88- await expect ( setSettingValueById ( api , 'Accounts_Default_User_Preferences_idleTimeLimit' , 300 ) ) . resolves . toBeOK ( ) ;
80+ await expect ( await setSettingValueById ( api , 'Livechat_waiting_queue' , false ) ) . toBeOK ( ) ;
81+ await expect ( await setSettingValueById ( api , 'Accounts_Default_User_Preferences_idleTimeLimit' , 300 ) ) . toBeOK ( ) ;
8982 } ) ;
9083
9184 test . afterAll ( async ( { api } ) => {
@@ -108,16 +101,11 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
108101 api,
109102 } ) => {
110103 await test . step ( 'Setup routing settings' , async ( ) => {
111- await expect ( setSettingValueById ( api , 'Livechat_Routing_Method' , 'Manual_Selection' ) ) . resolves . toBeOK ( ) ;
104+ await expect ( await setSettingValueById ( api , 'Livechat_Routing_Method' , 'Manual_Selection' ) ) . toBeOK ( ) ;
112105 } ) ;
113106
114107 await test . step ( 'Visitor initiates chat' , async ( ) => {
115- await poLivechat . page . reload ( ) ;
116- await poLivechat . openAnyLiveChatAndSendMessage ( {
117- liveChatUser : visitor ,
118- message : 'test message' ,
119- isOffline : false ,
120- } ) ;
108+ conversation = await createConversation ( api , { visitorName : visitor . name , agentId : onlineAgent . data . _id } ) ;
121109 } ) ;
122110
123111 await test . step ( 'Manager forwards chat' , async ( ) => {
@@ -129,12 +117,7 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
129117 } ) ;
130118
131119 await test . step ( 'Check inquiry status via API is queued' , async ( ) => {
132- const roomInfoResp = await api . get ( `/livechat/rooms` ) ;
133- await expect ( roomInfoResp ) . toBeOK ( ) ;
134- const roomBody = await roomInfoResp . json ( ) ;
135- const roomId = roomBody . rooms . find ( ( room : IRoom ) => room . fname === visitor . name ) . _id ;
136-
137- const inquiryResp = await api . get ( `/livechat/inquiries.getOne?roomId=${ roomId } ` ) ;
120+ const inquiryResp = await api . get ( `/livechat/inquiries.getOne?roomId=${ conversation . data . room . _id } ` ) ;
138121 await expect ( inquiryResp ) . toBeOK ( ) ;
139122 const inquiryBody = await inquiryResp . json ( ) ;
140123
@@ -147,21 +130,16 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
147130 api,
148131 } ) => {
149132 await test . step ( 'Setup routing settings' , async ( ) => {
150- await expect ( setSettingValueById ( api , 'Livechat_Routing_Method' , 'Auto_Selection' ) ) . resolves . toBeOK ( ) ;
133+ await expect ( await setSettingValueById ( api , 'Livechat_Routing_Method' , 'Auto_Selection' ) ) . toBeOK ( ) ;
151134 } ) ;
152135
153136 await test . step ( 'Visitor initiates chat' , async ( ) => {
154- await poLivechat . page . reload ( ) ;
155- await poLivechat . openAnyLiveChatAndSendMessage ( {
156- liveChatUser : visitor ,
157- message : 'test message' ,
158- isOffline : false ,
159- } ) ;
137+ conversation = await createConversation ( api , { visitorName : visitor . name , agentId : onlineAgent . data . _id } ) ;
160138 } ) ;
161139
162140 await test . step ( 'Manager enables queue and forwards chat' , async ( ) => {
163141 await poHomeOmnichannelOnlineAgent . sidebar . getSidebarItemByName ( visitor . name ) . click ( ) ;
164- await expect ( setSettingValueById ( api , 'Livechat_waiting_queue' , true ) ) . resolves . toBeOK ( ) ;
142+ await expect ( await setSettingValueById ( api , 'Livechat_waiting_queue' , true ) ) . toBeOK ( ) ;
165143
166144 await poHomeOmnichannelOnlineAgent . quickActionsRoomToolbar . forwardChat ( ) ;
167145 await poHomeOmnichannelOnlineAgent . content . forwardChatModal . selectDepartment ( 'Forward Dept' ) ;
@@ -170,48 +148,34 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
170148 } ) ;
171149
172150 await test . step ( 'Check inquiry status via API is queued' , async ( ) => {
173- const roomInfoResp = await api . get ( `/livechat/rooms` ) ;
174- await expect ( roomInfoResp ) . toBeOK ( ) ;
175- const roomBody = await roomInfoResp . json ( ) ;
176- const roomId = roomBody . rooms . find ( ( room : IRoom ) => room . fname === visitor . name ) . _id ;
177-
178- const inquiryResp = await api . get ( `/livechat/inquiries.getOne?roomId=${ roomId } ` ) ;
151+ const inquiryResp = await api . get ( `/livechat/inquiries.getOne?roomId=${ conversation . data . room . _id } ` ) ;
179152 await expect ( inquiryResp ) . toBeOK ( ) ;
180153 const inquiryBody = await inquiryResp . json ( ) ;
181154
182155 expect ( inquiryBody . inquiry . status ) . toBe ( 'queued' ) ;
183156 expect ( inquiryBody . inquiry . department ) . toBe ( forwardToOfflineDepartment . data . _id ) ;
184157 } ) ;
185-
186- await test . step ( 'Disable waiting queue' , async ( ) => {
187- await expect ( setSettingValueById ( api , 'Livechat_waiting_queue' , false ) ) . resolves . toBeOK ( ) ;
188- } ) ;
189158 } ) ;
190159
191160 test ( 'when manager forward to a department while waiting_queue is active and allowReceiveForwardOffline is false, transfer should fail' , async ( {
192161 api,
193162 } ) => {
194163 await test . step ( 'Setup routing and department settings' , async ( ) => {
195- await expect ( setSettingValueById ( api , 'Livechat_Routing_Method' , 'Auto_Selection' ) ) . resolves . toBeOK ( ) ;
164+ await expect ( await setSettingValueById ( api , 'Livechat_Routing_Method' , 'Auto_Selection' ) ) . toBeOK ( ) ;
196165 await expect (
197- api . put ( `/livechat/department/${ forwardToOfflineDepartment . data . _id } ` , {
166+ await api . put ( `/livechat/department/${ forwardToOfflineDepartment . data . _id } ` , {
198167 department : { ...forwardToOfflineDepartment . data , allowReceiveForwardOffline : false } ,
199168 } ) ,
200- ) . resolves . toBeOK ( ) ;
169+ ) . toBeOK ( ) ;
201170 } ) ;
202171
203172 await test . step ( 'Visitor initiates chat' , async ( ) => {
204- await poLivechat . page . reload ( ) ;
205- await poLivechat . openAnyLiveChatAndSendMessage ( {
206- liveChatUser : visitor ,
207- message : 'test message' ,
208- isOffline : false ,
209- } ) ;
173+ conversation = await createConversation ( api , { visitorName : visitor . name , agentId : onlineAgent . data . _id } ) ;
210174 } ) ;
211175
212176 await test . step ( 'Manager attempts to forward and sees error' , async ( ) => {
213177 await poHomeOmnichannelOnlineAgent . sidebar . getSidebarItemByName ( visitor . name ) . click ( ) ;
214- await expect ( setSettingValueById ( api , 'Livechat_waiting_queue' , true ) ) . resolves . toBeOK ( ) ;
178+ await expect ( await setSettingValueById ( api , 'Livechat_waiting_queue' , true ) ) . toBeOK ( ) ;
215179
216180 await poHomeOmnichannelOnlineAgent . quickActionsRoomToolbar . forwardChat ( ) ;
217181 await poHomeOmnichannelOnlineAgent . content . forwardChatModal . selectDepartment ( 'Forward Dept' ) ;
@@ -223,37 +187,27 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
223187
224188 await test . step ( 'Restore department setting' , async ( ) => {
225189 await expect (
226- api . put ( `/livechat/department/${ forwardToOfflineDepartment . data . _id } ` , {
190+ await api . put ( `/livechat/department/${ forwardToOfflineDepartment . data . _id } ` , {
227191 department : { ...forwardToOfflineDepartment . data , allowReceiveForwardOffline : true } ,
228192 } ) ,
229- ) . resolves . toBeOK ( ) ;
230- } ) ;
231-
232- await test . step ( 'Disable waiting queue' , async ( ) => {
233- await expect ( setSettingValueById ( api , 'Livechat_waiting_queue' , false ) ) . resolves . toBeOK ( ) ;
193+ ) . toBeOK ( ) ;
234194 } ) ;
235195 } ) ;
236196
237197 test ( 'when manager forward to online (agent away, accept when agent idle on) department the inquiry should not be set to the queue' , async ( {
238198 api,
239199 } ) => {
240200 await test . step ( 'Setup routing settings' , async ( ) => {
241- await expect ( setSettingValueById ( api , 'Livechat_Routing_Method' , 'Auto_Selection' ) ) . resolves . toBeOK ( ) ;
201+ await expect ( await setSettingValueById ( api , 'Livechat_Routing_Method' , 'Auto_Selection' ) ) . toBeOK ( ) ;
242202 } ) ;
243203
244204 await test . step ( 'Visitor initiates chat' , async ( ) => {
245- await poLivechat . page . reload ( ) ;
246- await poLivechat . openAnyLiveChatAndSendMessage ( {
247- liveChatUser : visitor ,
248- message : 'test message' ,
249- isOffline : false ,
250- } ) ;
251- await expect ( poLivechat . headerTitle ) . toHaveText ( onlineAgent . data . username ) ;
205+ conversation = await createConversation ( api , { visitorName : visitor . name , agentId : onlineAgent . data . _id } ) ;
252206 } ) ;
253207
254208 await test . step ( 'Set Livechat_enabled_when_agent_idle to true' , async ( ) => {
255209 // We set Livechat_enabled_when_agent_idle to true here in order to not assign the away agent in the previous step
256- await expect ( setSettingValueById ( api , 'Livechat_enabled_when_agent_idle' , true ) ) . resolves . toBeOK ( ) ;
210+ await expect ( await setSettingValueById ( api , 'Livechat_enabled_when_agent_idle' , true ) ) . toBeOK ( ) ;
257211 } ) ;
258212
259213 await test . step ( 'Manager forwards chat successfully' , async ( ) => {
@@ -265,13 +219,11 @@ test.describe('OC - Forwarding to away agents (EE)', () => {
265219 } ) ;
266220
267221 await test . step ( 'Check room routing via API serves to away agent' , async ( ) => {
268- const roomInfoResp = await api . get ( `/livechat/rooms` ) ;
269- await expect ( roomInfoResp ) . toBeOK ( ) ;
270- const roomBody = await roomInfoResp . json ( ) ;
271- const room = roomBody . rooms . find ( ( room : IRoom ) => room . fname === visitor . name ) ;
272-
273- expect ( room . servedBy . _id ) . toBe ( awayAgent . data . _id ) ;
274- expect ( room . departmentId ) . toBe ( forwardToOfflineDepartment . data . _id ) ;
222+ const inquiryResp = await api . get ( `/livechat/inquiries.getOne?roomId=${ conversation . data . room . _id } ` ) ;
223+ await expect ( inquiryResp ) . toBeOK ( ) ;
224+ const inquiryBody = await inquiryResp . json ( ) ;
225+ expect ( inquiryBody . inquiry . status ) . toBe ( 'taken' ) ;
226+ expect ( inquiryBody . inquiry . department ) . toBe ( forwardToOfflineDepartment . data . _id ) ;
275227 } ) ;
276228 } ) ;
277229} ) ;
0 commit comments