diff --git a/client/desk/formpage.js b/client/desk/formpage.js index 40193215..58db93f8 100644 --- a/client/desk/formpage.js +++ b/client/desk/formpage.js @@ -42,7 +42,7 @@ module.exports = class FormPage extends Page { await this.form.setDoc(params.doctype, params.name); frappe.desk.setActiveDoc(this.form.doc); } catch (e) { - this.renderError(e.status_code, e.message); + this.renderError(e.statusCode, e.message); } } } diff --git a/common/errors.js b/common/errors.js index a66113cf..7a5628a0 100644 --- a/common/errors.js +++ b/common/errors.js @@ -1,22 +1,35 @@ class BaseError extends Error { - constructor(status_code, ...params) { + constructor(statusCode, ...params) { super(...params); - this.status_code = status_code; + this.statusCode = statusCode; } } class ValidationError extends BaseError { - constructor(...params) { super(417, ...params); } + constructor(...params) { + super(417, ...params); + } } -module.exports = { - ValidationError: ValidationError, - ValueError: class ValueError extends ValidationError { }, - Conflict: class Conflict extends ValidationError { }, - NotFound: class NotFound extends BaseError { - constructor(...params) { super(404, ...params); } - }, - Forbidden: class Forbidden extends BaseError { - constructor(...params) { super(403, ...params); } - }, +class NotFound extends BaseError { + constructor(...params) { + super(404, ...params); + } +} + +class Forbidden extends BaseError { + constructor(...params) { + super(403, ...params); + } +} + +class ValueError extends ValidationError { } +class Conflict extends ValidationError { } + +module.exports = { + ValidationError, + ValueError, + Conflict, + NotFound, + Forbidden } diff --git a/model/naming.js b/model/naming.js index bb4304bb..ced7c208 100644 --- a/model/naming.js +++ b/model/naming.js @@ -62,10 +62,11 @@ module.exports = { try { series = await frappe.getDoc('NumberSeries', prefix); } catch (e) { - if (!e.status_code || e.status_code !== 404) { + if (!e.statusCode || e.statusCode !== 404) { throw e; } await this.createNumberSeries(prefix); + series = await frappe.getDoc('NumberSeries', prefix); } let next = await series.next() return prefix + next; diff --git a/tests/test_document.js b/tests/test_document.js index 87700b03..65d3c39a 100644 --- a/tests/test_document.js +++ b/tests/test_document.js @@ -67,7 +67,7 @@ describe('Document', () => { assert.equal(await frappe.db.getValue(doc.doctype, doc.name), null); }); - it('should add, fetch and delete documents with children', async() => { + it('should add, fetch and delete documents with children', async () => { if (!await frappe.db.exists('Role', 'Test Role 1')) { await frappe.insert({doctype: 'Role', name: 'Test Role'}); await frappe.insert({doctype: 'Role', name: 'Test Role 1'}); @@ -76,7 +76,8 @@ describe('Document', () => { let user = frappe.newDoc({ doctype: 'User', name: frappe.getRandomString(), - full_name: 'Test User', + fullName: 'Test User', + password: frappe.getRandomString(), roles: [ { role: 'Test Role' diff --git a/tests/test_naming.js b/tests/test_naming.js index f29a40bb..cc85a87e 100644 --- a/tests/test_naming.js +++ b/tests/test_naming.js @@ -10,9 +10,9 @@ describe('Naming', () => { it('should start a series and get next value', async () => { frappe.db.delete('NumberSeries', 'test-series-') - assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-1'); - assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-2'); - assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-3'); + assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-1001'); + assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-1002'); + assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-1003'); }); it('should set name by autoincrement', async () => { diff --git a/tests/test_restAPI.js b/tests/test_restAPI.js index e4343b7e..2416d1c2 100644 --- a/tests/test_restAPI.js +++ b/tests/test_restAPI.js @@ -16,7 +16,7 @@ describe('REST', () => { }); await frappe.init(); - await frappe.login(); + await frappe.login('Administrator'); frappe.db = await new HTTPClient({server: 'localhost:8000'}); frappe.fetch = fetch; diff --git a/utils/index.js b/utils/index.js index 0f71b461..309dcd5f 100644 --- a/utils/index.js +++ b/utils/index.js @@ -61,7 +61,7 @@ function asyncHandler(fn) { .catch((err) => { console.log(err); // handle error - res.status(err.status_code || 500).send({error: err.message}); + res.status(err.statusCode || 500).send({error: err.message}); }); }