Skip to content

Commit b128a5f

Browse files
Merge branch 'release-8.0.3' into backport-8.0.3-39492
2 parents 2229e0e + 60d3126 commit b128a5f

File tree

5 files changed

+23
-74
lines changed

5 files changed

+23
-74
lines changed

apps/meteor/.mocharc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ module.exports = {
3030
'app/file-upload/server/**/*.spec.ts',
3131
'app/statistics/server/**/*.spec.ts',
3232
'app/livechat/server/lib/**/*.spec.ts',
33-
'app/utils/server/**/*.spec.ts',
3433
],
3534
};

apps/meteor/app/livechat/server/lib/contacts/mapVisitorToContact.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
2727
contactManager: {
2828
username: 'user1',
2929
},
30+
lastChat: { _id: 'afdsfdasf', ts: testDate },
3031
},
3132
{
3233
type: OmnichannelSourceType.WIDGET,
@@ -50,8 +51,10 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
5051
details: {
5152
type: OmnichannelSourceType.WIDGET,
5253
},
54+
lastChat: { _id: 'afdsfdasf', ts: testDate },
5355
},
5456
],
57+
lastChat: { _id: 'afdsfdasf', ts: testDate },
5558
customFields: undefined,
5659
shouldValidateCustomFields: false,
5760
contactManager: 'manager1',
@@ -62,6 +65,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
6265
{
6366
_id: 'visitor1',
6467
username: 'Username',
68+
lastChat: { _id: 'afdsfdasf', ts: testDate },
6569
},
6670
{
6771
type: OmnichannelSourceType.SMS,
@@ -85,11 +89,13 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
8589
details: {
8690
type: OmnichannelSourceType.SMS,
8791
},
92+
lastChat: { _id: 'afdsfdasf', ts: testDate },
8893
},
8994
],
9095
customFields: undefined,
9196
shouldValidateCustomFields: false,
9297
contactManager: undefined,
98+
lastChat: { _id: 'afdsfdasf', ts: testDate },
9399
},
94100
],
95101

@@ -113,7 +119,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
113119
unknown: false,
114120
channels: [
115121
{
116-
name: 'sms',
122+
name: 'widget',
117123
visitor: {
118124
visitorId: 'visitor1',
119125
source: {
@@ -150,6 +156,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
150156
invalidCustomFieldId: 'invalidCustomFieldValue',
151157
},
152158
activity: [],
159+
lastChat: { _id: 'afdsfdasf', ts: testDate },
153160
},
154161
{
155162
type: OmnichannelSourceType.WIDGET,
@@ -161,7 +168,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
161168
unknown: true,
162169
channels: [
163170
{
164-
name: 'sms',
171+
name: 'widget',
165172
visitor: {
166173
visitorId: 'visitor1',
167174
source: {
@@ -173,13 +180,15 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
173180
details: {
174181
type: OmnichannelSourceType.WIDGET,
175182
},
183+
lastChat: { _id: 'afdsfdasf', ts: testDate },
176184
},
177185
],
178186
customFields: {
179187
customFieldId: 'customFieldValue',
180188
},
181189
shouldValidateCustomFields: false,
182190
contactManager: undefined,
191+
lastChat: { _id: 'afdsfdasf', ts: testDate },
183192
},
184193
],
185194
];
@@ -197,10 +206,9 @@ describe('mapVisitorToContact', () => {
197206
getAllowedCustomFields.resolves([{ _id: 'customFieldId', label: 'custom-field-label' }]);
198207
});
199208

200-
const index = 0;
201-
for (const [visitor, source, contact] of dataMap) {
209+
dataMap.forEach(([visitor, source, contact], index) => {
202210
it(`should map an ILivechatVisitor + IOmnichannelSource to an ILivechatContact [${index}]`, async () => {
203211
expect(await mapVisitorToContact(visitor, source)).to.be.deep.equal(contact);
204212
});
205-
}
213+
});
206214
});

apps/meteor/app/livechat/server/lib/contacts/resolveContactConflicts.spec.ts

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,14 @@ describe('resolveContactConflicts', () => {
3636
conflictingFields: [{ field: 'customFields.customField', value: 'oldValue' }],
3737
});
3838
modelsMock.Settings.incrementValueById.resolves(1);
39-
modelsMock.LivechatContacts.updateContact.resolves({
40-
_id: 'contactId',
41-
customField: { customField: 'newValue' },
42-
conflictingFields: [{ field: 'customFields.customField', value: 'oldValue' }],
43-
} as Partial<ILivechatContact>);
4439

45-
const result = await resolveContactConflicts({ contactId: 'contactId', customField: { customField: 'newValue' } });
40+
await resolveContactConflicts({ contactId: 'contactId', customFields: { customField: 'newestValue' } });
4641

4742
expect(modelsMock.LivechatContacts.findOneEnabledById.getCall(0).args[0]).to.be.equal('contactId');
4843

49-
expect(modelsMock.Settings.incrementValueById.getCall(0).args[0]).to.be.equal('Livechat_conflicting_fields_counter');
50-
expect(modelsMock.Settings.incrementValueById.getCall(0).args[1]).to.be.equal(1);
51-
5244
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[0]).to.be.equal('contactId');
53-
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({ customFields: { customField: 'newValue' } });
54-
expect(result).to.be.deep.equal({
55-
_id: 'contactId',
56-
customField: { customField: 'newValue' },
57-
conflictingFields: [],
45+
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({
46+
customFields: { customField: 'newestValue' },
5847
});
5948
});
6049

