diff --git a/src/Organizations/OrganizationDetails/OrganizationDetails.test.js b/src/Organizations/OrganizationDetails/OrganizationDetails.test.js index 3618f90f..5d907ea9 100644 --- a/src/Organizations/OrganizationDetails/OrganizationDetails.test.js +++ b/src/Organizations/OrganizationDetails/OrganizationDetails.test.js @@ -13,6 +13,7 @@ import OrganizationDetails from './OrganizationDetails'; jest.mock('@folio/stripes-acq-components', () => ({ ...jest.requireActual('@folio/stripes-acq-components'), useAcqRestrictions: jest.fn().mockReturnValue({ restrictions: {} }), + PrivilegedDonorsListContainer: jest.fn(() => 'PrivilegedDonorsListContainer'), TagsPane: jest.fn(() => 'TagsPane'), })); jest.mock('@folio/stripes-smart-components/lib/Notes/NotesSmartAccordion', () => () => 'NotesSmartAccordion'); diff --git a/src/contacts/EditContact/util.test.js b/src/contacts/EditContact/util.test.js index afffcc4b..d3eeb1a9 100644 --- a/src/contacts/EditContact/util.test.js +++ b/src/contacts/EditContact/util.test.js @@ -1,60 +1,56 @@ import { saveContact } from './util'; +const contactId = 'contactId'; +const contact = { name: 'Mark' }; +const contactWithId = { id: contactId, name: 'Mark' }; +const org = { id: 'org1', name: 'Amazon', contacts: [] }; + +const contactMutator = { + contact: { + POST: jest.fn().mockReturnValue(Promise.resolve({ ...contact, id: contactId })), + PUT: jest.fn().mockReturnValue(Promise.resolve()), + }, + privilegedContact: { + PUT: jest.fn().mockReturnValue(Promise.resolve()), + POST: jest.fn().mockReturnValue(Promise.resolve({ ...contact, id: contactId })), + }, + contactsOrg: { + PUT: jest.fn().mockReturnValue(Promise.resolve()), + }, +}; + describe('EditContact utils', () => { it('should create contact when contact without id', async () => { - const contact = { name: 'Mark' }; - const mutator = { - contact: { - POST: jest.fn().mockReturnValue(Promise.resolve()), - }, - }; - - await saveContact(mutator, contact); + await saveContact(contactMutator, contact); - expect(mutator.contact.POST).toHaveBeenCalledWith(contact); + expect(contactMutator.contact.POST).toHaveBeenCalledWith(contact); }); it('should update contact when contact with id', async () => { - const contact = { id: 'contactId', name: 'Mark' }; - const mutator = { - contact: { - PUT: jest.fn().mockReturnValue(Promise.resolve()), - }, - }; + await saveContact(contactMutator, contactWithId); - await saveContact(mutator, contact); - - expect(mutator.contact.PUT).toHaveBeenCalledWith(contact); + expect(contactMutator.contact.PUT).toHaveBeenCalledWith(contactWithId); }); it('should assign contact to org when contact is saved successfully and org is provided', async () => { - const contactId = 'contactId'; - const contact = { name: 'Mark' }; - const org = { id: 'org1', name: 'Amazon', contacts: [] }; - const mutator = { - contact: { - POST: jest.fn().mockReturnValue(Promise.resolve({ ...contact, id: contactId })), - }, - contactsOrg: { - PUT: jest.fn().mockReturnValue(Promise.resolve()), - }, - }; - - await saveContact(mutator, contact, org); - - expect(mutator.contactsOrg.PUT).toHaveBeenCalledWith({ ...org, contacts: [contactId] }); + await saveContact(contactMutator, contact, org); + + expect(contactMutator.contactsOrg.PUT).toHaveBeenCalledWith({ ...org, contacts: [contactId] }); + }); + + it('should create privileged contact', async () => { + const isPrivilegedContactUrl = true; + + await saveContact(contactMutator, contact, org, isPrivilegedContactUrl); + + expect(contactMutator.privilegedContact.POST).toHaveBeenCalledWith(contact); }); it('should update privileged contact when with id', async () => { - const contact = { id: 'contactId', name: 'Mark' }; - const mutator = { - privilegedContact: { - PUT: jest.fn().mockReturnValue(Promise.resolve()), - }, - }; + const isPrivilegedContactUrl = true; - await saveContact(mutator, contact); + await saveContact(contactMutator, contactWithId, org, isPrivilegedContactUrl); - expect(mutator.contact.PUT).toHaveBeenCalledWith(contact); + expect(contactMutator.privilegedContact.PUT).toHaveBeenCalledWith(contactWithId); }); }); diff --git a/src/contacts/ViewContact/ViewContact.test.js b/src/contacts/ViewContact/ViewContact.test.js index 47ac288c..c3d93874 100644 --- a/src/contacts/ViewContact/ViewContact.test.js +++ b/src/contacts/ViewContact/ViewContact.test.js @@ -24,6 +24,7 @@ jest.mock('@folio/stripes-components/lib/Commander', () => ({ collapseAllSections: jest.fn(), })); +const pushMock = jest.fn(); const defaultProps = { categories: [{ value: 'Customer Service', id: 'f52ceea4-8e35' }], contact, @@ -40,6 +41,12 @@ const renderViewContact = (props = defaultProps) => render( describe('ViewContact', () => { beforeEach(() => { global.document.createRange = global.document.originalCreateRange; + useHistory.mockClear().mockReturnValue({ + push: pushMock, + location: { + pathname: '/contacts/view/123', + }, + }); }); afterEach(() => { @@ -106,12 +113,6 @@ describe('ViewContact', () => { }); it('should navigate to edit view when edit shortcut is called', () => { - const pushMock = jest.fn(); - - useHistory.mockClear().mockReturnValue({ - push: pushMock, - }); - renderViewContact(); HasCommand.mock.calls[0][0].commands.find(c => c.name === 'edit').handler(); @@ -119,12 +120,6 @@ describe('ViewContact', () => { }); it('should navigate to list view when search shortcut is called', () => { - const pushMock = jest.fn(); - - useHistory.mockClear().mockReturnValue({ - push: pushMock, - }); - renderViewContact(); HasCommand.mock.calls[0][0].commands.find(c => c.name === 'search').handler();