Skip to content

Commit

Permalink
Node client notes and call logs API support[sc-55272]
Browse files Browse the repository at this point in the history
  • Loading branch information
SoeunSona committed Dec 11, 2023
1 parent 3512acd commit 7b30b2e
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/chartmogul.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const errors = require('./chartmogul/errors');
const Metrics = require('./chartmogul/metrics');

const Customer = require('./chartmogul/customer');
const CustomerNote = require('./chartmogul/customer-note');
const Contact = require('./chartmogul/contact');
const DataSource = require('./chartmogul/data-source');
const Plan = require('./chartmogul/plan');
Expand All @@ -30,6 +31,7 @@ const ChartMogul = {
Config,
CustomAttribute,
Customer,
CustomerNote,
Contact,
DataSource,
Enrichment,
Expand Down
11 changes: 11 additions & 0 deletions lib/chartmogul/customer-note.js
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;
10 changes: 10 additions & 0 deletions lib/chartmogul/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class Customer extends Resource {
const path = util.expandPath(this.path, [customerId, 'contacts']);
return Resource.request(config, 'POST', path, params, callback);
}

static notes (config, customerId, params, callback) {
const path = util.expandPath(this.path, [customerId, 'notes']);
return Resource.request(config, 'GET', path, params, callback);
}

static createrNote (config, customerId, params, callback) {
const path = util.expandPath(this.path, [customerId, 'notes']);
return Resource.request(config, 'POST', path, params, callback);
}
}

// @Override
Expand Down
100 changes: 100 additions & 0 deletions test/chartmogul/customer-note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
'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 new note', () => {
const postBody = {
/* eslint-disable camelcase */
customer_uuid: 'cus_919d5d7c-9e23-11ed-a936-97fbf69ba02b',
type: 'note',
text: 'This is a note',
auther_email: '[email protected]'
/* eslint-enable camelcase */
};

nock(config.API_BASE)
.post('/v1/customer_notes', postBody)
.reply(200, {
/* eslint-disable camelcase */
uuid: 'note_00000000-0000-0000-0000-000000000000',
customer_uuid: 'cus_919d5d7c-9e23-11ed-a936-97fbf69ba02b',
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.create(config, postBody)
.then(res => {
expect(res).to.have.property('uuid');
});
});

it('retrieves a customer note', () => {
const uuid = 'note_00000000-0000-0000-0000-000000000000';

nock(config.API_BASE)
.get('/v1/customer_notes' + '/' + uuid)
.reply(200, {
/* eslint-disable camelcase */
uuid: 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.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: 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({});
});
});
});
56 changes: 56 additions & 0 deletions test/chartmogul/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,62 @@ 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 = {
type: 'note',
author_email: '[email protected]',
note: 'This is a note'
};

nock(config.API_BASE)
.post(`/v1/customers/${customerUuid}/notes`, postBody)
.reply(200, {
/* eslint-disable camelcase */
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'
/* eslint-enable camelcase */
});

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/customers/${customerUuid}/notes`)
.reply(200, {
/* eslint-disable camelcase */
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'
}]
/* eslint-enable camelcase */
});

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.
Expand Down

0 comments on commit 7b30b2e

Please sign in to comment.