Skip to content

Commit e5aebe8

Browse files
committed
script for easy testing of couchdb service
1 parent e4fa8f9 commit e5aebe8

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

couchdb/test/service-check.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const couchDBService = require("../node/services/couchdb");
2+
3+
async function main() {
4+
try {
5+
// Create Database
6+
let createdDatabase = await couchDBService.createDatabase("heroes");
7+
console.log(`Created Database Heroes: ${createdDatabase.ok}`);
8+
9+
// Get Database
10+
let database = await couchDBService.getDatabase("heroes");
11+
console.log("Retrieved Database");
12+
console.log(database);
13+
14+
// Get Databases
15+
let databases = await couchDBService.getDatabases();
16+
console.log("Retrieved Database List");
17+
console.log(databases);
18+
19+
// Create Document
20+
let document = {
21+
name: "Tranquility",
22+
health: 125,
23+
stamina: 100,
24+
atk: 20,
25+
items: ["SerenityKey"],
26+
canFight: true,
27+
canHeal: true,
28+
};
29+
let documentId = "Tranquility";
30+
let createdDocument = await couchDBService.createDocument(
31+
"heroes",
32+
document,
33+
documentId
34+
);
35+
console.log(`Created Document: ${createdDocument.ok}`);
36+
37+
// Get Document
38+
let documentObj = await couchDBService.getDocument("heroes", documentId);
39+
console.log(`Retrieved Document`);
40+
console.log(documentObj);
41+
42+
// Query Documents
43+
let query = {
44+
selector: { name: { $gt: "0" } },
45+
fields: ["name", "health", "canFight"],
46+
limit: 20,
47+
};
48+
let documents = await couchDBService.queryDocuments("heroes", query);
49+
console.log("Retrieved Documents");
50+
for (let document of documents.docs) {
51+
console.log(document);
52+
}
53+
54+
// Delete Document
55+
let deletedDocument = await couchDBService.deleteDocument("heroes", documentId);
56+
console.log(`Deleted Document Tranquility: ${deletedDocument.ok}`);
57+
58+
// Get Database Changes
59+
let databaseChanges = await couchDBService.getDatabaseChanges("heroes");
60+
console.log("Retrieved Database Changes");
61+
console.log(databaseChanges);
62+
63+
// Delete Database
64+
let deletedDatabase = await couchDBService.deleteDatabase("heroes");
65+
console.log(`Deleted Database Heroes: ${deletedDatabase.ok}`);
66+
67+
} catch (e) {
68+
console.log(`Error executing couchdb service check: ${e}`);
69+
}
70+
}
71+
72+
main();

0 commit comments

Comments
 (0)