-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
936bf15
commit 5d5a8fa
Showing
6 changed files
with
100 additions
and
44 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,49 +1,94 @@ | ||
import { parseMessage } from './meshbir'; | ||
|
||
describe('parseMessage', () => { | ||
it('should parse a position', () => { | ||
expect( | ||
parseMessage({ | ||
type: 'position', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
time: 123456, | ||
latitude: 32.1927, | ||
longitude: 76.4506, | ||
altitude: 1778.12, | ||
ground_speed: 30, | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"altitude": 1778.12, | ||
"ground_speed": 30, | ||
"latitude": 32.1927, | ||
"longitude": 76.4506, | ||
"time": 123456, | ||
"type": "position", | ||
"user_id": "12345678-1234-1234-1234-123456789012", | ||
} | ||
`); | ||
}); | ||
describe('valid messages', () => { | ||
it('should parse a position', () => { | ||
expect( | ||
parseMessage({ | ||
type: 'position', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
time: 123456, | ||
latitude: 32.1927, | ||
longitude: 76.4506, | ||
altitude: 1778.12, | ||
ground_speed: 30, | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"altitude": 1778.12, | ||
"ground_speed": 30, | ||
"latitude": 32.1927, | ||
"longitude": 76.4506, | ||
"time": 123456, | ||
"type": "position", | ||
"user_id": "12345678-1234-1234-1234-123456789012", | ||
} | ||
`); | ||
}); | ||
|
||
it('should parse a text message', () => { | ||
expect( | ||
parseMessage({ | ||
type: 'message', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
time: 123456, | ||
message: 'hello Meshtastic', | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"message": "hello Meshtastic", | ||
"time": 123456, | ||
"type": "message", | ||
"user_id": "12345678-1234-1234-1234-123456789012", | ||
} | ||
`); | ||
}); | ||
|
||
it('should parse a test', () => { | ||
expect( | ||
parseMessage({ | ||
type: 'message', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
time: 123456, | ||
message: 'hello Meshtastic', | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"message": "hello Meshtastic", | ||
"time": 123456, | ||
"type": "message", | ||
"user_id": "12345678-1234-1234-1234-123456789012", | ||
} | ||
`); | ||
it('should allow extra fields', () => { | ||
expect( | ||
parseMessage({ | ||
type: 'message', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
time: 123456, | ||
message: 'hello Meshtastic', | ||
extra: 123, | ||
}), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"message": "hello Meshtastic", | ||
"time": 123456, | ||
"type": "message", | ||
"user_id": "12345678-1234-1234-1234-123456789012", | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
it('should throw on invalid message', () => { | ||
expect(() => parseMessage({ type: 'unkown' })).toThrow(); | ||
describe('invalid messages', () => { | ||
it('should throw on invalid message', () => { | ||
expect(() => parseMessage({ type: 'unkown' })).toThrowErrorMatchingInlineSnapshot(`"Invalid message format"`); | ||
}); | ||
|
||
it('should throw on invalid values', () => { | ||
expect(() => | ||
parseMessage({ | ||
type: 'message', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
time: '123456', // should be a number | ||
message: 'hello Meshtastic', | ||
}), | ||
).toThrowErrorMatchingInlineSnapshot(`"Invalid message format"`); | ||
}); | ||
|
||
it('should throw on missing values', () => { | ||
expect(() => | ||
parseMessage({ | ||
type: 'message', | ||
user_id: '12345678-1234-1234-1234-123456789012', | ||
//time: 123456, | ||
message: 'hello Meshtastic', | ||
}), | ||
).toThrowErrorMatchingInlineSnapshot(`"Invalid message format"`); | ||
}); | ||
}); | ||
}); |
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