Skip to content

Commit a70d290

Browse files
authored
Merge pull request #162 from intercom/em0ney-feature/deeper-company-queries
Em0ney feature/deeper company queries Adding extra options to find companies and list users
2 parents d66f279 + 7f60ff5 commit a70d290

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

lib/company.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@ export default class Company {
1818
return this.client.get('/companies', params, f);
1919
}
2020
find(params, f) {
21-
return this.client.get(`/companies/${params.id}`, {}, f);
21+
if (params.id) {
22+
return this.client.get(`/companies/${params.id}`, {}, f);
23+
} else if (params.company_id) {
24+
return this.client.get('/companies', { company_id: params.company_id }, f);
25+
} else if (params.name) {
26+
return this.client.get('/companies', { name: params.name }, f);
27+
}
2228
}
2329
listUsers(params, f) {
2430
if (params.id) {
2531
return this.client.get(`/companies/${params.id}/users`, {}, f);
2632
} else if (params.company_id) {
27-
return this.client.get(`/companies`, {type: 'user', company_id: params.company_id}, f);
33+
return this.client.get('/companies', { company_id: params.company_id, type: 'user' }, f);
34+
} else if (params.name) {
35+
return this.client.get('/companies', { name: params.name, type: 'user' }, f);
2836
}
2937
}
3038
}

test/company.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,52 @@ describe('companies', () => {
2727
done();
2828
});
2929
});
30-
it('find companies by id', done => {
30+
it('should find companies by id', done => {
3131
nock('https://api.intercom.io').get('/companies/baz').reply(200, {});
3232
const client = new Client('foo', 'bar').usePromises();
3333
client.companies.find({ id: 'baz' }).then(r => {
3434
assert.equal(200, r.status);
3535
done();
3636
});
3737
});
38-
it('list company users by id', done => {
38+
it('should find companies by company_id', done => {
39+
nock('https://api.intercom.io').get('/companies').query({ company_id: 'baz' }).reply(200, {});
40+
const client = new Client('foo', 'bar').usePromises();
41+
client.companies.find({ company_id: 'baz' }).then(r => {
42+
assert.equal(200, r.status);
43+
done();
44+
});
45+
});
46+
it('should find companies by name', done => {
47+
nock('https://api.intercom.io').get('/companies').query({ name: 'baz' }).reply(200, {});
48+
const client = new Client('foo', 'bar').usePromises();
49+
client.companies.find({ name: 'baz' }).then(r => {
50+
assert.equal(200, r.status);
51+
done();
52+
});
53+
});
54+
it('should list company users by id', done => {
3955
nock('https://api.intercom.io').get('/companies/baz/users').reply(200, {});
4056
const client = new Client('foo', 'bar').usePromises();
4157
client.companies.listUsers({ id: 'baz' }).then(r => {
4258
assert.equal(200, r.status);
4359
done();
4460
});
4561
});
46-
it('list company users by company_id', done => {
47-
nock('https://api.intercom.io').get('/companies').query({type: 'user', company_id: 'baz'}).reply(200, {});
62+
it('should list company users by company_id', done => {
63+
nock('https://api.intercom.io').get('/companies').query({ company_id: 'baz', type: 'user' }).reply(200, {});
4864
const client = new Client('foo', 'bar').usePromises();
4965
client.companies.listUsers({ company_id: 'baz' }).then(r => {
5066
assert.equal(200, r.status);
5167
done();
5268
});
5369
});
70+
it('should list company users by company name', done => {
71+
nock('https://api.intercom.io').get('/companies').query({ name: 'baz', type: 'user' }).reply(200, {});
72+
const client = new Client('foo', 'bar').usePromises();
73+
client.companies.listUsers({ name: 'baz' }).then(r => {
74+
assert.equal(200, r.status);
75+
done();
76+
});
77+
});
5478
});

0 commit comments

Comments
 (0)