smartrule/test/test.ts

34 lines
802 B
TypeScript
Raw Normal View History

2020-01-20 08:47:35 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2022-08-07 09:18:02 +00:00
import * as smartrule from '../ts/index.js';
2020-01-20 08:47:35 +00:00
2020-01-20 14:41:27 +00:00
interface ITestMessage {
id: string;
body: string;
}
let testSmartruleInstance: smartrule.SmartRule<ITestMessage>;
2020-01-20 08:47:35 +00:00
tap.test('first test', async () => {
2020-01-20 14:41:27 +00:00
testSmartruleInstance = new smartrule.SmartRule<ITestMessage>();
testSmartruleInstance.createRule(
2020-01-23 15:24:46 +00:00
2,
2022-08-07 09:19:43 +00:00
async (messageArg) => {
2020-01-20 14:41:27 +00:00
if (messageArg.body.startsWith('hello')) {
return 'apply-stop';
}
},
2022-08-07 09:19:43 +00:00
async (messageArg) => {
2020-01-20 14:41:27 +00:00
console.log(`rule triggered for message with body ${messageArg.body}`);
}
);
});
tap.test('make a decision based on an object', async () => {
testSmartruleInstance.makeDecision({
id: '123456',
2022-08-07 09:19:43 +00:00
body: 'hello, there. This is a cool message!',
2020-01-24 07:11:25 +00:00
});
2020-01-20 08:47:35 +00:00
});
tap.start();