From e1f1b654baff137b9201239a2ae5fe428acd2b36 Mon Sep 17 00:00:00 2001 From: SoeunSona <78331453+SoeunSona@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:43:59 +0100 Subject: [PATCH] Change specs --- README.md | 15 +++++++ lib/chartmogul/customer.js | 9 ++-- test/chartmogul/customer-note.js | 70 +++++++++++++++++++++++++++----- test/chartmogul/customer.js | 11 ++--- 4 files changed, 83 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 7fa5b28..9a50ce3 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ ChartMogul.Customer.merge(config, { ChartMogul.Customer.contacts(config, customerUuid, { per_page: 10, cursor: 'cursor==' }) ChartMogul.Customer.createContact(config, customerUuid, data) + +ChartMogul.Customer.notes(config, customerUuid, { per_page: 10, cursor: 'cursor==' }) +ChartMogul.Customer.createNote(config, customerUuid, data) ``` #### [Contacts](https://dev.chartmogul.com/docs/contacts) @@ -137,6 +140,18 @@ ChartMogul.Contact.all(config, { per_page: 10, cursor: 'cursor==' }) ``` +#### [Customer Notes](https://dev.chartmogul.com/docs/customer_notes) + +```js +ChartMogul.CustomerNote.create(config, data) +ChartMogul.CustomerNote.retrieve(config) +ChartMogul.CustomerNote.patch(config) +ChartMogul.CustomerNote.destroy(config) +ChartMogul.CustomerNote.all(config, { per_page: 10, cursor: 'cursor==', customer_uuid: customerUuid}) + +``` + + #### [Plans](https://dev.chartmogul.com/docs/plans) ```js diff --git a/lib/chartmogul/customer.js b/lib/chartmogul/customer.js index 39bcfbf..d83a50c 100644 --- a/lib/chartmogul/customer.js +++ b/lib/chartmogul/customer.js @@ -2,6 +2,7 @@ const Resource = require('./resource'); const util = require('./util'); +const CustomerNote = require('./customer-note'); class Customer extends Resource { static get path () { @@ -29,13 +30,13 @@ class Customer extends Resource { } static notes (config, customerId, params, callback) { - const path = util.expandPath(this.path, [customerId, 'notes']); - return Resource.request(config, 'GET', path, params, callback); + const path = util.expandPath(CustomerNote.path, []); + return Resource.request(config, 'GET', path, { ...params, customerId }, callback); } static createrNote (config, customerId, params, callback) { - const path = util.expandPath(this.path, [customerId, 'notes']); - return Resource.request(config, 'POST', path, params, callback); + const path = util.expandPath(CustomerNote.path, []); + return Resource.request(config, 'POST', path, { ...params, customerId }, callback); } } diff --git a/test/chartmogul/customer-note.js b/test/chartmogul/customer-note.js index 7579104..f9c562a 100644 --- a/test/chartmogul/customer-note.js +++ b/test/chartmogul/customer-note.js @@ -7,26 +7,74 @@ const nock = require('nock'); const CustomerNote = ChartMogul.CustomerNote; describe('CustomerNote', () => { + it('create a customer note', () => { + 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 (john@example.com)' + }); + + 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 customer notes', () => { + 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 (john@example.com)', + 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, { - /* eslint-disable camelcase */ - uuid: 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 (john@example.com)' - /* eslint-enable camelcase */ }); - CustomerNote.retrieve(config, uuid).then(res => { - expect(res).to.have.property('uuid'); - }); + CustomerNote.retrieve(config, uuid).then(res => { + expect(res).to.have.property('uuid'); + }); }); it('updates a customer note', () => { @@ -39,7 +87,7 @@ describe('CustomerNote', () => { .patch('/v1/customer_notes' + '/' + uuid, postBody) .reply(200, { /* eslint-disable camelcase */ - uuid: uuid, + uuid, customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', type: 'note', text: 'This is a note', @@ -49,10 +97,10 @@ describe('CustomerNote', () => { /* eslint-enable camelcase */ }); - CustomerNote.patch(config, uuid, postBody) - .then(res => { - expect(res['text']).to.be.equal('This is a note'); - }); + CustomerNote.patch(config, uuid, postBody) + .then(res => { + expect(res.text).to.be.equal('This is a note'); + }); }); it('deletes a customer note', () => { diff --git a/test/chartmogul/customer.js b/test/chartmogul/customer.js index 6dd9d2e..8a015da 100644 --- a/test/chartmogul/customer.js +++ b/test/chartmogul/customer.js @@ -191,15 +191,15 @@ describe('Customer', () => { 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: 'john@example.com', note: 'This is a note' }; nock(config.API_BASE) - .post(`/v1/customers/${customerUuid}/notes`, postBody) + .post('/v1/customer_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 (john@example.com)', @@ -207,7 +207,6 @@ describe('Customer', () => { 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) @@ -220,9 +219,8 @@ describe('Customer', () => { const customerUuid = 'cus_00000000-0000-0000-0000-000000000000'; nock(config.API_BASE) - .get(`/v1/customers/${customerUuid}/notes`) + .get(`/v1/customer_notes?customer_uuid=${customerUuid}`) .reply(200, { - /* eslint-disable camelcase */ entries: [{ uuid: 'note_00000000-0000-0000-0000-000000000000', customer_uuid: 'cus_00000000-0000-0000-0000-000000000000', @@ -232,8 +230,7 @@ describe('Customer', () => { updated_at: '2015-01-01T12:00:00-05:00', type: 'note' }] - /* eslint-enable camelcase */ - }); + }); Customer.notes(config, customerUuid) .then(res => {