|
| 1 | +//@ts-check |
| 2 | +import { describe, expect, test, beforeAll } from '@jest/globals'; |
| 3 | +import { WOQLClient, WOQL } from '../index.js'; |
| 4 | +import { DbDetails, DocParamsGet } from '../dist/typescript/lib/typedef.js'; |
| 5 | +import schemaJson from './persons_schema' |
| 6 | +import { mock_employees_limit_1 } from './data/employees_limit1'; |
| 7 | +import fs from 'fs'; |
| 8 | + |
| 9 | +let client: WOQLClient //= new WOQLClient('http://localhost:6363'); |
| 10 | + |
| 11 | +beforeAll(() => { |
| 12 | + client = new WOQLClient("http://localhost:6363", { user: 'admin', organization: 'admin', key: 'root' }) |
| 13 | +}); |
| 14 | + |
| 15 | +const db01 = 'db__test_woql'; |
| 16 | + |
| 17 | +describe('Create a database, schema and insert data', () => { |
| 18 | + test('Create a database', async () => { |
| 19 | + const dbObj: DbDetails = { label: db01, comment: 'add db', schema: true } |
| 20 | + const result = await client.createDatabase(db01, dbObj); |
| 21 | + //woqlClient return only the data no status |
| 22 | + expect(result["@type"]).toEqual("api:DbCreateResponse"); |
| 23 | + expect(result["api:status"]).toEqual("api:success"); |
| 24 | + }); |
| 25 | + |
| 26 | + test('Create a schema', async () => { |
| 27 | + const result = await client.addDocument(schemaJson, { graph_type: "schema", full_replace: true }); |
| 28 | + expect(result).toStrictEqual(["Child", "Person", "Parent"]); |
| 29 | + }) |
| 30 | + |
| 31 | + test('Query with CSV upload from file', async () => { |
| 32 | + const query = WOQL.limit(1).and( |
| 33 | + WOQL.get( |
| 34 | + WOQL.as('Name', 'v:Name') |
| 35 | + .as('Manager', 'v:Manager') |
| 36 | + .as('Title', 'v:Title'), |
| 37 | + WOQL.post("./integration_tests/data/employees.csv") |
| 38 | + ), |
| 39 | + ); |
| 40 | + const result = await client.query(query, undefined, undefined, undefined, undefined,); |
| 41 | + expect(result?.bindings).toStrictEqual(mock_employees_limit_1); |
| 42 | + }); |
| 43 | + |
| 44 | + test('Query with CSV upload as resource attachment', async () => { |
| 45 | + const query = WOQL.limit(1).and( |
| 46 | + WOQL.get( |
| 47 | + WOQL.as('Name', 'v:Name') |
| 48 | + .as('Manager', 'v:Manager') |
| 49 | + .as('Title', 'v:Title'), |
| 50 | + WOQL.post("employees.csv") |
| 51 | + ), |
| 52 | + ); |
| 53 | + const data = fs.readFileSync('./integration_tests/data/employees.csv'); |
| 54 | + const result = await client.query(query, undefined, undefined, undefined, undefined, [{ |
| 55 | + filename: "employees.csv", |
| 56 | + data: data, |
| 57 | + }]); |
| 58 | + expect(result?.bindings).toStrictEqual(mock_employees_limit_1); |
| 59 | + }); |
| 60 | + |
| 61 | + test('Get branches from the server (only main)', async () => { |
| 62 | + const result = await client.getBranches(); |
| 63 | + expect(result.main["@id"]).toStrictEqual("Branch/main"); |
| 64 | + expect(Object.keys(result)).toStrictEqual(["main"]); |
| 65 | + }); |
| 66 | + |
| 67 | + test('Get commits log from the server', async () => { |
| 68 | + const result = await client.getCommitsLog(); |
| 69 | + expect(result.length).toStrictEqual(1); |
| 70 | + expect(result[0]["@type"]).toStrictEqual("ValidCommit"); |
| 71 | + }); |
| 72 | + |
| 73 | + test('Get prefixes from the server', async () => { |
| 74 | + const result = await client.getPrefixes(); |
| 75 | + expect(result).toStrictEqual({"@base": "terminusdb:///data/", "@schema": "terminusdb:///schema#", "@type": "Context"}); |
| 76 | + }); |
| 77 | + |
| 78 | + test('Get userOrganisations from the server', async () => { |
| 79 | + const result = (await client.getUserOrganizations()).filter(org => org["@id"] === "Organization/admin"); |
| 80 | + expect(result[0]["@id"]).toStrictEqual("Organization/admin"); |
| 81 | + }); |
| 82 | + |
| 83 | + test('Delete a database', async () => { |
| 84 | + const result = await client.deleteDatabase(db01); |
| 85 | + expect(result).toStrictEqual({ '@type': 'api:DbDeleteResponse', 'api:status': 'api:success' }); |
| 86 | + }); |
| 87 | +}); |
0 commit comments