Skip to content

Commit e804eb4

Browse files
authored
Merge branch 'main' into issue/318-fix-woql-from
2 parents e44bdfa + 794d701 commit e804eb4

File tree

7 files changed

+1286
-1263
lines changed

7 files changed

+1286
-1263
lines changed

integration_tests/create_database.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import schemaJson from './persons_schema'
1010
let client : WOQLClient //= new WOQLClient('http://localhost:6363');
1111

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

1616
const db01 = 'db__test';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
});

integration_tests/woql_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import fs from 'fs';
99
let client: WOQLClient //= new WOQLClient('http://localhost:6363');
1010

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

1515
const db01 = 'db__test_woql';

lib/woqlClient.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/// /@ts-check
66
const FormData = require('form-data');
77
const fs = require('fs');
8+
const { Buffer } = require('buffer');
89
const typedef = require('./typedef');
910
const CONST = require('./const');
1011
const DispatchRequest = require('./dispatchRequest');
@@ -648,7 +649,7 @@ WOQLClient.prototype.query = function (woql, commitMsg, allWitnesses, lastDataVe
648649
const providedResourcesLookupMap = (resources ?? [])
649650
.reduce((map, res) => ({ ...map, [(res.filename).split('/').pop()]: res.data }), {});
650651

651-
if (woql && woql.json && (!woql.containsUpdate() || commitMsg)) {
652+
if (woql?.json && (!woql.containsUpdate() || commitMsg)) {
652653
const doql = woql.containsUpdate() ? this.generateCommitInfo(commitMsg) : {};
653654
doql.query = woql.json();
654655

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

669670
if (providedResourceInsteadOfFile) {
670-
formData.append('file', new Blob([providedResourceInsteadOfFile], { type: 'application/csv' }), fileName);
671+
formData.append('file', Buffer.from(providedResourceInsteadOfFile), { filename: fileName, contentType: 'application/csv' });
671672
} else {
672673
formData.append('file', fs.createReadStream(resourceObject.source.post));
673674
}
674675
resourceObject.source.post = fileName;
675676
});
676677

677-
formData.append('payload', new Blob([JSON.stringify(doql)], { type: 'application/json' }), 'body.json');
678+
formData.append('payload', Buffer.from(JSON.stringify(doql)), { filename: 'body.json', contentType: 'application/json' });
678679
if (formData.getHeaders) {
679680
this.customHeaders(formData.getHeaders());
680681
} else {

0 commit comments

Comments
 (0)