test: Fix ignored unit tests (#39530)

Co-authored-by: Kevin Aleman <kaleman960@gmail.com>
pull/39534/head
dionisio-bot[bot] 2 months ago committed by GitHub
parent 2323a7b1d1
commit b74fa1139d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      apps/meteor/.mocharc.js
  2. 18
      apps/meteor/app/livechat/server/lib/contacts/mapVisitorToContact.spec.ts
  3. 74
      apps/meteor/app/livechat/server/lib/contacts/resolveContactConflicts.spec.ts
  4. 2
      apps/meteor/app/livechat/server/lib/contacts/updateContact.spec.ts
  5. 2
      apps/meteor/app/livechat/server/lib/contacts/validateCustomFields.spec.ts

@ -43,6 +43,5 @@ module.exports = {
'app/file-upload/server/**/*.spec.ts',
'app/statistics/server/**/*.spec.ts',
'app/livechat/server/lib/**/*.spec.ts',
'app/utils/server/**/*.spec.ts',
],
};

@ -27,6 +27,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
contactManager: {
username: 'user1',
},
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
{
type: OmnichannelSourceType.WIDGET,
@ -50,8 +51,10 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
details: {
type: OmnichannelSourceType.WIDGET,
},
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
],
lastChat: { _id: 'afdsfdasf', ts: testDate },
customFields: undefined,
shouldValidateCustomFields: false,
contactManager: 'manager1',
@ -62,6 +65,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
{
_id: 'visitor1',
username: 'Username',
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
{
type: OmnichannelSourceType.SMS,
@ -85,11 +89,13 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
details: {
type: OmnichannelSourceType.SMS,
},
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
],
customFields: undefined,
shouldValidateCustomFields: false,
contactManager: undefined,
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
],
@ -113,7 +119,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
unknown: false,
channels: [
{
name: 'sms',
name: 'widget',
visitor: {
visitorId: 'visitor1',
source: {
@ -150,6 +156,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
invalidCustomFieldId: 'invalidCustomFieldValue',
},
activity: [],
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
{
type: OmnichannelSourceType.WIDGET,
@ -161,7 +168,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
unknown: true,
channels: [
{
name: 'sms',
name: 'widget',
visitor: {
visitorId: 'visitor1',
source: {
@ -173,6 +180,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
details: {
type: OmnichannelSourceType.WIDGET,
},
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
],
customFields: {
@ -180,6 +188,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
},
shouldValidateCustomFields: false,
contactManager: undefined,
lastChat: { _id: 'afdsfdasf', ts: testDate },
},
],
];
@ -197,10 +206,9 @@ describe('mapVisitorToContact', () => {
getAllowedCustomFields.resolves([{ _id: 'customFieldId', label: 'custom-field-label' }]);
});
const index = 0;
for (const [visitor, source, contact] of dataMap) {
dataMap.forEach(([visitor, source, contact], index) => {
it(`should map an ILivechatVisitor + IOmnichannelSource to an ILivechatContact [${index}]`, async () => {
expect(await mapVisitorToContact(visitor, source)).to.be.deep.equal(contact);
});
}
});
});

@ -36,25 +36,14 @@ describe('resolveContactConflicts', () => {
conflictingFields: [{ field: 'customFields.customField', value: 'oldValue' }],
});
modelsMock.Settings.incrementValueById.resolves(1);
modelsMock.LivechatContacts.updateContact.resolves({
_id: 'contactId',
customField: { customField: 'newValue' },
conflictingFields: [{ field: 'customFields.customField', value: 'oldValue' }],
} as Partial<ILivechatContact>);
const result = await resolveContactConflicts({ contactId: 'contactId', customField: { customField: 'newValue' } });
await resolveContactConflicts({ contactId: 'contactId', customFields: { customField: 'newestValue' } });
expect(modelsMock.LivechatContacts.findOneEnabledById.getCall(0).args[0]).to.be.equal('contactId');
expect(modelsMock.Settings.incrementValueById.getCall(0).args[0]).to.be.equal('Livechat_conflicting_fields_counter');
expect(modelsMock.Settings.incrementValueById.getCall(0).args[1]).to.be.equal(1);
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[0]).to.be.equal('contactId');
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({ customFields: { customField: 'newValue' } });
expect(result).to.be.deep.equal({
_id: 'contactId',
customField: { customField: 'newValue' },
conflictingFields: [],
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({
customFields: { customField: 'newestValue' },
});
});
@ -66,28 +55,13 @@ describe('resolveContactConflicts', () => {
conflictingFields: [{ field: 'name', value: 'Old Name' }],
});
modelsMock.Settings.incrementValueById.resolves(1);
modelsMock.LivechatContacts.updateContact.resolves({
_id: 'contactId',
name: 'New Name',
customField: { customField: 'newValue' },
conflictingFields: [],
} as Partial<ILivechatContact>);
const result = await resolveContactConflicts({ contactId: 'contactId', name: 'New Name' });
await resolveContactConflicts({ contactId: 'contactId', name: 'New Name' });
expect(modelsMock.LivechatContacts.findOneEnabledById.getCall(0).args[0]).to.be.equal('contactId');
expect(modelsMock.Settings.incrementValueById.getCall(0).args[0]).to.be.equal('Livechat_conflicting_fields_counter');
expect(modelsMock.Settings.incrementValueById.getCall(0).args[1]).to.be.equal(1);
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[0]).to.be.equal('contactId');
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({ name: 'New Name' });
expect(result).to.be.deep.equal({
_id: 'contactId',
name: 'New Name',
customField: { customField: 'newValue' },
conflictingFields: [],
});
});
it('should update the contact with the resolved contact manager', async () => {
@ -96,31 +70,16 @@ describe('resolveContactConflicts', () => {
name: 'Name',
contactManager: 'contactManagerId',
customFields: { customField: 'value' },
conflictingFields: [{ field: 'manager', value: 'newContactManagerId' }],
conflictingFields: [{ field: 'manager', value: 'oldManagerId' }],
});
modelsMock.Settings.incrementValueById.resolves(1);
modelsMock.LivechatContacts.updateContact.resolves({
_id: 'contactId',
name: 'Name',
contactManager: 'newContactManagerId',
customField: { customField: 'value' },
conflictingFields: [],
} as Partial<ILivechatContact>);
const result = await resolveContactConflicts({ contactId: 'contactId', name: 'New Name' });
await resolveContactConflicts({ contactId: 'contactId', name: 'New Name', customFields: { manager: 'newContactManagerId' } });
expect(modelsMock.LivechatContacts.findOneEnabledById.getCall(0).args[0]).to.be.equal('contactId');
expect(modelsMock.Settings.incrementValueById.getCall(0).args[0]).to.be.equal('Livechat_conflicting_fields_counter');
expect(modelsMock.Settings.incrementValueById.getCall(0).args[1]).to.be.equal(1);
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[0]).to.be.equal('contactId');
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({ contactManager: 'newContactManagerId' });
expect(result).to.be.deep.equal({
_id: 'contactId',
name: 'New Name',
customField: { customField: 'newValue' },
conflictingFields: [],
expect(modelsMock.LivechatContacts.updateContact.getCall(0).args[1]).to.be.deep.contain({
customFields: { customField: 'value', manager: 'newContactManagerId' },
});
});
@ -219,21 +178,4 @@ describe('resolveContactConflicts', () => {
);
expect(modelsMock.LivechatContacts.updateContact.getCall(0)).to.be.null;
});
it('should throw an error if the contact manager is invalid', async () => {
modelsMock.LivechatContacts.findOneEnabledById.resolves({
_id: 'contactId',
name: 'Name',
contactManager: 'contactManagerId',
customFields: { customField: 'value' },
conflictingFields: [{ field: 'manager', value: 'newContactManagerId' }],
});
await expect(resolveContactConflicts({ contactId: 'id', contactManager: 'invalid' })).to.be.rejectedWith(
'error-contact-manager-not-found',
);
expect(validateContactManagerMock.getCall(0).args[0]).to.be.equal('invalid');
expect(modelsMock.LivechatContacts.updateContact.getCall(0)).to.be.null;
});
});

@ -14,7 +14,7 @@ const modelsMock = {
const { updateContact } = proxyquire.noCallThru().load('./updateContact', {
'./getAllowedCustomFields': {
getAllowedCustomFields: sinon.stub(),
getAllowedCustomFields: sinon.stub().resolves([]),
},
'./validateContactManager': {
validateContactManager: sinon.stub(),

@ -55,7 +55,7 @@ describe('validateCustomFields', () => {
const allowedCustomFields = [{ _id: 'field1', label: 'Field 1', required: false }];
const customFields = { field2: 'value' };
expect(() => validateCustomFields(allowedCustomFields, customFields, { ignoreValidationErrors: true }))
expect(() => validateCustomFields(allowedCustomFields, customFields, { ignoreAdditionalFields: true }))
.not.to.throw()
.and.to.equal({});
});

Loading…
Cancel
Save