Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added slip chars handling, Added tests (#15)
* Added tests, added slip chars handling * replaced raw payload from test data with bytes
- Loading branch information
Showing
9 changed files
with
9,403 additions
and
5,346 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
transform: {'^.+\\.ts?$': 'ts-jest'}, | ||
testEnvironment: 'node', | ||
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { SerialPacket } from '../src/SerialPacket'; | ||
|
||
describe('decode payload', function () { | ||
it('wrong message decode', function () { | ||
let bytes = [ | ||
0, 1, 57, 219, 221, 2, // HEADER | ||
// PAYLOAD | ||
1, 47, 115, 104, 97, 114, 101, 47, 104, 105, | ||
115, 116, 111, 114, 105, 99, 97, 108, 68, 97, | ||
116, 97, 47, 0, 1, 51, 52, 0, 1, 103, 108, 50, | ||
0, 1, 103, 108, 0, 1, 99, 101, 108, 115, 105, | ||
117, 115, 0, 192 | ||
]; | ||
|
||
let rawPayload = ''; | ||
for (let i = 0; i < bytes.length; i++) { | ||
rawPayload += (String.fromCharCode(bytes[i])) | ||
} | ||
let result = SerialPacket.dataToSerialPacket(rawPayload); | ||
expect(result.payload).toMatchObject(["/share/historicalData/", "34", "gl2", "gl", "celsius"]); | ||
}) | ||
it('correct message decode', function () { | ||
let bytes = [ | ||
0, 1, 63, 104, 2, // HEADER correct | ||
// PAYLOAD | ||
1, 47, 115, 104, 97, 114, 101, 47, 104, 105, | ||
115, 116, 111, 114, 105, 99, 97, 108, 68, 97, | ||
116, 97, 47, 0, 1, 51, 53, 0, 1, 103, 108, 49, | ||
0, 1, 103, 108, 0, 1, 99, 101, 108, 115, 105, | ||
117, 115, 0, 192 | ||
]; | ||
let rawPayload = ''; | ||
for (let i = 0; i < bytes.length; i++) { | ||
rawPayload += (String.fromCharCode(bytes[i])) | ||
} | ||
let result = SerialPacket.dataToSerialPacket(rawPayload); | ||
expect(result.payload).toMatchObject(["/share/historicalData/", "35", "gl1", "gl", "celsius"]); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters