budibase/packages/server/middleware/routes/neo/tests/couchTestUtils.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-04-09 17:53:48 +02:00
const couchdb = require("../../../../db");
const CLIENT_DB_ID = "client-testing";
2020-04-10 12:18:15 +02:00
exports.destroyDatabase = couchdb.db.destroy;
2020-04-13 12:47:53 +02:00
exports.createModel = async instanceId => {
const model = {
"name": "TestModel",
"type": "model",
"key": "name",
"fields": [
{
"name": "name",
"type": "string"
}
]
}
await couchdb.db.use(instanceId).insert(model);
return model;
}
2020-04-09 17:53:48 +02:00
exports.createClientDatabase = async () => {
await couchdb.db.create(CLIENT_DB_ID);
await couchdb.db.use(CLIENT_DB_ID).insert({
views: {
by_type: {
map: function(doc) {
emit([doc.type], doc._id);
}
}
}
}, '_design/client');
}
exports.createInstanceDatabase = async instanceId => {
await couchdb.db.create(instanceId);
await couchdb.db.use(instanceId).insert({
views: {
by_type: {
map: function(doc) {
emit([doc.type], doc._id);
}
}
}
}, '_design/database');
2020-04-13 12:47:53 +02:00
return instanceId;
2020-04-10 17:37:59 +02:00
}
exports.insertDocument = async (databaseId, document) => {
const { id, ...documentFields } = document;
await couchdb.db.use(databaseId).insert(documentFields, id);
2020-04-09 17:53:48 +02:00
}