forked from intercom/intercom-node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisitor.js
63 lines (62 loc) · 2.19 KB
/
visitor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import assert from 'assert';
import {Client} from '../lib';
import nock from 'nock';
describe('visitors', () => {
it('should be updated', done => {
nock('https://api.intercom.io').post('/visitors', { id: 'baz', email: '[email protected]' }).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.visitors.update({ id: 'baz', email: '[email protected]' }).then(r => {
assert.equal(200, r.statusCode);
done();
});
});
it('should find by user_id', done => {
nock('https://api.intercom.io').get('/visitors').query({ user_id: '1234-5678-9876' }).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.visitors.find({ user_id: '1234-5678-9876' }).then(r => {
assert.equal(200, r.statusCode);
done();
});
});
it('should find by id', done => {
nock('https://api.intercom.io').get('/visitors/baz').reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.visitors.find({ id: 'baz' }).then(r => {
assert.equal(200, r.statusCode);
done();
});
});
it('delete by id', done => {
nock('https://api.intercom.io').delete('/visitors/baz').reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.visitors.delete({ id: 'baz' }).then(r => {
assert.equal(200, r.statusCode);
done();
});
});
it('should convert to user', done => {
const conversionObject = {
visitor: { user_id: 'baz' },
user: { email: 'bang' },
type: 'user'
};
nock('https://api.intercom.io').post('/visitors/convert', conversionObject).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.visitors.convert(conversionObject).then(r => {
assert.equal(200, r.statusCode);
done();
});
});
it('should convert to lead', done => {
const conversionObject = {
visitor: { user_id: 'baz' },
type: 'lead'
};
nock('https://api.intercom.io').post('/visitors/convert', conversionObject).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.visitors.convert(conversionObject).then(r => {
assert.equal(200, r.statusCode);
done();
});
});
});