Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: message types #229

Merged
merged 14 commits into from
Sep 22, 2024
Prev Previous commit
Next Next commit
refactor: rename
jbrunton committed Sep 22, 2024
commit 5e76adb0893cb4bf9948f93cad41798102ec45d3
1 change: 0 additions & 1 deletion services/api/src/app/messages/messages.service.spec.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import { SendMessageUseCase } from '@usecases/messages/send';
import { CommandService } from './command.service';
import { UnauthorizedException } from '@nestjs/common';
import { systemUser } from '@entities/users/system-user';
import { TokenizedCommand } from '@usecases/commands/parse/tokenize';
import { IncomingCommand } from '@entities/commands';

describe('MessagesService', () => {
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@ import { BadRequestException, Injectable } from '@nestjs/common';
import { ParsedCommand } from './parsed-command';
import {
TokenizedCommand,
tokenizeMessage,
} from '@usecases/commands/parse/tokenize';
tokenizeCommand,
} from '@usecases/commands/parse/tokenize-command';
import { commands } from '@usecases/commands/parse/commands';
import { IncomingCommand } from '@entities/commands';

@Injectable()
export class ParseCommandUseCase {
exec(command: IncomingCommand): ParsedCommand {
const tokenizedCommand = tokenizeMessage(command);
const tokenizedCommand = tokenizeCommand(command);

for (const command of commands) {
const result = command.parse(tokenizedCommand);
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { ContentPolicy, JoinPolicy } from '@entities/rooms/room';
import { BadRequestException } from '@nestjs/common';
import { equals } from 'rambda';
import { z, ZodIssue, ZodType } from 'zod';
import { TokenizedCommand } from '@usecases/commands/parse/tokenize';
import { TokenizedCommand } from '@usecases/commands/parse/tokenize-command';

/**
* A parsed command represents a valid command with type-safe parameters, and thus can be safely
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { tokenizeMessage } from '@usecases/commands/parse/tokenize';
import { tokenizeCommand } from '@usecases/commands/parse/tokenize-command';

describe('tokenizeMessage', () => {
describe('tokenizeCommand', () => {
const roomId = 'room-id';
const authorId = 'user-id';

it('tokenizes commands', () => {
expect(
tokenizeMessage({ content: '/lorem 3 words', roomId, authorId }),
tokenizeCommand({ content: '/lorem 3 words', roomId, authorId }),
).toEqual({
canonicalInput: '/lorem 3 words',
roomId,
@@ -16,7 +16,7 @@ describe('tokenizeMessage', () => {

it('derives a canonical form by ignoring excess whitespace', () => {
expect(
tokenizeMessage({ content: '/lorem 3 words', roomId, authorId }),
tokenizeCommand({ content: '/lorem 3 words', roomId, authorId }),
).toEqual({
canonicalInput: '/lorem 3 words',
roomId,
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IncomingMessage } from '@entities/messages/message';
import { IncomingCommand } from '@entities/commands';

/**
@@ -29,7 +28,7 @@ export type TokenizedCommand = {
* @param command The command to tokenize
* @returns The tokenized command
*/
export const tokenizeMessage = ({
export const tokenizeCommand = ({
content,
roomId,
}: IncomingCommand): TokenizedCommand => {