-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwoql_client.test.ts
87 lines (75 loc) · 3.29 KB
/
woql_client.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
//@ts-check
import { describe, expect, test, beforeAll } from '@jest/globals';
import { WOQLClient, WOQL } from '../index.js';
import { DbDetails, DocParamsGet } from '../dist/typescript/lib/typedef.js';
import schemaJson from './persons_schema'
import { mock_employees_limit_1 } from './data/employees_limit1';
import fs from 'fs';
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_woql';
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('Query with CSV upload from file', async () => {
const query = WOQL.limit(1).and(
WOQL.get(
WOQL.as('Name', 'v:Name')
.as('Manager', 'v:Manager')
.as('Title', 'v:Title'),
WOQL.post("./integration_tests/data/employees.csv")
),
);
const result = await client.query(query, undefined, undefined, undefined, undefined,);
expect(result?.bindings).toStrictEqual(mock_employees_limit_1);
});
test('Query with CSV upload as resource attachment', async () => {
const query = WOQL.limit(1).and(
WOQL.get(
WOQL.as('Name', 'v:Name')
.as('Manager', 'v:Manager')
.as('Title', 'v:Title'),
WOQL.post("employees.csv")
),
);
const data = fs.readFileSync('./integration_tests/data/employees.csv');
const result = await client.query(query, undefined, undefined, undefined, undefined, [{
filename: "employees.csv",
data: data,
}]);
expect(result?.bindings).toStrictEqual(mock_employees_limit_1);
});
test('Get branches from the server (only main)', async () => {
const result = await client.getBranches();
expect(result.main["@id"]).toStrictEqual("Branch/main");
expect(Object.keys(result)).toStrictEqual(["main"]);
});
test('Get commits log from the server', async () => {
const result = await client.getCommitsLog();
expect(result.length).toStrictEqual(1);
expect(result[0]["@type"]).toStrictEqual("ValidCommit");
});
test('Get prefixes from the server', async () => {
const result = await client.getPrefixes();
expect(result).toStrictEqual({"@base": "terminusdb:///data/", "@schema": "terminusdb:///schema#", "@type": "Context"});
});
test('Get userOrganisations from the server', async () => {
const result = (await client.getUserOrganizations()).filter(org => org["@id"] === "Organization/admin");
expect(result[0]["@id"]).toStrictEqual("Organization/admin");
});
test('Delete a database', async () => {
const result = await client.deleteDatabase(db01);
expect(result).toStrictEqual({ '@type': 'api:DbDeleteResponse', 'api:status': 'api:success' });
});
});