Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ export default class Company {
return this.client.get('/companies', params, f);
}
find(params, f) {
return this.client.get(`/companies/${params.id}`, {}, f);
if (params.id) {
return this.client.get(`/companies/${params.id}`, {}, f);
} else if (params.company_id) {
return this.client.get('/companies', { company_id: params.company_id }, f);
} else if (params.name) {
return this.client.get('/companies', { name: params.name }, f);
}
}
listUsers(params, f) {
if (params.id) {
return this.client.get(`/companies/${params.id}/users`, {}, f);
} else if (params.company_id) {
return this.client.get(`/companies`, {type: 'user', company_id: params.company_id}, f);
return this.client.get('/companies', { company_id: params.company_id, type: 'user' }, f);
} else if (params.name) {
return this.client.get('/companies', { name: params.name, type: 'user' }, f);
}
}
}
32 changes: 28 additions & 4 deletions test/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,52 @@ describe('companies', () => {
done();
});
});
it('find companies by id', done => {
it('should find companies by id', done => {
nock('https://api.intercom.io').get('/companies/baz').reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.companies.find({ id: 'baz' }).then(r => {
assert.equal(200, r.status);
done();
});
});
it('list company users by id', done => {
it('should find companies by company_id', done => {
nock('https://api.intercom.io').get('/companies').query({ company_id: 'baz' }).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.companies.find({ company_id: 'baz' }).then(r => {
assert.equal(200, r.status);
done();
});
});
it('should find companies by name', done => {
nock('https://api.intercom.io').get('/companies').query({ name: 'baz' }).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.companies.find({ name: 'baz' }).then(r => {
assert.equal(200, r.status);
done();
});
});
it('should list company users by id', done => {
nock('https://api.intercom.io').get('/companies/baz/users').reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.companies.listUsers({ id: 'baz' }).then(r => {
assert.equal(200, r.status);
done();
});
});
it('list company users by company_id', done => {
nock('https://api.intercom.io').get('/companies').query({type: 'user', company_id: 'baz'}).reply(200, {});
it('should list company users by company_id', done => {
nock('https://api.intercom.io').get('/companies').query({ company_id: 'baz', type: 'user' }).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.companies.listUsers({ company_id: 'baz' }).then(r => {
assert.equal(200, r.status);
done();
});
});
it('should list company users by company name', done => {
nock('https://api.intercom.io').get('/companies').query({ name: 'baz', type: 'user' }).reply(200, {});
const client = new Client('foo', 'bar').usePromises();
client.companies.listUsers({ name: 'baz' }).then(r => {
assert.equal(200, r.status);
done();
});
});
});