Skip to content

Commit

Permalink
[tests] Added tests for contacts service.
Browse files Browse the repository at this point in the history
  • Loading branch information
seland committed Sep 8, 2018
1 parent 38bb5a6 commit d2e185a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions __tests__/src/services/contacts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @flow

import ContactsService from '../../../../src/services/contacts';
import * as Panthalassa from '../../../../src/services/panthalassa';

const mockIdentityKey = 'MOCK_IDENTITY_KEY';
const mockIdentityKey2 = 'MOCK_IDENTITY_KEY_2';

// $FlowExpectedError
Panthalassa.panthalassaCall = jest.fn((command) => {
switch (command) {
case 'CONTACT:ALL':
return JSON.stringify({
contacts: [
{ identity_key: mockIdentityKey },
{ identity_key: mockIdentityKey2 },
],
});
default:
return null;
}
});

test('getContacts', async () => {
expect.assertions(1);

expect(await ContactsService.getContacts()).toEqual([
{ identity_key: mockIdentityKey },
{ identity_key: mockIdentityKey2 },
]);
});

test('addContact', async () => {
expect.assertions(2);

expect(await ContactsService.addContact(mockIdentityKey)).toEqual();
expect(Panthalassa.panthalassaCall).toBeCalledWith('CONTACT:CREATE', { identity_key: mockIdentityKey });
});

0 comments on commit d2e185a

Please sign in to comment.