From d2e185a61dc4eff1ffa2d8cdd8e0aa239a683992 Mon Sep 17 00:00:00 2001 From: Andrii Selivanov Date: Sat, 8 Sep 2018 23:27:59 +0300 Subject: [PATCH] [tests] Added tests for contacts service. --- __tests__/src/services/contacts/index.js | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 __tests__/src/services/contacts/index.js diff --git a/__tests__/src/services/contacts/index.js b/__tests__/src/services/contacts/index.js new file mode 100644 index 00000000..9bb1edea --- /dev/null +++ b/__tests__/src/services/contacts/index.js @@ -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 }); +});