2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00

Fix failing tests

This commit is contained in:
Faris Ansari 2018-07-18 00:59:18 +05:30
parent f92e1c28e4
commit 24b55da0e4
7 changed files with 37 additions and 22 deletions

View File

@ -42,7 +42,7 @@ module.exports = class FormPage extends Page {
await this.form.setDoc(params.doctype, params.name); await this.form.setDoc(params.doctype, params.name);
frappe.desk.setActiveDoc(this.form.doc); frappe.desk.setActiveDoc(this.form.doc);
} catch (e) { } catch (e) {
this.renderError(e.status_code, e.message); this.renderError(e.statusCode, e.message);
} }
} }
} }

View File

@ -1,22 +1,35 @@
class BaseError extends Error { class BaseError extends Error {
constructor(status_code, ...params) { constructor(statusCode, ...params) {
super(...params); super(...params);
this.status_code = status_code; this.statusCode = statusCode;
} }
} }
class ValidationError extends BaseError { class ValidationError extends BaseError {
constructor(...params) { super(417, ...params); } constructor(...params) {
super(417, ...params);
}
} }
module.exports = { class NotFound extends BaseError {
ValidationError: ValidationError, constructor(...params) {
ValueError: class ValueError extends ValidationError { }, super(404, ...params);
Conflict: class Conflict extends ValidationError { }, }
NotFound: class NotFound extends BaseError { }
constructor(...params) { super(404, ...params); }
}, class Forbidden extends BaseError {
Forbidden: class Forbidden extends BaseError { constructor(...params) {
constructor(...params) { super(403, ...params); } super(403, ...params);
}, }
}
class ValueError extends ValidationError { }
class Conflict extends ValidationError { }
module.exports = {
ValidationError,
ValueError,
Conflict,
NotFound,
Forbidden
} }

View File

@ -62,10 +62,11 @@ module.exports = {
try { try {
series = await frappe.getDoc('NumberSeries', prefix); series = await frappe.getDoc('NumberSeries', prefix);
} catch (e) { } catch (e) {
if (!e.status_code || e.status_code !== 404) { if (!e.statusCode || e.statusCode !== 404) {
throw e; throw e;
} }
await this.createNumberSeries(prefix); await this.createNumberSeries(prefix);
series = await frappe.getDoc('NumberSeries', prefix);
} }
let next = await series.next() let next = await series.next()
return prefix + next; return prefix + next;

View File

@ -67,7 +67,7 @@ describe('Document', () => {
assert.equal(await frappe.db.getValue(doc.doctype, doc.name), null); 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')) { 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'});
await frappe.insert({doctype: 'Role', name: 'Test Role 1'}); await frappe.insert({doctype: 'Role', name: 'Test Role 1'});
@ -76,7 +76,8 @@ describe('Document', () => {
let user = frappe.newDoc({ let user = frappe.newDoc({
doctype: 'User', doctype: 'User',
name: frappe.getRandomString(), name: frappe.getRandomString(),
full_name: 'Test User', fullName: 'Test User',
password: frappe.getRandomString(),
roles: [ roles: [
{ {
role: 'Test Role' role: 'Test Role'

View File

@ -10,9 +10,9 @@ describe('Naming', () => {
it('should start a series and get next value', async () => { it('should start a series and get next value', async () => {
frappe.db.delete('NumberSeries', 'test-series-') 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-1001');
assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-2'); assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-1002');
assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-3'); assert.equal(await naming.getSeriesNext('test-series-'), 'test-series-1003');
}); });
it('should set name by autoincrement', async () => { it('should set name by autoincrement', async () => {

View File

@ -16,7 +16,7 @@ describe('REST', () => {
}); });
await frappe.init(); await frappe.init();
await frappe.login(); await frappe.login('Administrator');
frappe.db = await new HTTPClient({server: 'localhost:8000'}); frappe.db = await new HTTPClient({server: 'localhost:8000'});
frappe.fetch = fetch; frappe.fetch = fetch;

View File

@ -61,7 +61,7 @@ function asyncHandler(fn) {
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
// handle error // handle error
res.status(err.status_code || 500).send({error: err.message}); res.status(err.statusCode || 500).send({error: err.message});
}); });
} }