smartlog-receiver/test/test.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-10-31 16:42:18 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2018-11-11 00:38:19 +00:00
import * as smartlog from '@pushrocks/smartlog';
import * as smarthash from '@pushrocks/smarthash';
2018-10-31 16:42:18 +00:00
import * as smartlogReceiver from '../ts/index';
let testReceiver: smartlogReceiver.SmartlogReceiver;
2018-11-11 00:38:19 +00:00
let testSmartlog = smartlog.defaultLogger;
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,
validatorFunction: () => {
return true;
}
});
expect(testReceiver).to.be.instanceof(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',
zone: 'gitzone'
},
2018-11-11 00:56:02 +00:00
level: 'info',
type: 'log',
2018-11-11 00:38:19 +00:00
message: 'hi there'
}
});
})
2018-10-31 16:42:18 +00:00
tap.start();