|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 MarkLogic Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +var marklogic = require('../'); |
| 18 | +var fs = require('fs'); |
| 19 | +var testconfig = require('../etc/test-config.js'); |
| 20 | +var expect = require('chai').expect; |
| 21 | +var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection); |
| 22 | + |
| 23 | +describe('Endpoint caller', function() { |
| 24 | + |
| 25 | + it('moduleInitSjs endpoint', function(done) { |
| 26 | + const serviceDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/moduleInitSjs/service.json', {encoding: 'utf8'})); |
| 27 | + const endpointDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/moduleInitSjs/initializer.api', {encoding: 'utf8'})); |
| 28 | + endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+'initializer'+'.sjs'; |
| 29 | + const endpointCaller = dbWriter.endpointCaller(endpointDeclaration); |
| 30 | + const params = {param1:true, param2: '1.2', param3: [1.2, 3.4], param4:[5, 6] }; |
| 31 | + |
| 32 | + endpointCaller.call(params) |
| 33 | + .then(output => { |
| 34 | + expect(output).to.eql(true); |
| 35 | + done(); |
| 36 | + }) |
| 37 | + .catch(err => { |
| 38 | + expect.fail(err.toString()); |
| 39 | + done(); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('moduleInitXqy endpoint', function(done) { |
| 44 | + const serviceDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/moduleInitXqy/service.json', {encoding: 'utf8'})); |
| 45 | + const endpointDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/moduleInitXqy/initializer.api', {encoding: 'utf8'})); |
| 46 | + endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+'initializer'+'.xqy'; |
| 47 | + const endpointCaller = dbWriter.endpointCaller(endpointDeclaration); |
| 48 | + const params = {param1:true, param2: '1.2', param3: [1.2, 3.4], param4:[5, 6] }; |
| 49 | + |
| 50 | + endpointCaller.call(params) |
| 51 | + .then(output => { |
| 52 | + expect(output).to.eql(true); |
| 53 | + done(); |
| 54 | + }) |
| 55 | + .catch(err => { |
| 56 | + expect.fail(err.toString()); |
| 57 | + done(); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + it('postOfMultipartForDocumentArray1 endpoint', function(done) { |
| 62 | + const serviceDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/postOfMultipartForDocument/service.json', |
| 63 | + {encoding: 'utf8'})); |
| 64 | + const endpointDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/postOfMultipartForDocument/postOfMultipartForDocumentArray1.api', |
| 65 | + {encoding: 'utf8'})); |
| 66 | + endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+'postOfMultipartForDocumentArray1'+'.sjs'; |
| 67 | + const endpointCaller = dbWriter.endpointCaller(endpointDeclaration); |
| 68 | + const params = {param1:[{"root":{"child":"text1"}}, {"root":{"child":"text2"}}]}; |
| 69 | + |
| 70 | + endpointCaller.call(params) |
| 71 | + .then(output => { |
| 72 | + expect(output).to.eql(["text1", 1]); |
| 73 | + done(); |
| 74 | + }) |
| 75 | + .catch(err => { |
| 76 | + expect.fail(err.toString()); |
| 77 | + done(); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('postOfUrlencodedForDocumentArray1 endpoint', function(done) { |
| 82 | + const serviceDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/postOfUrlencodedForDocument/service.json', |
| 83 | + {encoding: 'utf8'})); |
| 84 | + const endpointDeclaration = JSON.parse(fs.readFileSync('test-basic-proxy/ml-modules/generated/postOfUrlencodedForDocument/postOfUrlencodedForDocumentArray1.api', |
| 85 | + {encoding: 'utf8'})); |
| 86 | + endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+'postOfUrlencodedForDocumentArray1'+'.mjs'; |
| 87 | + const endpointCaller = dbWriter.endpointCaller(endpointDeclaration); |
| 88 | + const params = {param1:[1.2, 3.4]}; |
| 89 | + |
| 90 | + endpointCaller.call(params) |
| 91 | + .then(output => { |
| 92 | + expect(output).to.eql(["text1", 1]); |
| 93 | + done(); |
| 94 | + }) |
| 95 | + .catch(err => { |
| 96 | + expect.fail(err.toString()); |
| 97 | + done(); |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments