|
|
|
|
@ -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; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|