-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from jbrunton/extract-message-parser
refactor: extract message parser
- Loading branch information
Showing
4 changed files
with
60 additions
and
11 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
36 changes: 36 additions & 0 deletions
36
services/api/src/domain/usecases/messages/parse-message.spec.ts
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,36 @@ | ||
import { parseMessage } from './parse-message'; | ||
|
||
describe('parseMessage', () => { | ||
const roomId = 'room-id'; | ||
const authorId = 'user-id'; | ||
|
||
it('parses commands', () => { | ||
expect( | ||
parseMessage({ content: '/lorem 3 words', roomId, authorId }), | ||
).toEqual({ | ||
canonicalInput: '/lorem 3 words', | ||
roomId, | ||
tokens: ['lorem', '3', 'words'], | ||
}); | ||
}); | ||
|
||
it('ignores excess whitespace in commands', () => { | ||
expect( | ||
parseMessage({ content: '/lorem 3 words', roomId, authorId }), | ||
).toEqual({ | ||
canonicalInput: '/lorem 3 words', | ||
roomId, | ||
tokens: ['lorem', '3', 'words'], | ||
}); | ||
}); | ||
|
||
it('parses normal messages', () => { | ||
expect( | ||
parseMessage({ content: 'Hello, World!', roomId, authorId }), | ||
).toEqual({ | ||
content: 'Hello, World!', | ||
roomId, | ||
authorId, | ||
}); | ||
}); | ||
}); |
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