-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d11d95b
commit 56027c1
Showing
3 changed files
with
45 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters