@@ -26,6 +26,186 @@ import { IS_EE } from '../../../e2e/config/constants';
2626 await updateSetting ( 'Livechat_Routing_Method' , 'Manual_Selection' ) ;
2727 } ) ;
2828
29+ // Basically: if there's a bot in the department, it should be assigned to the conversation
30+ // No matter what settings workspace has in, as long as the setting to assign new conversations to bots is enabled
31+ describe ( 'Bots - Manual selection' , ( ) => {
32+ let botUser : { user : IUser ; credentials : Credentials } ;
33+ let testDepartment : ILivechatDepartment ;
34+ let testDepartment2 : ILivechatDepartment ;
35+ before ( async ( ) => {
36+ const bot = await createUser ( { roles : [ 'bot' , 'livechat-agent' ] } ) ;
37+ const credentials = await login ( bot . username , password ) ;
38+
39+ botUser = { user : bot , credentials } ;
40+ } ) ;
41+ before ( async ( ) => {
42+ testDepartment = await createDepartment ( [ { agentId : botUser . user . _id } ] ) ;
43+ testDepartment2 = await createDepartment ( ) ;
44+ await updateSetting ( 'Livechat_Routing_Method' , 'Manual_Selection' ) ;
45+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , true ) ;
46+ await updateSetting ( 'Livechat_accept_chats_with_no_agents' , true ) ;
47+ } ) ;
48+
49+ after ( async ( ) => {
50+ await deleteUser ( botUser . user ) ;
51+ await updateSetting ( 'Livechat_Routing_Method' , 'Auto_Selection' ) ;
52+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , false ) ;
53+ await updateSetting ( 'Livechat_accept_chats_with_no_agents' , false ) ;
54+ } ) ;
55+
56+ it ( 'should assign conversation to bot' , async ( ) => {
57+ const visitor = await createVisitor ( testDepartment . _id ) ;
58+ const room = await createLivechatRoom ( visitor . token ) ;
59+
60+ const roomInfo = await getLivechatRoomInfo ( room . _id ) ;
61+
62+ expect ( roomInfo . servedBy ?. _id ) . to . be . equal ( botUser . user . _id ) ;
63+ } ) ;
64+ it ( 'should not assign conversation to bot if department has no bots' , async ( ) => {
65+ const visitor = await createVisitor ( testDepartment2 . _id ) ;
66+ const room = await createLivechatRoom ( visitor . token ) ;
67+
68+ expect ( room . servedBy ) . to . be . undefined ;
69+ } ) ;
70+
71+ describe ( 'with setting disabled' , ( ) => {
72+ before ( async ( ) => {
73+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , false ) ;
74+ } ) ;
75+ after ( async ( ) => {
76+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , true ) ;
77+ } ) ;
78+
79+ it ( 'should not assign conversation to bot' , async ( ) => {
80+ const visitor = await createVisitor ( testDepartment . _id ) ;
81+ const room = await createLivechatRoom ( visitor . token ) ;
82+
83+ expect ( room . servedBy ) . to . be . undefined ;
84+ } ) ;
85+ } ) ;
86+ } ) ;
87+
88+ describe ( 'Bots - Auto selection' , ( ) => {
89+ let botUser : { user : IUser ; credentials : Credentials } ;
90+ let otherUser : { user : IUser ; credentials : Credentials } ;
91+ let testDepartment : ILivechatDepartment ;
92+ let testDepartment2 : ILivechatDepartment ;
93+ before ( async ( ) => {
94+ const bot = await createUser ( { roles : [ 'bot' , 'livechat-agent' ] } ) ;
95+ const credentials = await login ( bot . username , password ) ;
96+
97+ const other = await createUser ( { roles : [ 'livechat-agent' ] } ) ;
98+ const otherCredentials = await login ( other . username , password ) ;
99+
100+ await makeAgentAvailable ( otherCredentials ) ;
101+
102+ botUser = { user : bot , credentials } ;
103+ otherUser = { user : other , credentials : otherCredentials } ;
104+ } ) ;
105+ before ( async ( ) => {
106+ testDepartment = await createDepartment ( [ { agentId : botUser . user . _id } , { agentId : otherUser . user . _id } ] ) ;
107+ testDepartment2 = await createDepartment ( ) ;
108+ await updateSetting ( 'Livechat_Routing_Method' , 'Auto_Selection' ) ;
109+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , true ) ;
110+ await updateSetting ( 'Livechat_accept_chats_with_no_agents' , true ) ;
111+ } ) ;
112+
113+ after ( async ( ) => {
114+ await deleteUser ( botUser . user ) ;
115+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , false ) ;
116+ await updateSetting ( 'Livechat_accept_chats_with_no_agents' , false ) ;
117+ } ) ;
118+
119+ it ( 'should assign conversation to bot' , async ( ) => {
120+ const visitor = await createVisitor ( testDepartment . _id ) ;
121+ const room = await createLivechatRoom ( visitor . token ) ;
122+
123+ const roomInfo = await getLivechatRoomInfo ( room . _id ) ;
124+
125+ expect ( roomInfo . servedBy ?. _id ) . to . be . equal ( botUser . user . _id ) ;
126+ } ) ;
127+ it ( 'should not assign conversation to bot if department has no bots' , async ( ) => {
128+ const visitor = await createVisitor ( testDepartment2 . _id ) ;
129+ const room = await createLivechatRoom ( visitor . token ) ;
130+
131+ expect ( room . servedBy ) . to . be . undefined ;
132+ } ) ;
133+
134+ describe ( 'with setting disabled' , ( ) => {
135+ before ( async ( ) => {
136+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , false ) ;
137+ } ) ;
138+ after ( async ( ) => {
139+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , true ) ;
140+ } ) ;
141+
142+ it ( 'should not assign conversation to bot' , async ( ) => {
143+ const visitor = await createVisitor ( testDepartment . _id ) ;
144+ const room = await createLivechatRoom ( visitor . token ) ;
145+
146+ expect ( room . servedBy ?. _id ) . to . be . equal ( otherUser . user . _id ) ;
147+ } ) ;
148+ } ) ;
149+ } ) ;
150+
151+ describe ( 'Bots - Auto selection & Waiting queue' , ( ) => {
152+ let botUser : { user : IUser ; credentials : Credentials } ;
153+ let testDepartment : ILivechatDepartment ;
154+ let testDepartment2 : ILivechatDepartment ;
155+ before ( async ( ) => {
156+ const bot = await createUser ( { roles : [ 'bot' , 'livechat-agent' ] } ) ;
157+ const credentials = await login ( bot . username , password ) ;
158+
159+ botUser = { user : bot , credentials } ;
160+ } ) ;
161+ before ( async ( ) => {
162+ testDepartment = await createDepartment ( [ { agentId : botUser . user . _id } ] ) ;
163+ testDepartment2 = await createDepartment ( ) ;
164+ await updateSetting ( 'Livechat_Routing_Method' , 'Auto_Selection' ) ;
165+ await updateSetting ( 'Livechat_waiting_queue' , true ) ;
166+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , true ) ;
167+ await updateSetting ( 'Livechat_accept_chats_with_no_agents' , true ) ;
168+ } ) ;
169+
170+ after ( async ( ) => {
171+ await deleteUser ( botUser . user ) ;
172+ await updateSetting ( 'Livechat_waiting_queue' , false ) ;
173+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , false ) ;
174+ await updateSetting ( 'Livechat_accept_chats_with_no_agents' , false ) ;
175+ } ) ;
176+
177+ it ( 'should assign conversation to bot' , async ( ) => {
178+ const visitor = await createVisitor ( testDepartment . _id ) ;
179+ const room = await createLivechatRoom ( visitor . token ) ;
180+
181+ const roomInfo = await getLivechatRoomInfo ( room . _id ) ;
182+
183+ expect ( roomInfo . servedBy ?. _id ) . to . be . equal ( botUser . user . _id ) ;
184+ } ) ;
185+ it ( 'should not assign conversation to bot if department has no bots' , async ( ) => {
186+ const visitor = await createVisitor ( testDepartment2 . _id ) ;
187+ const room = await createLivechatRoom ( visitor . token ) ;
188+
189+ expect ( room . servedBy ) . to . be . undefined ;
190+ } ) ;
191+
192+ describe ( 'with setting disabled' , ( ) => {
193+ before ( async ( ) => {
194+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , false ) ;
195+ } ) ;
196+ after ( async ( ) => {
197+ await updateSetting ( 'Livechat_assign_new_conversation_to_bot' , true ) ;
198+ } ) ;
199+
200+ it ( 'should not assign conversation to bot' , async ( ) => {
201+ const visitor = await createVisitor ( testDepartment . _id ) ;
202+ const room = await createLivechatRoom ( visitor . token ) ;
203+
204+ expect ( room . servedBy ) . to . be . undefined ;
205+ } ) ;
206+ } ) ;
207+ } ) ;
208+
29209 describe ( 'Auto-Selection' , ( ) => {
30210 before ( async ( ) => {
31211 await updateSetting ( 'Livechat_Routing_Method' , 'Auto_Selection' ) ;
0 commit comments