Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration_tests/create_database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import schemaJson from './persons_schema'
let client : WOQLClient //= new WOQLClient('http://localhost:6363');

beforeAll(() => {
client = new WOQLClient("http://localhost:6363",{ user: 'admin', organization: 'admin', key: 'root' })
client = new WOQLClient("http://localhost:6363",{ user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
});

const db01 = 'db__test';
Expand Down
48 changes: 48 additions & 0 deletions integration_tests/woql_arithmetic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//@ts-check
import { describe, expect, test, beforeAll } from '@jest/globals';
import { WOQLClient, WOQL } from '../index.js';
import { DbDetails } from '../dist/typescript/lib/typedef.js';
import { Vars } from '../lib/woql.js';

let client: WOQLClient //= new WOQLClient('http://localhost:6363');
const db01 = 'db__test_woql_arithmetic';

beforeAll(() => {
client = new WOQLClient("http://localhost:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
client.db(db01);
});


describe('Tests for woql arithmetic', () => {
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('Test simple arithmetic with vars variables handling', async () => {
let v = Vars("result");
const query = WOQL.limit(100).eval(WOQL.times(2, 3), v.result);

const expectedJson = [{"result": {"@type": "xsd:decimal", "@value": 6}}];

const result = await client.query(query);
expect(result?.bindings).toStrictEqual(expectedJson);
});

test('Test simple arithmetic with string variable handling', async () => {
const query = WOQL.limit(100).eval(WOQL.times(2, 3), "v:result");

const expectedJson = [{"result": {"@type": "xsd:decimal", "@value": 6}}];

const result = await client.query(query);
expect(result?.bindings).toStrictEqual(expectedJson);
});

test('Delete a database', async () => {
const result = await client.deleteDatabase(db01);
expect(result).toStrictEqual({ '@type': 'api:DbDeleteResponse', 'api:status': 'api:success' });
});
});
2 changes: 1 addition & 1 deletion integration_tests/woql_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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' })
client = new WOQLClient("http://localhost:6363", { user: 'admin', organization: 'admin', key: process.env.TDB_ADMIN_PASS ?? 'root' })
});

const db01 = 'db__test_woql';
Expand Down
11 changes: 8 additions & 3 deletions lib/woqlClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// /@ts-check
const FormData = require('form-data');
const fs = require('fs');
const { Buffer } = require('buffer');
const typedef = require('./typedef');
const CONST = require('./const');
const DispatchRequest = require('./dispatchRequest');
Expand Down Expand Up @@ -648,7 +649,7 @@ WOQLClient.prototype.query = function (woql, commitMsg, allWitnesses, lastDataVe
const providedResourcesLookupMap = (resources ?? [])
.reduce((map, res) => ({ ...map, [(res.filename).split('/').pop()]: res.data }), {});

if (woql && woql.json && (!woql.containsUpdate() || commitMsg)) {
if (woql?.json && (!woql.containsUpdate() || commitMsg)) {
const doql = woql.containsUpdate() ? this.generateCommitInfo(commitMsg) : {};
doql.query = woql.json();

Expand All @@ -667,15 +668,19 @@ WOQLClient.prototype.query = function (woql, commitMsg, allWitnesses, lastDataVe
const fileName = resourceObject.source.post.split('/').pop();

if (providedResourceInsteadOfFile) {
formData.append('file', providedResourceInsteadOfFile, { filename: fileName, contentType: 'application/csv' });
formData.append('file', Buffer.from(providedResourceInsteadOfFile), { filename: fileName, contentType: 'application/csv' });
} else {
formData.append('file', fs.createReadStream(resourceObject.source.post));
}
resourceObject.source.post = fileName;
});

formData.append('payload', Buffer.from(JSON.stringify(doql)), { filename: 'body.json', contentType: 'application/json' });
this.customHeaders(formData.getHeaders());
if (formData.getHeaders) {
this.customHeaders(formData.getHeaders());
} else {
this.customHeaders({ 'Content-Type': 'multipart/form-data' });
}

postBody = formData;
} else {
Expand Down
Loading