import { expect, tap } from '@pushrocks/tapbundle'; import { Qenv } from '@pushrocks/qenv'; import * as elasticsearch from '../ts/index.js'; let testElasticLog: elasticsearch.ElsSmartlogDestination; let testElasticDoc: elasticsearch.ElasticDoc; tap.test('first test', async () => { testElasticLog = new elasticsearch.ElsSmartlogDestination({ indexPrefix: 'testprefix', indexRetention: 7, node: 'http://localhost:9200', auth: { username: 'elastic', password: 'YourPassword' } }); expect(testElasticLog).toBeInstanceOf(elasticsearch.ElsSmartlogDestination); }); tap.test('should send a message to Elasticsearch', async () => { await testElasticLog.log({ timestamp: Date.now(), type: 'increment', level: 'info', context: { company: 'Lossless GmbH', companyunit: 'lossless.cloud', containerName: 'testcontainer', environment: 'test', runtime: 'node', zone: 'ship.zone', }, message: 'GET https://myroute.to.a.cool.destination/sorare?hello=there', correlation: null, }); }); tap.test('should create an ElasticDoc instance', async () => { testElasticDoc = new elasticsearch.ElasticDoc({ index: 'testindex', node: 'http://localhost:9200', auth: { username: 'elastic', password: 'YourPassword' } }); expect(testElasticDoc).toBeInstanceOf(elasticsearch.ElasticDoc); }); tap.test('should add and update documents in a piping session', async () => { await testElasticDoc.startPipingSession(); await testElasticDoc.pipeDocument({ docId: '1', timestamp: new Date().toISOString(), doc: { name: 'doc1' } }); await testElasticDoc.pipeDocument({ docId: '2', timestamp: new Date().toISOString(), doc: { name: 'doc2' } }); await testElasticDoc.pipeDocument({ docId: '1', timestamp: new Date().toISOString(), doc: { name: 'updated doc1' } }); }); tap.test('should delete documents not part of the piping session', async () => { await testElasticDoc.endPipingSession(); }); tap.test('should take and store snapshot', async () => { await testElasticDoc.takeSnapshot(async (iterator, prevSnapshot) => { const aggregationData = []; for await (const doc of iterator) { // Sample aggregation: counting documents aggregationData.push(doc); } const snapshot = { date: new Date().toISOString(), aggregationData, }; return snapshot; }); }); tap.start();