test.js 1.93 KB
"use strict";
const should = require("should");
const reverseParser = require('./reverse-parser');

describe('#reverse-parser', function() {
    describe('#parseMessage', function() {

        describe('test with valid message', function () {
            const msg = 'IDPEL:2017-01-30 16:58:19,1BNS2550C539F5B40545,ERRY-FEBRIANTO,32024560198,32024560198,R1M/900,Rp ,kWh 24.40,Stroom/Token 4260-5779-4249-2925-9618,SUKSES';
            const data = reverseParser.parseMessage(msg);

            it('should to have correct nama pelanggan', function() {
                data.namapel.should.equal('ERRY-FEBRIANTO');
            })

            it('should to have correct tarif daya', function() {
                data.tarifdaya.should.equal('R1M/900VA');
            })

            it('should to have correct tarif', function() {
                data.tarif.should.equal('R1M');
            })

            it('should to have correct daya', function() {
                data.daya.should.equal('900VA');
            })

            it('should to have correct jumlah kwh', function() {
                data.jumlahkwh.should.equal('24.40');
            })
        })

        describe('test with invalid message', function () {
            const msg = '';
            const data = reverseParser.parseMessage(msg);

            it('should to have correct nama pelanggan', function() {
                should(data.namapel).not.be.ok();
            })

            it('should to have correct tarif daya', function() {
                should(data.tarifdaya).not.be.ok();
            })

            it('should to have correct tarif', function() {
                should(data.tarif).not.be.ok();
            })

            it('should to have correct daya', function() {
                should(data.daya).not.be.ok();
            })

            it('should to have correct jumlah kwh', function() {
                should(data.jumlahkwh).not.be.ok();
            })
        })

    })
})