Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests with coverage
run: npm run coverage

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/coverage
/dist
/docs/api
.DS_Store
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
[![codecov](https://codecov.io/gh/wayofthefuture/ais-nmea-decoder/graph/badge.svg)](https://codecov.io/gh/wayofthefuture/ais-nmea-decoder)

### *Currently under development...

Expand Down
37 changes: 37 additions & 0 deletions src/ais-decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,43 @@ describe('error cases', () => {
const result = decoder.parse('!AIVDM,2,3,,,hi,*57');
expect(result.error).toBe('Invalid fragment number for two-part message.');
});

it('should return error in case of invalid message type', () => {
const result = decoder.parse(`!AIVDM,1,1,1,1,w,*20`); // w is mtype 63
expect(result.error).toBe('Invalid message type: 63');
})
})

describe('error cases for seconds session', () => {
it('should return missing part 1 when sending only the second part', () => {
const result = decoder.parse('!AIVDM,2,2,,,hi,*56');
expect(result.error).toBe('Part 1 missing from two-part message.');
})

it('should return message too old when there is a time gap in the sequence', async () => {
decoder.parse('!AIVDM,2,1,,,hi,*55');
await new Promise(resolve => setTimeout(resolve, 4000)); // 4 seconds delay
const result2 = decoder.parse('!AIVDM,2,2,,,hi,*56');
expect(result2.error).toBe('Part 2 message is too old relative to part 1.');
})

it('should return error when second message prefix does not match the first one', () => {
decoder.parse('!AIVDM,2,1,,,hi,*55');
const result2 = decoder.parse('!AIVDO,2,2,,,hi,*54');
expect(result2.error).toBe('Part 2 message does not match part 1 message prefix.');
})

it('should return error when second message sequence id does not match the first one', () => {
decoder.parse('!AIVDM,2,1,seq1,,hi,*03');
const result2 = decoder.parse('!AIVDM,2,2,seq2,,hi,*03');
expect(result2.error).toBe('Part 2 message sequence id does not match part 1 sequence id.');
})

it('should return error when second message channel id does not match the first one', () => {
decoder.parse('!AIVDM,2,1,seq1,channel1,hi,*51');
const result2 = decoder.parse('!AIVDM,2,2,seq1,channel2,hi,*51');
expect(result2.error).toBe('Part 2 message channel does not match part 1 channel.');
})
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

})

describe('isNumeric', () => {
Expand Down
Loading
Loading