|
| 1 | +//@ts-check |
| 2 | +import { describe, expect, test, beforeAll } from '@jest/globals'; |
| 3 | +import { WOQLClient, WOQL } from '../index.js'; |
| 4 | +import { DbDetails } from '../dist/typescript/lib/typedef.js'; |
| 5 | +import { Vars } from '../lib/woql.js'; |
| 6 | + |
| 7 | +let client: WOQLClient //= new WOQLClient('http://localhost:6363'); |
| 8 | +const db01 = 'db__test_woql_arithmetic'; |
| 9 | + |
| 10 | +beforeAll(() => { |
| 11 | + client = new WOQLClient("http://localhost:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' }) |
| 12 | + client.db(db01); |
| 13 | +}); |
| 14 | + |
| 15 | + |
| 16 | +describe('Tests for woql arithmetic', () => { |
| 17 | + test('Create a database', async () => { |
| 18 | + const dbObj: DbDetails = { label: db01, comment: 'add db', schema: true } |
| 19 | + const result = await client.createDatabase(db01, dbObj); |
| 20 | + //woqlClient return only the data no status |
| 21 | + expect(result["@type"]).toEqual("api:DbCreateResponse"); |
| 22 | + expect(result["api:status"]).toEqual("api:success"); |
| 23 | + }); |
| 24 | + |
| 25 | + test('Test simple arithmetic with vars variables handling', async () => { |
| 26 | + let v = Vars("result"); |
| 27 | + const query = WOQL.limit(100).eval(WOQL.times(2, 3), v.result); |
| 28 | + |
| 29 | + const expectedJson = [{"result": {"@type": "xsd:decimal", "@value": 6}}]; |
| 30 | + |
| 31 | + const result = await client.query(query); |
| 32 | + expect(result?.bindings).toStrictEqual(expectedJson); |
| 33 | + }); |
| 34 | + |
| 35 | + test('Test simple arithmetic with string variable handling', async () => { |
| 36 | + const query = WOQL.limit(100).eval(WOQL.times(2, 3), "v:result"); |
| 37 | + |
| 38 | + const expectedJson = [{"result": {"@type": "xsd:decimal", "@value": 6}}]; |
| 39 | + |
| 40 | + const result = await client.query(query); |
| 41 | + expect(result?.bindings).toStrictEqual(expectedJson); |
| 42 | + }); |
| 43 | + |
| 44 | + test('Delete a database', async () => { |
| 45 | + const result = await client.deleteDatabase(db01); |
| 46 | + expect(result).toStrictEqual({ '@type': 'api:DbDeleteResponse', 'api:status': 'api:success' }); |
| 47 | + }); |
| 48 | +}); |
0 commit comments