Skip to content

Commit

Permalink
🧪 chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Jul 9, 2024
1 parent c2c7e4f commit 63e5329
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ describe('The active contacts service', () => {
const dbMock = {
get: jest.fn(),
insert: jest.fn(),
deleteEqual: jest.fn()
deleteEqual: jest.fn(),
update: jest.fn()
}

const loggerMock = {
Expand All @@ -22,6 +23,7 @@ describe('The active contacts service', () => {

it('should save active contacts for a user', async () => {
dbMock.insert.mockResolvedValue(undefined)
dbMock.get.mockResolvedValue([])

await expect(
activeContactsService.save('test', 'contact')
Expand All @@ -33,6 +35,22 @@ describe('The active contacts service', () => {
})
})

it('should update active contacts for a user if there are existing ones', async () => {
dbMock.get.mockResolvedValue([{ userId: 'test', contacts: 'test contact' }])
dbMock.update.mockResolvedValue(undefined)

await expect(
activeContactsService.save('test', 'contact')
).resolves.not.toThrow()

expect(dbMock.update).toHaveBeenCalledWith(
'activeContacts',
{ contacts: 'contact' },
'userId',
'test'
)
})

it('should fetch active contacts for a user', async () => {
dbMock.get.mockResolvedValue([{ userId: 'test', contacts: 'contact' }])

Expand Down

0 comments on commit 63e5329

Please sign in to comment.