-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node client notes and call logs API support[sc-55272] (#85)
* Node client notes and call logs API support[sc-55272] https://app.shortcut.com/chartmogul/story/55272/node-client-notes-and-call-logs-api-support
- Loading branch information
Showing
6 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const Resource = require('./resource'); | ||
|
||
class CustomerNote extends Resource { | ||
static get path () { | ||
return '/v1/customer_notes{/noteUuid}'; | ||
} | ||
} | ||
|
||
module.exports = CustomerNote; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
'use strict'; | ||
|
||
const ChartMogul = require('../../lib/chartmogul'); | ||
const config = new ChartMogul.Config('token'); | ||
const expect = require('chai').expect; | ||
const nock = require('nock'); | ||
const CustomerNote = ChartMogul.CustomerNote; | ||
|
||
describe('CustomerNote', () => { | ||
it('creates a note from a customer', () => { | ||
const uuid = 'cus_00000000-0000-0000-0000-000000000000'; | ||
const postBody = { | ||
customer_uuid: uuid, | ||
type: 'note', | ||
text: 'This is a note' | ||
}; | ||
|
||
nock(config.API_BASE) | ||
.post('/v1/customer_notes', postBody) | ||
.reply(200, { | ||
uuid: 'note_00000000-0000-0000-0000-000000000000', | ||
customer_uuid: uuid, | ||
type: 'note', | ||
text: 'This is a note', | ||
created_at: '2021-10-20T14:00:00.000Z', | ||
updated_at: '2021-10-20T14:00:00.000Z', | ||
author: 'John Doe ([email protected])' | ||
}); | ||
|
||
CustomerNote.create(config, postBody) | ||
.then(res => { | ||
expect(res.customer_uuid).to.be.equal(uuid); | ||
expect(res.text).to.be.equal('This is a note'); | ||
}); | ||
}); | ||
|
||
it('lists all notes from a customer', () => { | ||
const uuid = 'cus_00000000-0000-0000-0000-000000000000'; | ||
|
||
nock(config.API_BASE) | ||
.get('/v1/customer_notes') | ||
.reply(200, { | ||
entries: [{ | ||
uuid: 'note_00000000-0000-0000-0000-000000000000', | ||
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', | ||
author: 'John Doe ([email protected])', | ||
text: 'This is a note', | ||
created_at: '2015-01-01T12:00:00-05:00', | ||
updated_at: '2015-01-01T12:00:00-05:00', | ||
type: 'note' | ||
}] | ||
}); | ||
|
||
CustomerNote.all(config, uuid) | ||
.then(res => { | ||
expect(res.entries).to.haveLength(1); | ||
}); | ||
}); | ||
|
||
it('retrieves a customer note', () => { | ||
const uuid = 'note_00000000-0000-0000-0000-000000000000'; | ||
|
||
nock(config.API_BASE) | ||
.get(`/v1/customer_notes/${uuid}`) | ||
.reply(200, { | ||
uuid, | ||
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', | ||
type: 'note', | ||
text: 'This is a note', | ||
created_at: '2021-10-20T14:00:00.000Z', | ||
updated_at: '2021-10-20T14:00:00.000Z', | ||
author: 'John Doe ([email protected])' | ||
}); | ||
|
||
CustomerNote.retrieve(config, uuid).then(res => { | ||
expect(res).to.have.property('uuid'); | ||
}); | ||
}); | ||
|
||
it('updates a customer note', () => { | ||
const uuid = 'note_00000000-0000-0000-0000-000000000000'; | ||
const postBody = { | ||
text: 'This is a note' | ||
}; | ||
|
||
nock(config.API_BASE) | ||
.patch(`/v1/customer_notes/${uuid}`, postBody) | ||
.reply(200, { | ||
/* eslint-disable camelcase */ | ||
uuid, | ||
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', | ||
type: 'note', | ||
text: 'This is a note', | ||
created_at: '2021-10-20T14:00:00.000Z', | ||
updated_at: '2021-10-20T14:00:00.000Z', | ||
author: 'John Doe ([email protected])' | ||
/* eslint-enable camelcase */ | ||
}); | ||
|
||
CustomerNote.patch(config, uuid, postBody) | ||
.then(res => { | ||
expect(res.text).to.be.equal('This is a note'); | ||
}); | ||
}); | ||
|
||
it('deletes a customer note', () => { | ||
const uuid = 'con_00000000-0000-0000-0000-000000000000'; | ||
|
||
nock(config.API_BASE) | ||
.delete(`/v1/customer_notes/${uuid}`) | ||
.reply(204); | ||
|
||
CustomerNote.destroy(config, uuid) | ||
.then(res => { | ||
expect(res).to.be.equal({}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,59 @@ describe('Customer', () => { | |
expect(res.has_more).to.eql(false); | ||
}); | ||
}); | ||
|
||
it('creates a new note from a customer', () => { | ||
const customerUuid = 'cus_00000000-0000-0000-0000-000000000000'; | ||
const postBody = { | ||
customer_uuid: customerUuid, | ||
type: 'note', | ||
author_email: '[email protected]', | ||
note: 'This is a note' | ||
}; | ||
|
||
nock(config.API_BASE) | ||
.post('/v1/customer_notes', postBody) | ||
.reply(200, { | ||
uuid: 'note_00000000-0000-0000-0000-000000000000', | ||
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', | ||
author: 'John Doe ([email protected])', | ||
text: 'This is a note', | ||
created_at: '2015-01-01T12:00:00-05:00', | ||
updated_at: '2015-01-01T12:00:00-05:00', | ||
type: 'note' | ||
}); | ||
|
||
Customer.createrNote(config, customerUuid, postBody) | ||
.then(res => { | ||
expect(res).to.have.property('uuid'); | ||
}); | ||
}); | ||
|
||
it('gets all notes from a customer', () => { | ||
const customerUuid = 'cus_00000000-0000-0000-0000-000000000000'; | ||
|
||
nock(config.API_BASE) | ||
.get(`/v1/customer_notes?customer_uuid=${customerUuid}`) | ||
.reply(200, { | ||
entries: [{ | ||
uuid: 'note_00000000-0000-0000-0000-000000000000', | ||
customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', | ||
author: 'John Doe ([email protected])', | ||
text: 'This is a note', | ||
created_at: '2015-01-01T12:00:00-05:00', | ||
updated_at: '2015-01-01T12:00:00-05:00', | ||
type: 'note' | ||
}] | ||
}); | ||
|
||
Customer.notes(config, customerUuid) | ||
.then(res => { | ||
expect(res).to.have.property('entries'); | ||
expect(res.entries).to.be.instanceof(Array); | ||
expect(res.cursor).to.eql('MjAyMy0wMy0xM1QxMjowMTozMi44MD=='); | ||
expect(res.has_more).to.eql(false); | ||
}); | ||
}); | ||
}); | ||
|
||
/** Suite that originally belonged in the Enrichment module. | ||
|