tests added

This commit is contained in:
Wolfgang Hottgenroth 2017-08-10 16:47:50 +02:00
parent e857b7baa7
commit 49a6a46052
3 changed files with 70 additions and 44 deletions

View File

@ -4,7 +4,7 @@ import {MeterbusLibExceptions} from './exceptions'
import {MeterbusLibFrames} from './simpleframes'
import {MeterbusLibCodeTables} from './codetables'
import * as mocha from 'mocha'
import * as chai from 'chai'
@ -43,7 +43,7 @@ let inputOKControlframe = "68 03 03 68 01 02 03 06 16"
let inputNOKControlframe_wrong_stopcode = "68 03 03 68 01 02 03 06 15"
let inputNOKControlframe_wrong_secondlength = "68 03 04 68 01 02 03 06 16"
let inputNOKLongframe_too_short = "68 02 02 68 01 02 03 16"
let inputNOk_wrong_startcode = "15 01 02 03 16"
@ -138,47 +138,48 @@ describe('The Meterbus Library', () => {
telegram.parse()
expect((telegram.frame as MeterbusLibFrames.ControlFrame).ciField).to.equal(3)
})
})
describe('The Meterbus Longframe Library', () => {
let telegram : MeterbusLib.Telegram
beforeEach(() => {
telegram = new MeterbusLib.Telegram()
telegram.fromHexString(inputOkLongFrame_1phase_electric)
telegram.parse()
})
it('should find the identNo', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.identNo)
.to.equal(17001300)
})
it('should find the manufacturer', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.manufacturer)
.to.equal("FIN")
})
it('should find the version', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.version)
.to.equal(0x24)
})
it('should find the medium', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.medium)
.to.equal("Electrity")
})
it('should find the accessNo', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.accessNo)
.to.equal(0xd6)
})
it('should find the status', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.status)
.to.equal(0)
})
it('should find the signature', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.signature)
.to.deep.equal([0,0])
})
it('should prepare itself as JSON', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).getJSON()).to.equal(json_1phase_electric)
})
describe('The Meterbus Longframe Library', () => {
let telegram : MeterbusLib.Telegram
beforeEach(() => {
telegram = new MeterbusLib.Telegram()
telegram.fromHexString(inputOkLongFrame_1phase_electric)
telegram.parse()
})
})
it('should find the identNo', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.identNo)
.to.equal(17001300)
})
it('should find the manufacturer', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.manufacturer)
.to.equal("FIN")
})
it('should find the version', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.version)
.to.equal(0x24)
})
it('should find the medium', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.medium)
.to.equal("Electrity")
})
it('should find the accessNo', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.accessNo)
.to.equal(0xd6)
})
it('should find the status', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.status)
.to.equal(0)
})
it('should find the signature', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).fixedDataHeader.signature)
.to.deep.equal([0,0])
})
it('should prepare itself as JSON', () => {
expect((telegram.frame as MeterbusLibLongFrame.LongFrame).getJSON()).to.equal(json_1phase_electric)
})
})

View File

@ -1,6 +1,8 @@
import {MeterbusLibExceptions} from './exceptions'
import {MeterbusLibFrames} from './simpleframes'
import {MeterbusLibLongFrame} from './longframe'
import {MeterbusLibUtils} from './utils'
export namespace MeterbusLib {

View File

@ -26,3 +26,26 @@ describe('The Meterbus Library Utils', () => {
expect(MeterbusLibUtils.manufCode([0x2e, 0x19])).to.equal("FIN")
})
})
describe('The jsonPrepare function in the Meterbus Library Utils', () => {
it('should forward regular properties of an object', () => {
let objIn = {'a': 1, 'b':2}
let objOut = objIn
expect(MeterbusLibUtils.jsonPrepaper(objIn, [])).to.deep.equal(objOut)
})
it('should hide properties in the hide list', () => {
let objIn = {'a': 1, 'b':2}
let objOut = {'a': 1}
expect(MeterbusLibUtils.jsonPrepaper(objIn, ['b'])).to.deep.equal(objOut)
})
it('should hide properties beginning with two underscores', () => {
let objIn = {'a': 1, '__b':2}
let objOut = {'a': 1}
expect(MeterbusLibUtils.jsonPrepaper(objIn, [])).to.deep.equal(objOut)
})
it('should remove one leading underscore from property names', () => {
let objIn = {'_a': 1, 'b':2}
let objOut = {'a': 1, 'b':2}
expect(MeterbusLibUtils.jsonPrepaper(objIn, [])).to.deep.equal(objOut)
})
})