diff --git a/packages/mojatax/ast.json b/packages/mojatax/ast.json index 7ade7b611..05a8ff3d0 100644 --- a/packages/mojatax/ast.json +++ b/packages/mojatax/ast.json @@ -13,8 +13,8 @@ "tags": [ { "title": "example", - "description": "post(\"patient\", { \"name\":\"Bukayo\" });", - "caption": "Make a POST request create an invoice" + "description": "post(\"CreateInvoice\", {\ninvoice_id: 'PID092',\ncustomerId: '102',\nitems: [],\n});", + "caption": "Make a POST request to create an invoice" }, { "title": "function", @@ -75,7 +75,7 @@ }, { "title": "state", - "description": "{HttpState}" + "description": "{MojataxHttpState}" } ] }, @@ -95,8 +95,8 @@ "tags": [ { "title": "example", - "description": "request(\"POST\", \"patient\", { \"name\":\"Bukayo\" });", - "caption": "Make a POST request create an invoice" + "description": "request(\"POST\", \"/client/CreateInvoice\", {\ninvoice_id: 'PID092',\ncustomerId: '102',\nitems: [],\n});", + "caption": "Make a POST request to create an invoice" }, { "title": "function", @@ -166,7 +166,7 @@ }, { "title": "state", - "description": "{HttpState}" + "description": "{MojataxHttpState}" } ] }, diff --git a/packages/mojatax/src/Adaptor.js b/packages/mojatax/src/Adaptor.js index 7249080bf..4cb766f9a 100644 --- a/packages/mojatax/src/Adaptor.js +++ b/packages/mojatax/src/Adaptor.js @@ -58,26 +58,7 @@ export function execute(...operations) { * post("CreateInvoice", { * invoice_id: 'PID092', * customerId: '102', - * customerIdType: '6', - * customerName: 'MojaONe LTD', - * mobileNumber: '0787640622', - * items: [ - * { - * id: 1, - * desc: 'Solar Panel', - * qty: 3, - * taxcode: 1, - * amt: '5000.00', - * }, - * ], - * totals: { - * totaltaxincl: '15000.00', - * discount: '0', - * }, - * payments: { - * pmttype: 'INVOICE', - * pmtamount: '15000.00', - * }, + * items: [], * }); * @function * @public @@ -98,26 +79,7 @@ export function post(path, data, options, callback) { * request("POST", "/client/CreateInvoice", { * invoice_id: 'PID092', * customerId: '102', - * customerIdType: '6', - * customerName: 'MojaONe LTD', - * mobileNumber: '0787640622', - * items: [ - * { - * id: 1, - * desc: 'Solar Panel', - * qty: 3, - * taxcode: 1, - * amt: '5000.00', - * }, - * ], - * totals: { - * totaltaxincl: '15000.00', - * discount: '0', - * }, - * payments: { - * pmttype: 'INVOICE', - * pmtamount: '15000.00', - * }, + * items: [], * }); * @function * @public diff --git a/packages/mojatax/src/Utils.js b/packages/mojatax/src/Utils.js index 4b07bce08..b10fb7fd1 100644 --- a/packages/mojatax/src/Utils.js +++ b/packages/mojatax/src/Utils.js @@ -7,25 +7,26 @@ import { import nodepath from 'node:path'; export const authorize = state => { - const auth = state.configuration; + const auth = state.configuration ?? {}; if (auth.access_token) { return state; } - const clientId = auth.clientId; - const password = auth.password; + + const { clientId: client_id, password } = auth; + const headers = {}; - if (clientId && password) { + if (client_id && password) { Object.assign(headers, { 'Content-Type': 'application/json', }); const body = { - client_id: clientId, - password: password, + client_id, + password, }; const options = { - body: JSON.stringify(body), + body, headers, method: 'POST', parseAs: 'json', @@ -62,7 +63,7 @@ export const prepareNextState = (state, response, callback = s => s) => { }; export const request = (configuration, method, path, options) => { - const { baseUrl, access_token } = configuration; + const { baseUrl, access_token } = configuration ?? {}; const { data, params = {} } = options; diff --git a/packages/mojatax/test/Adaptor.test.js b/packages/mojatax/test/Adaptor.test.js index 6750b3289..a9b4d0ad6 100644 --- a/packages/mojatax/test/Adaptor.test.js +++ b/packages/mojatax/test/Adaptor.test.js @@ -28,47 +28,7 @@ before(() => { .persist(); }); -describe('execute', () => { - it('executes each operation in sequence', async () => { - const state = { - configuration, - }; - const operations = [ - state => { - return { counter: 1 }; - }, - state => { - return { counter: 2 }; - }, - state => { - return { counter: 3 }; - }, - ]; - - const finalState = await execute(...operations)(state); - - expect(finalState).to.eql({ counter: 3 }); - }); - it('assigns references and data to the initialState', async () => { - const state = { - configuration, - }; - - const finalState = await execute()(state); - - expect(finalState).to.eql({ - configuration: { - baseUrl: 'https://fake.mojatax.server.com', - clientId: 'someclientid', - password: 'somepassword', - access_token: 'fake-token', - }, - references: [], - data: null, - }); - }); -}); describe('request', () => { it('makes a post request to the right endpoint', async () => { @@ -97,14 +57,16 @@ describe('request', () => { }); describe('post', () => { - it('should create an invoice', async () => { + it('posts to /CreateInvoice', async () => { + testServer .intercept({ path: `/api/v1/client/CreateInvoice`, method: 'POST', }) - .reply(201, () => { + .reply(201, (req) => { + expect(JSON.parse(req.body)).to.haveOwnProperty('customerId'); return { id: 7,"customerId": "102", } }); @@ -113,7 +75,7 @@ describe('post', () => { }; const { data } = await execute( - post('CreateInvoice',{ + post('CreateInvoice', { "customerId": "102", "invoice_id": "PID092", } )