2
0
mirror of https://github.com/frappe/books.git synced 2025-02-02 20:18:26 +00:00
books/frappe/tests/test_database.js

49 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-01-01 14:57:59 +05:30
const assert = require('assert');
const frappe = require('frappe-core');
2018-01-03 12:19:59 +05:30
const helpers = require('./helpers');
2018-01-01 14:57:59 +05:30
2018-01-02 15:40:32 +05:30
describe('Database', () => {
before(async function() {
2018-01-03 12:19:59 +05:30
await helpers.init_sqlite();
2018-01-01 14:57:59 +05:30
});
2018-01-02 15:40:32 +05:30
it('should insert and get values', async () => {
await frappe.db.sql('delete from todo');
await frappe.insert({doctype:'ToDo', subject: 'testing 1'});
await frappe.insert({doctype:'ToDo', subject: 'testing 3'});
await frappe.insert({doctype:'ToDo', subject: 'testing 2'});
2018-01-01 15:58:30 +05:30
2018-01-03 15:42:40 +05:30
let subjects = await frappe.db.get_all({doctype:'ToDo', fields:['name', 'subject']})
2018-01-02 15:40:32 +05:30
subjects = subjects.map(d => d.subject);
2018-01-01 15:58:30 +05:30
assert.ok(subjects.includes('testing 1'));
assert.ok(subjects.includes('testing 2'));
assert.ok(subjects.includes('testing 3'));
});
2018-01-02 15:40:32 +05:30
it('should filter correct values', async () => {
2018-01-01 15:58:30 +05:30
let subjects = null;
2018-01-02 15:40:32 +05:30
await frappe.db.sql('delete from todo');
await frappe.insert({doctype:'ToDo', subject: 'testing 1', status: 'Open'});
await frappe.insert({doctype:'ToDo', subject: 'testing 3', status: 'Open'});
await frappe.insert({doctype:'ToDo', subject: 'testing 2', status: 'Closed'});
2018-01-01 15:58:30 +05:30
2018-01-03 15:42:40 +05:30
subjects = await frappe.db.get_all({doctype:'ToDo', fields:['name', 'subject'],
filters:{status: 'Open'}});
2018-01-02 15:40:32 +05:30
subjects = subjects.map(d => d.subject);
2018-01-01 15:58:30 +05:30
assert.ok(subjects.includes('testing 1'));
assert.ok(subjects.includes('testing 3'));
assert.equal(subjects.includes('testing 2'), false);
2018-01-03 15:42:40 +05:30
subjects = await frappe.db.get_all({doctype:'ToDo', fields:['name', 'subject'],
filters:{status: 'Closed'}});
2018-01-02 15:40:32 +05:30
subjects = subjects.map(d => d.subject);
2018-01-01 15:58:30 +05:30
assert.equal(subjects.includes('testing 1'), false);
assert.equal(subjects.includes('testing 3'), false);
assert.ok(subjects.includes('testing 2'));
});
2018-01-01 14:57:59 +05:30
});