test.js 1008 Bytes
"use strict";

const should = require('should');
const patternRuleMatcher = require("./lib/pattern-rule-matcher");

describe("#pattern-rule-matcher", function() {

    describe('#mkios', function() {

        it('should return correct trx date', function() {
            const rules = [
                { "pattern": "pada\\s+(.+?) \\d" }
            ];

            patternRuleMatcher('Transaksi ke 811236393 pada  2018-08-01 16:40:57 senilai SimPATI: 5 gagal. Error 14: Nomer tidak ditemukan.', rules).should.equal('2018-08-01');
        })

        it('should return correct product', function() {
            const rules = [
                { "pattern": "senilai SimPATI: (\\d+) " },
                { "pattern": "senilai <\\d+> untuk"},
                { "pattern": "Transaksi bulk <(\\d+) IDR>"}
            ];

            patternRuleMatcher('Transaksi ke 811236393 pada  2018-08-01 16:40:57 senilai SimPATI: 5 gagal. Error 14: Nomer tidak ditemukan.', rules).should.equal('5');
        })

    })

})