-
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 #147 from jbrunton/private-rooms
feature: request join policy
- Loading branch information
Showing
21 changed files
with
438 additions
and
24 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
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
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 |
---|---|---|
|
@@ -159,7 +159,7 @@ describe('ParseCommandUseCase', () => { | |
it('validates the number of arguments', () => { | ||
withMessage('/set room join policy').expectError( | ||
'Error in command `/set room join policy`:', | ||
`* Received too few arguments. Expected: \`/set room join policy {'anyone', 'invite'}\``, | ||
`* Received too few arguments. Expected: \`/set room join policy {'anyone', 'request', 'invite'}\``, | ||
); | ||
}); | ||
}); | ||
|
@@ -189,6 +189,31 @@ describe('ParseCommandUseCase', () => { | |
}); | ||
}); | ||
|
||
describe('/approve request', () => { | ||
it('parses valid commands', () => { | ||
withMessage('/approve request [email protected]').expectCommand({ | ||
tag: 'approveRequest', | ||
params: { | ||
email: '[email protected]', | ||
}, | ||
}); | ||
}); | ||
|
||
it('validates the number of arguments', () => { | ||
withMessage('/approve request').expectError( | ||
'Error in command `/approve request`:', | ||
`* Received too few arguments. Expected: \`/approve request {email}\``, | ||
); | ||
}); | ||
|
||
it('validates the email', () => { | ||
withMessage('/approve request not-an-email').expectError( | ||
'Error in command `/approve request not-an-email`:', | ||
`* Argument 2 (\`not-an-email\`): Invalid email`, | ||
); | ||
}); | ||
}); | ||
|
||
it('responds if the command is unrecognised', () => { | ||
const command: Command = { | ||
roomId: 'my-room', | ||
|
16 changes: 16 additions & 0 deletions
16
services/api/src/domain/usecases/commands/parse/parsers/approve-request-parser.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,16 @@ | ||
import { z } from 'zod'; | ||
import { CommandParser, ParsedCommand } from '../command.parser'; | ||
|
||
const schema = z | ||
.tuple([z.literal('approve'), z.literal('request'), z.string().email()]) | ||
.transform<ParsedCommand>(([, , email]) => ({ | ||
tag: 'approveRequest', | ||
params: { email }, | ||
})); | ||
|
||
export const approveRequestParser = new CommandParser({ | ||
matchTokens: ['approve', 'request'], | ||
schema, | ||
signature: `/approve request {email}`, | ||
summary: 'approve pending request to join the room', | ||
}); |
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
Oops, something went wrong.