smartlog-receiver/test/test.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-03-07 21:07:59 +00:00
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
2018-11-11 00:38:19 +00:00
import * as smartlog from '@pushrocks/smartlog';
import * as smarthash from '@pushrocks/smarthash';
2022-07-27 10:34:41 +00:00
import * as smartlogReceiver from '../ts/index.js';
2018-10-31 16:42:18 +00:00
let testReceiver: smartlogReceiver.SmartlogReceiver;
2022-03-07 21:07:59 +00:00
let testSmartlog = new smartlog.Smartlog({
logContext: null,
2022-03-07 21:08:32 +00:00
minimumLogLevel: 'debug',
2022-03-07 21:07:59 +00:00
});
2018-11-11 00:38:19 +00:00
testSmartlog.enableConsole();
2018-10-31 16:42:18 +00:00
2018-11-11 00:38:19 +00:00
tap.test('should create a valid SmartlogReceiver', async () => {
testReceiver = new smartlogReceiver.SmartlogReceiver({
passphrase: 'hi',
smartlogInstance: testSmartlog,
2020-06-10 06:57:47 +00:00
validatorFunction: async () => {
2018-11-11 00:38:19 +00:00
return true;
2022-03-07 21:08:32 +00:00
},
2018-11-11 00:38:19 +00:00
});
2022-03-07 21:07:59 +00:00
expect(testReceiver).toBeInstanceOf(smartlogReceiver.SmartlogReceiver);
2018-10-31 16:45:51 +00:00
});
2018-10-31 16:42:18 +00:00
2018-11-11 00:38:19 +00:00
tap.test('should receive a message', async () => {
testReceiver.handleAuthenticatedLog({
auth: smarthash.sha256FromStringSync('hi'),
logPackage: {
2018-11-11 00:56:02 +00:00
timestamp: Date.now(),
context: {
2018-11-11 00:38:19 +00:00
company: 'Lossless GmbH',
companyunit: 'Lossless Cloud',
containerName: null,
environment: 'staging',
runtime: 'node',
2022-03-07 21:08:32 +00:00
zone: 'gitzone',
2018-11-11 00:38:19 +00:00
},
2018-11-11 00:56:02 +00:00
level: 'info',
type: 'log',
2020-06-07 12:41:25 +00:00
correlation: {
id: '123',
2022-03-07 21:08:32 +00:00
type: 'none',
2020-06-07 12:41:25 +00:00
},
2022-03-07 21:08:32 +00:00
message: 'hi there',
},
2018-11-11 00:38:19 +00:00
});
2020-06-07 12:41:25 +00:00
});
2018-11-11 00:38:19 +00:00
2018-10-31 16:42:18 +00:00
tap.start();