Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions test-basic/annTopK.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('tests for annTopK', function () {
planAnnTopKOptionsMap)
.orderBy(p.col('name'))
);
done(new Error('Expecting an error to be thrown due to invalid key in options argument'));
} catch(error){
assert(error.message.toString().includes('options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid'))
done();
Expand Down
20 changes: 15 additions & 5 deletions test-basic/basePath-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath'));
})
.catch(err=>
{
assert(err.toString().includes('path: invalid/v1/documents'));
Expand All @@ -29,7 +31,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with a leading slash'));
})
.catch(err=>
{
assert(err.toString().includes('path: /invalid/v1/documents'));
Expand All @@ -41,7 +45,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid/';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with a trailing slash'));
})
.catch(err=>
{
assert(err.toString().includes('path: invalid/v1/documents'));
Expand All @@ -53,7 +59,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid/';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with starting and trailing slashes'));
})
.catch(err=>
{
assert(err.toString().includes('path: /invalid/v1/documents'));
Expand All @@ -65,7 +73,9 @@ describe('basePath tests', function() {
testconfig.restWriterConnectionWithBasePath.basePath = '//invalid//';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){})
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with multiple starting and trailing slashes'));
})
.catch(err=>
{
try{
Expand Down
81 changes: 57 additions & 24 deletions test-basic/bindingFromParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate,null, temp);
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
} catch (e) {
e.toString().should.equal('Error: row-col-types argument at 2 of PlanBuilder.fromParam() has invalid argument for PlanRowColTypes value: [object Object]');
done();
Expand Down Expand Up @@ -157,6 +158,7 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp);
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
} catch (e) {
e.toString().should.equal('Error: row-col-types argument at 2 of PlanBuilder.fromParam() has another type than string');
done();
Expand Down Expand Up @@ -205,7 +207,11 @@ describe('optic-update fromParam tests', function(){
}, {"column": "lastName", "type": "string"}];
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp).catch(e => {
db.rows.query(planBuilderTemplate, null, temp)
.then(function(response){
done(new Error('Expecting an error to be thrown due to null value for non-nullable column'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
Expand All @@ -221,7 +227,11 @@ describe('optic-update fromParam tests', function(){
}, {"column": "lastName", "type": "string", "nullable": true}];
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null,temp).catch(e => {
db.rows.query(planBuilderTemplate, null,temp)
.then(function(response){
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
Expand All @@ -237,7 +247,11 @@ describe('optic-update fromParam tests', function(){
}, {"column": "lastName", "type": "string", "nullable": true}];
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate,null, temp).catch(e => {
db.rows.query(planBuilderTemplate,null, temp)
.then(function(response){
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
Expand All @@ -255,10 +269,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate,null, temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to null value for non-nullable column'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
} catch (e) {
done();
}
Expand All @@ -274,10 +291,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null,temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to extra non-defined column types'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});

});

Expand All @@ -290,10 +310,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {bindingParam: rows};
db.rows.query(planBuilderTemplate, null, temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to non-consistent binding argument name'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});

});

Expand All @@ -311,10 +334,13 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp)
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});
.then(function(response){
done(new Error('Expecting an error to be thrown due to mismatch type'));
})
.catch(e => {
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
done();
});

});

Expand All @@ -333,6 +359,7 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', 1234, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp);
done(new Error('Expecting an error to be thrown due to invalid qualifier argument'));
} catch (e) {
e.toString().includes('Error: qualifier argument at 1 of PlanBuilder.fromParam() must be a XsString value');
done();
Expand All @@ -353,11 +380,17 @@ describe('optic-update fromParam tests', function(){
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
const temp = {myDocs: rows};
db.rows.query(planBuilderTemplate, null, temp).then(res => {
const rows = res.rows;
rows[0].id.value.should.equal(1);
rows[0].firstName.value.should.equal("firstName_1");
rows[0].lastName.value.should.equal("lastName_1");
done();
try {
const rows = res.rows;
rows[0].id.value.should.equal(1);
rows[0].firstName.value.should.equal("firstName_1");
rows[0].lastName.value.should.equal("lastName_1");
done();
} catch (e) {
done(e);
}
}).catch(e => {
done(e);
});

});
Expand Down
22 changes: 17 additions & 5 deletions test-basic/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ describe('database clients', function () {
done();
});
it('should use a custom agent', function (done) {
agentDb.connectionParams.agent.options.keepAliveTimeoutMsecs.should.equal(1000);
done();
try {
agentDb.connectionParams.agent.options.keepAliveTimeoutMsecs.should.equal(1000);
done();
} catch(e){
done(e);
}
});
it('should create a timestamp', function (done) {
let timestamp = db.createTimestamp('123');
timestamp.value.should.equal('123');
done();
try {
timestamp.value.should.equal('123');
done();
} catch(e){
done(e);
}
});
it('should throw Error when server expects DIGEST and authType is CERTIFICATE', function (done) {
const db = marklogic.createDatabaseClient({
Expand All @@ -108,6 +116,7 @@ describe('database clients', function () {
.result(function (documents) {
documents.forEach(function (document) {
});
done(new Error('Expecting an error to be thrown due to invalid authentication configuration'));
})
.catch(error => {
assert(error.toString().includes('response with invalid 401 status with path: /v1/search'));
Expand Down Expand Up @@ -143,7 +152,9 @@ describe('database clients', function () {
contentType: 'application/json',
content: '{"key1":"value 1"}'
})
.result()
.result(function (document) {
done(new Error('Expecting an error to be thrown due to invalid SSL configuration'));
})
.catch(error => {
try{
assert(error.message.toString().includes('You have attempted to access an HTTP server using HTTPS. Please check your configuration.') ||
Expand All @@ -158,6 +169,7 @@ describe('database clients', function () {
it('should throw error when authType is OAuth and oauthToken is missing', function(done){
try {
marklogic.createDatabaseClient(testconfig.restConnectionForOauth);
done(new Error('Expecting an error to be thrown due to missing oauthToken'));
} catch(error){
assert(error.message.toString().includes('oauthToken required for OAuth authentication. '));
done();
Expand Down
1 change: 1 addition & 0 deletions test-basic/cloud_authentication-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('cloud-authentication tests', function() {
host: 'invalid',
authType: 'cloud'
});
done(new Error('Expecting an error to be thrown due to missing apiKey'));
} catch(error) {
assert(error.toString().includes('apiKey needed for MarkLogic cloud authentication.'));
done();
Expand Down
6 changes: 4 additions & 2 deletions test-basic/digestauth-fips-nomd5load.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const should = require('should');

describe('FIPS test - ensure MD5 hash digester object is not loaded by default on require of www-authenticate module', function () {
it('should not automatically load MD5 digest algorithm function when requiring www-authenticate module', function () {
it('should not automatically load MD5 digest algorithm function when requiring www-authenticate module', function (done) {
/**
* Attempt to load/require the www-authenticate module after applying a monkey-patch
* to the crypto.createHash function to intercept any attempts to create an MD5 hash
Expand Down Expand Up @@ -42,7 +42,9 @@ describe('FIPS test - ensure MD5 hash digester object is not loaded by default o
// Require the module - should not call to get MD5 digester so should not throw
(() => require('../lib/www-authenticate-patched/md5')).should.not.throw();
(() => require('../lib/www-authenticate-patched/www-authenticate')).should.not.throw();

done();
} catch (e) {
done(e);
} finally {
// Restore the original createHash function to avoid side effects
// This MUST execute to avoid breaking other tests!
Expand Down
1 change: 1 addition & 0 deletions test-basic/docColTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('optic-update docColTypes tests', function() {

try {
db.rows.query(op.fromDocDescriptors(docsDescriptor).write(op.docColTypes()));
done(new Error('Expecting an error to be thrown due to invalid document descriptor'));
} catch (e) {
e.toString().includes('Error: doc-cols argument at 0 of PlanModifyPlan.write() must have type PlanDocColsIdentifier');
done();
Expand Down
Loading