|
| 1 | +import assert from 'assert'; |
| 2 | +import {Client} from '../lib'; |
| 3 | +var nock = require('nock'); |
| 4 | + |
| 5 | +describe('contacts', function () { |
| 6 | + it('should be created', function (done) { |
| 7 | + nock('https://api.intercom.io').post('/contacts').reply(200, {}); |
| 8 | + let client = new Client('foo', 'bar'); |
| 9 | + client.contacts.create(function (r) { |
| 10 | + assert.equal(200, r.status); |
| 11 | + done(); |
| 12 | + }); |
| 13 | + }); |
| 14 | + it('should be updated', function (done) { |
| 15 | + nock('https://api.intercom.io').post('/contacts/baz', { email: '[email protected]' }).reply(200, {}); |
| 16 | + let client = new Client('foo', 'bar'); |
| 17 | + client.contacts.update({ id: 'baz', email: '[email protected]' }, function (r) { |
| 18 | + assert.equal(200, r.status); |
| 19 | + done(); |
| 20 | + }); |
| 21 | + }); |
| 22 | + it('should list', function (done) { |
| 23 | + nock('https://api.intercom.io').get('/contacts').reply(200, {}); |
| 24 | + let client = new Client('foo', 'bar'); |
| 25 | + client.contacts.list(function (r) { |
| 26 | + assert.equal(200, r.status); |
| 27 | + done(); |
| 28 | + }); |
| 29 | + }); |
| 30 | + it('should list by params', function (done) { |
| 31 | + nock('https://api.intercom.io').get('/contacts').query({ email: '[email protected]' }).reply(200, {}); |
| 32 | + let client = new Client('foo', 'bar'); |
| 33 | + client.contacts.listBy({ email: '[email protected]' }, function (r) { |
| 34 | + assert.equal(200, r.status); |
| 35 | + done(); |
| 36 | + }); |
| 37 | + }); |
| 38 | + it('should find by id', function (done) { |
| 39 | + nock('https://api.intercom.io').get('/contacts/baz').reply(200, {}); |
| 40 | + let client = new Client('foo', 'bar'); |
| 41 | + client.contacts.find({ id: 'baz' }, function (r) { |
| 42 | + assert.equal(200, r.status); |
| 43 | + done(); |
| 44 | + }); |
| 45 | + }); |
| 46 | + it('delete by id', function (done) { |
| 47 | + nock('https://api.intercom.io').delete('/contacts/baz').reply(200, {}); |
| 48 | + let client = new Client('foo', 'bar'); |
| 49 | + client.contacts.delete({ id: 'baz' }, function (r) { |
| 50 | + assert.equal(200, r.status); |
| 51 | + done(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + it('should convert', function (done) { |
| 55 | + let conversionObject = { |
| 56 | + contact: { user_id: 'baz' }, |
| 57 | + user: { email: 'bang' } |
| 58 | + }; |
| 59 | + nock('https://api.intercom.io').post('/contacts/convert', conversionObject).reply(200, {}); |
| 60 | + let client = new Client('foo', 'bar'); |
| 61 | + client.contacts.convert(conversionObject, function (r) { |
| 62 | + assert.equal(200, r.status); |
| 63 | + done(); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments