-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcreate_database.test.ts
131 lines (110 loc) · 5.05 KB
/
create_database.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//@ts-check
import {describe, expect, test, beforeAll} from '@jest/globals';
//import WOQLClient from '../lib/woqlClient';
import {WOQLClient} from '../index.js';
import { DbDetails, DocParamsGet } from '../dist/typescript/lib/typedef';
//import {ParamsObj,DbDetails} from '../lib/typedef';
import schemaJson from './persons_schema'
//console.log(typeof schemaJson)
let client : WOQLClient //= new WOQLClient('http://localhost:6363');
beforeAll(() => {
client = new WOQLClient("http://localhost:6363",{ user: 'admin', organization: 'admin', key: 'root' })
});
const db01 = 'db__test';
describe('Create a database, schema and insert data', () => {
test('Create a database', async () => {
const dbObj : DbDetails = { label: db01, comment: 'add db', schema: true }
const result = await client.createDatabase(db01,dbObj);
//woqlClient return only the data no status
expect(result["@type"]).toEqual("api:DbCreateResponse");
expect(result["api:status"]).toEqual("api:success");
});
test('Create a schema', async () => {
const result = await client.addDocument(schemaJson,{graph_type:"schema",full_replace:true});
expect(result).toStrictEqual(["Child", "Person", "Parent" ]);
})
test('Insert Document Child Tom', async () => {
const person = {"age":"10","name":"Tom","@type":"Child" }
const result = await client.addDocument(person);
expect(result).toStrictEqual(["terminusdb:///data/Child/Tom" ]);
})
test('Insert Document Child Anna', async () => {
const person = {"age":"20","name":"Anna","@type":"Child"}
const result = await client.addDocument(person);
expect(result).toStrictEqual(["terminusdb:///data/Child/Anna" ]);
})
test('Insert Document Parent Tom Senior', async () => {
const person = {"age":"40","name":"Tom Senior","@type":"Parent" , "has_child":"Child/Tom"}
const result = await client.addDocument(person);
expect(result).toStrictEqual(["terminusdb:///data/Parent/Tom%20Senior" ]);
})
test('Get document history on an object', async () => {
const result = await client.getDocumentHistory("Child/Tom");
expect(result[0].message).toStrictEqual("add a new document");
})
test('Query Person by name', async () => {
const queryTemplate = {"name":"Tom", "@type":"Person" }
const result = await client.getDocument({query:queryTemplate});
expect(result).toStrictEqual({ '@id': 'Child/Tom', '@type': 'Child', age: "10", name: 'Tom' });
})
test('Query Person by ege', async () => {
const queryTemplate = {"age":"40", "@type":"Person" }
const result = await client.getDocument({query:queryTemplate});
expect(result).toStrictEqual({"@id": "Parent/Tom%20Senior", "age":"40","name":"Tom Senior","@type":"Parent" , "has_child":"Child/Tom"});
})
const change_request = "change_request02";
test('Create Branch change_request', async () => {
const result = await client.branch(change_request);
expect(result).toStrictEqual({ '@type': 'api:BranchResponse', 'api:status': 'api:success' });
})
test('Checkout Branch change_request', async () => {
client.checkout(change_request)
expect(client.checkout()).toStrictEqual(change_request);
})
test('Update Child Tom, link Parent', async () => {
const childTom = { '@id': 'Child/Tom', '@type': 'Child', age: "10", name: 'Tom' , has_parent:"Parent/Tom%20Senior"}
const result = await client.updateDocument(childTom);
expect(result).toStrictEqual(["terminusdb:///data/Child/Tom" ]);
})
test('Diff beetwen main and change_request branch', async () => {
const result = await client.getVersionDiff("main",change_request);
expect(result).toStrictEqual([
{
'@id': 'Child/Tom',
has_parent: {
'@after': 'Parent/Tom%20Senior',
'@before': null,
'@op': 'SwapValue'
}
}
]);
})
test('Checkout Branch change_request', async () => {
client.checkout("main")
expect(client.checkout()).toStrictEqual("main");
})
test('Merge beetwen main and change_request branch', async () => {
const result = await client.apply("main", change_request, "merge change_request to main");
expect(result).toStrictEqual( { '@type': 'api:ApplyResponse', 'api:status': 'api:success' });
})
test('Check if merge worked. Query Person by age in main branch', async () => {
const queryTemplate = {"age":"10", "@type":"Person" }
const result = await client.getDocument({query:queryTemplate});
//console.log(result)
expect(result).toStrictEqual({
'@id': 'Child/Tom',
'@type': 'Child',
age: "10",
name: 'Tom',
has_parent: 'Parent/Tom%20Senior'
});
})
test('Delete a branch', async () => {
const result = await client.deleteBranch(change_request);
expect(result).toStrictEqual({ '@type': 'api:BranchResponse', 'api:status': 'api:success' });
});
test('Delete a database', async () => {
const result = await client.deleteDatabase(db01);
expect(result).toStrictEqual({ '@type': 'api:DbDeleteResponse', 'api:status': 'api:success' });
});
});