|
| 1 | +/* |
| 2 | +* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. |
| 3 | +*/ |
| 4 | + |
| 5 | +/// <reference path="../marklogic.d.ts" /> |
| 6 | + |
| 7 | +/** |
| 8 | + * Runtime validation tests for Documents API. |
| 9 | + * |
| 10 | + * These tests make actual calls to MarkLogic to verify: |
| 11 | + * - Type definitions match runtime behavior |
| 12 | + * - ResultProvider pattern works correctly |
| 13 | + * - Methods return expected data structures |
| 14 | + * |
| 15 | + * Run with: npm run test:compile && npx mocha test-typescript/*.js |
| 16 | + */ |
| 17 | + |
| 18 | +import should = require('should'); |
| 19 | +import type { DatabaseClient } from 'marklogic'; |
| 20 | + |
| 21 | +const testConfig = require('../etc/test-config.js'); |
| 22 | +const marklogic = require('../lib/marklogic.js'); |
| 23 | + |
| 24 | +describe('Documents API runtime validation', function() { |
| 25 | + let client: DatabaseClient; |
| 26 | + const testUri = '/test-typescript/documents-runtime-test.json'; |
| 27 | + const testContent = { message: 'TypeScript test document', timestamp: Date.now() }; |
| 28 | + |
| 29 | + before(function() { |
| 30 | + client = marklogic.createDatabaseClient(testConfig.restWriterConnection); |
| 31 | + }); |
| 32 | + |
| 33 | + after(function() { |
| 34 | + client.release(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('write() returns ResultProvider with WriteResult', async function() { |
| 38 | + const resultProvider = client.documents.write({ |
| 39 | + uri: testUri, |
| 40 | + content: testContent, |
| 41 | + contentType: 'application/json' |
| 42 | + }); |
| 43 | + |
| 44 | + // Verify ResultProvider has result() method |
| 45 | + resultProvider.should.have.property('result'); |
| 46 | + resultProvider.result.should.be.a.Function(); |
| 47 | + |
| 48 | + const writeResult = await resultProvider.result(); |
| 49 | + |
| 50 | + // Verify return type is WriteResult with documents array |
| 51 | + writeResult.should.be.an.Object(); |
| 52 | + writeResult.should.have.property('documents'); |
| 53 | + writeResult.documents.should.be.an.Array(); |
| 54 | + writeResult.documents.should.have.length(1); |
| 55 | + writeResult.documents[0].should.have.property('uri'); |
| 56 | + writeResult.documents[0].uri.should.equal(testUri); |
| 57 | + }); |
| 58 | + |
| 59 | + it('probe() returns ResultProvider with ProbeResult', async function() { |
| 60 | + const resultProvider = client.documents.probe(testUri); |
| 61 | + |
| 62 | + // Verify ResultProvider has result() method |
| 63 | + resultProvider.should.have.property('result'); |
| 64 | + resultProvider.result.should.be.a.Function(); |
| 65 | + |
| 66 | + const probeResult = await resultProvider.result(); |
| 67 | + |
| 68 | + // Verify ProbeResult structure |
| 69 | + probeResult.should.have.property('uri', testUri); |
| 70 | + probeResult.should.have.property('exists', true); |
| 71 | + probeResult.should.have.property('contentType'); |
| 72 | + probeResult.should.have.property('contentLength'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('read() returns ResultProvider with DocumentDescriptor array', async function() { |
| 76 | + const resultProvider = client.documents.read(testUri); |
| 77 | + |
| 78 | + // Verify ResultProvider has result() method |
| 79 | + resultProvider.should.have.property('result'); |
| 80 | + resultProvider.result.should.be.a.Function(); |
| 81 | + |
| 82 | + const docs = await resultProvider.result(); |
| 83 | + |
| 84 | + // Verify return type is DocumentDescriptor array |
| 85 | + docs.should.be.an.Array(); |
| 86 | + docs.should.have.length(1); |
| 87 | + |
| 88 | + const doc = docs[0]; |
| 89 | + doc.should.have.property('uri', testUri); |
| 90 | + doc.should.have.property('content'); |
| 91 | + doc.content.should.have.property('message', testContent.message); |
| 92 | + }); |
| 93 | + |
| 94 | + it('remove() returns ResultProvider with RemoveResult', async function() { |
| 95 | + const resultProvider = client.documents.remove(testUri); |
| 96 | + |
| 97 | + // Verify ResultProvider has result() method |
| 98 | + resultProvider.should.have.property('result'); |
| 99 | + resultProvider.result.should.be.a.Function(); |
| 100 | + |
| 101 | + const result = await resultProvider.result(); |
| 102 | + |
| 103 | + // Verify RemoveResult structure |
| 104 | + result.should.have.property('uris'); |
| 105 | + result.should.have.property('removed', true); |
| 106 | + result.uris.should.be.an.Array(); |
| 107 | + result.uris.should.have.length(1); |
| 108 | + result.uris[0].should.equal(testUri); |
| 109 | + |
| 110 | + // Verify document was actually removed |
| 111 | + const probeResult = await client.documents.probe(testUri).result(); |
| 112 | + probeResult.exists.should.equal(false); |
| 113 | + }); |
| 114 | +}); |
0 commit comments