@@ -66,28 +55,13 @@ describe('resolveContactConflicts', () => {
6655
conflictingFields: [{ field: 'name', value: 'Old Name' }],
6756
});
6857
modelsMock.Settings.incrementValueById.resolves(1);
69-
modelsMock.LivechatContacts.updateContact.resolves({
70-
_id: 'contactId',
71-
name: 'New Name',
72-
customField: { customField: 'newValue' },
73-
conflictingFields: [],
74-
} as Partial<ILivechatContact>);
7558

76-
const result = await resolveContactConflicts({ contactId: 'contactId', name: 'New Name' });
59+
await resolveContactConflicts({ contactId: 'contactId', name: 'New Name' });
7760

7861
expect(modelsMock.LivechatContacts.findOneEnabledById.getCall(0).args[0]).to.be.equal('contactId');
7962

80-
expect(modelsMock.Settings.incrementValueById.getCall(0).args[0]).to.be.equal('Livechat_conflicting_fields_counter');
81-
expect(modelsMock.Settings.incrementValueById.getCall(0).args[1]).to.be.equal(1);
82-
8363
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[0]).to.be.equal('contactId');
8464
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({ name: 'New Name' });
85-
expect(result).to.be.deep.equal({
86-
_id: 'contactId',
87-
name: 'New Name',
88-
customField: { customField: 'newValue' },
89-
conflictingFields: [],
90-
});
9165
});
9266

9367
it('should update the contact with the resolved contact manager', async () => {
@@ -96,31 +70,16 @@ describe('resolveContactConflicts', () => {
9670
name: 'Name',
9771
contactManager: 'contactManagerId',
9872
customFields: { customField: 'value' },
99-
conflictingFields: [{ field: 'manager', value: 'newContactManagerId' }],
73+
conflictingFields: [{ field: 'manager', value: 'oldManagerId' }],
10074
});
101-
modelsMock.Settings.incrementValueById.resolves(1);
102-
modelsMock.LivechatContacts.updateContact.resolves({
103-
_id: 'contactId',
104-
name: 'Name',
105-
contactManager: 'newContactManagerId',
106-
customField: { customField: 'value' },
107-
conflictingFields: [],
108-
} as Partial<ILivechatContact>);
10975

110-
const result = await resolveContactConflicts({ contactId: 'contactId', name: 'New Name' });
76+
await resolveContactConflicts({ contactId: 'contactId', name: 'New Name', customFields: { manager: 'newContactManagerId' } });
11177

11278
expect(modelsMock.LivechatContacts.findOneEnabledById.getCall(0).args[0]).to.be.equal('contactId');
11379

114-
expect(modelsMock.Settings.incrementValueById.getCall(0).args[0]).to.be.equal('Livechat_conflicting_fields_counter');
115-
expect(modelsMock.Settings.incrementValueById.getCall(0).args[1]).to.be.equal(1);
116-
11780
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[0]).to.be.equal('contactId');
118-
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({ contactManager: 'newContactManagerId' });
119-
expect(result).to.be.deep.equal({
120-
_id: 'contactId',
121-
name: 'New Name',
122-
customField: { customField: 'newValue' },
123-
conflictingFields: [],
81+
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({
82+
customFields: { customField: 'value', manager: 'newContactManagerId' },
12483
});
12584
});
12685

@@ -219,21 +178,4 @@ describe('resolveContactConflicts', () => {
219178
);
220179
expect(modelsMock.LivechatContacts.updateContact.getCall(0)).to.be.null;
221180
});
222-
223-
it('should throw an error if the contact manager is invalid', async () => {
224-
modelsMock.LivechatContacts.findOneEnabledById.resolves({
225-
_id: 'contactId',
226-
name: 'Name',
227-
contactManager: 'contactManagerId',
228-
customFields: { customField: 'value' },
229-
conflictingFields: [{ field: 'manager', value: 'newContactManagerId' }],
230-
});
231-
await expect(resolveContactConflicts({ contactId: 'id', contactManager: 'invalid' })).to.be.rejectedWith(
232-
'error-contact-manager-not-found',
233-
);
234-
235-
expect(validateContactManagerMock.getCall(0).args[0]).to.be.equal('invalid');
236-
237-
expect(modelsMock.LivechatContacts.updateContact.getCall(0)).to.be.null;
238-
});
239181
});

apps/meteor/app/livechat/server/lib/contacts/updateContact.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const modelsMock = {
1414

1515
const { updateContact } = proxyquire.noCallThru().load('./updateContact', {
1616
'./getAllowedCustomFields': {
17-
getAllowedCustomFields: sinon.stub(),
17+
getAllowedCustomFields: sinon.stub().resolves([]),
1818
},
1919
'./validateContactManager': {
2020
validateContactManager: sinon.stub(),

apps/meteor/app/livechat/server/lib/contacts/validateCustomFields.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('validateCustomFields', () => {
5555
const allowedCustomFields = [{ _id: 'field1', label: 'Field 1', required: false }];
5656
const customFields = { field2: 'value' };
5757

58-
expect(() => validateCustomFields(allowedCustomFields, customFields, { ignoreValidationErrors: true }))
58+
expect(() => validateCustomFields(allowedCustomFields, customFields, { ignoreAdditionalFields: true }))
5959
.not.to.throw()
6060
.and.to.equal({});
6161
});

0 commit comments

Comments
 (0)