Skip to content

Commit

Permalink
v1.0.0 (#2)
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
connellr023 authored Dec 28, 2023
2 parents d432835 + 0c0b21f commit fa47e1f
Show file tree
Hide file tree
Showing 39 changed files with 1,390 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

*/coverage

/chatter-api/src/build/

# Logs
logs
*.log
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The test suite for the API includes **unit** and **networking** tests in order t

<br />

### Client Test Suite `WIP`
### Client Test Suite
The client test suite is also visible in the **Actions** tab. Otherwise, run the following commands,
```bash
cd chatter-client
Expand All @@ -48,6 +48,24 @@ npm run test
```
<br />

### Building
This web app is not currently deployed. However, in order to do so, build the client by,
```bash
cd chatter-client
```
```bash
npm run build
```
This will create a directory called `build` in `chatter-api/src` containing the static webpage. The hostname and port
the client will attempt to connect to is `localhost:8000` by default. If the server is not able to run on port `8000`, then
this can be changed in `stream.ts`. The server API attempts to host on `process.env.PORT` or `8000` if not set. The server API
can be run in production mode by,
```bash
npm run start
```

<br />

### Tools
- The server API was built with **express.js** and **socket.io** and tested with **Jest**.
- The client was built with the **Vue** framework and tested with **Vitest**.
Expand Down
10 changes: 9 additions & 1 deletion chatter-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ import ChatRoomFactory from "./lib/ChatRoomFactory";
import Logger from "./lib/Logger";
import express, {Application} from "express";
import Stream from "./stream/Stream";
import path from "node:path";
import cors from "cors";

import {Server, type Socket} from "socket.io";
import {config, StreamEvents} from "./lib/utility";

const port: number = config.DEV_PORT;
const port: number = (process.env["PORT"] as any) || config.DEV_PORT;

// Setup express
const app: Application = express();

app.use(cors());

// HTTP Routing (Vue project must be built in the src folder)
app.use("/", express.static(path.join(__dirname, "build")));

app.get("*", (req, res): void => {
res.sendFile(path.join(__dirname, "build", "index.html"));
});

// Setup HTTP server
const server: http.Server = app.listen(port, (): void => {
Logger.ok(`Server started on port ${port}`);
Expand Down
10 changes: 5 additions & 5 deletions chatter-api/tests/networking/Stream.net.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ afterAll((): void => {
clientSocket2.disconnect();
});

test("Test receive user data success", (done): void => {
test("Receive user data success", (done): void => {
const data: UserDataObject = {
username: "alice"
};
Expand All @@ -61,7 +61,7 @@ test("Test receive user data success", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, data);
});

test("Test receive bad user data with name too long", (done): void => {
test("Receive bad user data with name too long", (done): void => {
const data: UserDataObject = {
username: "sjdoifjiodsfgiodfjiogdf"
};
Expand All @@ -74,7 +74,7 @@ test("Test receive bad user data with name too long", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, data);
});

test("Test receive bad user data with name too short", (done): void => {
test("Receive bad user data with name too short", (done): void => {
const data: UserDataObject = {
username: ""
};
Expand All @@ -87,7 +87,7 @@ test("Test receive bad user data with name too short", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, data);
});

test("Test receive garbage user data", (done): void => {
test("Receive garbage user data", (done): void => {
const data: {} = {};

clientSocket1.once(StreamEvents.SERVER_SEND_STATUS, (status: StatusObject): void => {
Expand All @@ -98,7 +98,7 @@ test("Test receive garbage user data", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, data);
});

test("Test receive room encodings", (done): void => {
test("Send room encodings", (done): void => {
const r1: AbstractChatRoom = ChatRoomFactory.instantiate("1");
const r2: AbstractChatRoom = ChatRoomFactory.instantiate("34");
const r3: AbstractChatRoom = ChatRoomFactory.instantiate("private", false);
Expand Down
20 changes: 10 additions & 10 deletions chatter-api/tests/networking/chat.net.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ afterAll((): void => {
clientSocket2.disconnect();
});

test("Test clients receive updated list of connected users on client connect with GlobalChatRoom", (done): void => {
test("Clients receive updated list of connected users on client connect with GlobalChatRoom", (done): void => {
const globalRoom: AbstractChatRoom = ChatRoomFactory.instantiate("t1");

const user1: UserDataObject = {username: "arhp"};
Expand Down Expand Up @@ -93,7 +93,7 @@ test("Test clients receive updated list of connected users on client connect wit
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, user1);
});

test("Test only correct clients receive updated list of connected users on client connect with PrivateChatRoom", (done): void => {
test("Only correct clients receive updated list of connected users on client connect with PrivateChatRoom", (done): void => {
const privateRoom: AbstractChatRoom = ChatRoomFactory.instantiate("t1", false);

const user1: UserDataObject = {username: "finger"};
Expand Down Expand Up @@ -136,7 +136,7 @@ test("Test only correct clients receive updated list of connected users on clien
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, user1);
});

test("Test clients receive updated list of connected users on client disconnect with GlobalChatRoom", (done): void => {
test("Clients receive updated list of connected users on client disconnect with GlobalChatRoom", (done): void => {
const room: AbstractChatRoom = ChatRoomFactory.instantiate("test");
const user1: UserDataObject = {username: "crisp"};
const user2: UserDataObject = {username: "hp123"};
Expand Down Expand Up @@ -173,9 +173,9 @@ test("Test clients receive updated list of connected users on client disconnect
clientSocket1.emit(StreamEvents.CLIENT_SEND_USERDATA, user1);
});

test("Test receive valid chat message with GlobalChatRoom", (done): void => {
test("Receive valid chat message with GlobalChatRoom", (done): void => {
const room: AbstractChatRoom = ChatRoomFactory.instantiate("test");
const message: string = "test message";
const message: string = "message";
const user: UserDataObject = {username: "alice"};
const chat: ChatObject = {roomId: 0, text: message};

Expand All @@ -196,11 +196,11 @@ test("Test receive valid chat message with GlobalChatRoom", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_CHAT, chat);
});

test("Test only clients in room receive chat message with GlobalChatRoom", (done): void => {
test("Only clients in room receive chat message with GlobalChatRoom", (done): void => {
const r1: AbstractChatRoom = ChatRoomFactory.instantiate("test1");
const r2: AbstractChatRoom = ChatRoomFactory.instantiate("test1");

const message: string = "test message";
const message: string = "message";
const chat: ChatObject = {roomId: 0, text: message};

const user1: UserDataObject = {username: "phinger01"};
Expand Down Expand Up @@ -236,7 +236,7 @@ test("Test only clients in room receive chat message with GlobalChatRoom", (done
clientSocket1.emit(StreamEvents.CLIENT_SEND_CHAT, chat);
});

test("Test receive message too long with GlobalChatRoom", (done): void => {
test("Receive message too long with GlobalChatRoom", (done): void => {
const r1: AbstractChatRoom = new AbstractChatRoomStub("test1", 50);
const message: string = "dhfguidfifodshjiodfhgfdiuohjgifodfigduohosjsdklsdlf";
const user: UserDataObject = {username: "bob"};
Expand All @@ -263,7 +263,7 @@ test("Test receive message too long with GlobalChatRoom", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_CHAT, chat);
});

test("Test receive message too short with GlobalChatRoom", (done): void => {
test("Receive message too short with GlobalChatRoom", (done): void => {
const r1: AbstractChatRoom = ChatRoomFactory.instantiate("test");
const message: string = "";
const user: UserDataObject = {username: "frank"};
Expand All @@ -290,7 +290,7 @@ test("Test receive message too short with GlobalChatRoom", (done): void => {
clientSocket1.emit(StreamEvents.CLIENT_SEND_CHAT, chat);
});

test("Test receive garbage message with GlobalChatRoom", (done): void => {
test("Receive garbage message with GlobalChatRoom", (done): void => {
const r1: AbstractChatRoom = ChatRoomFactory.instantiate("test");
const message: string = null;
const user: UserDataObject = {username: "frank"};
Expand Down
16 changes: 8 additions & 8 deletions chatter-api/tests/unit/AbstractChatRoom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@ beforeEach((): void => {
room = new AbstractChatRoomStub("stub", 0);
});

test("Test verifyClientMessage() with valid message", (): void => {
test("verifyClientMessage() returns successful status object with valid message", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 0, text: "sample"})

expect(result.success).toBe(true);
});

test("Test verifyClientMessage() with wrong room ID", (): void => {
test("verifyClientMessage() returns unsuccessful status object with wrong room ID", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 1, text: "sample"})

expect(result.success).toBe(false);
});

test("Test verifyClientMessage() with garbage data", (): void => {
test("verifyClientMessage() returns unsuccessful status object with garbage data", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 0, text: null})

expect(result.success).toBe(false);
});

test("Test verifyClientMessage() message text 1 character too long", (): void => {
test("verifyClientMessage() returns unsuccessful status object message text 1 character too long", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 0, text: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1"})

expect(result.success).toBe(false);
});

test("Test verifyClientMessage() with message exactly at maximum length", (): void => {
test("verifyClientMessage() returns successful status object with message exactly at maximum length", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 0, text: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"})

expect(result.success).toBe(true);
});

test("Test verifyClientMessage() with message 1 character too short", (): void => {
test("verifyClientMessage() returns unsuccessful status object with message 1 character too short", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 0, text: ""})

expect(result.success).toBe(false);
});

test("Test verifyClientMessage() with message exactly at minimum length", (): void => {
test("verifyClientMessage() returns successful status object with message exactly at minimum length", (): void => {
const result: StatusObject = room.verifyClientMessage({roomId: 0, text: "a"})

expect(result.success).toBe(true);
});

test("Test encodeConnections()", (): void => {
test("encodeConnections()", (): void => {
const c: Client = new Client(null, "arhp");

try {
Expand Down
8 changes: 4 additions & 4 deletions chatter-api/tests/unit/ChatRoomFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ beforeEach((): void => {
ChatRoomFactory.reset();
});

test("Test unique ID assignment", (): void => {
test("Unique ID assignment", (): void => {
const f1: AbstractChatRoom = ChatRoomFactory.instantiate("1");
const f2: AbstractChatRoom = ChatRoomFactory.instantiate("2");

expect(f1.getID()).not.toEqual(f2.getID());
});

test("Test memberOf() with global chat rooms", (): void => {
test("memberOf() with global chat rooms", (): void => {
const f1: AbstractChatRoom = ChatRoomFactory.instantiate("1");
const f2: AbstractChatRoom = ChatRoomFactory.instantiate("2");

Expand All @@ -36,7 +36,7 @@ test("Test memberOf() with global chat rooms", (): void => {
expect(ChatRoomFactory.memberOf(c)).toStrictEqual(expected);
});

test("Test memberOf() with private chat rooms", (): void => {
test("memberOf() with private chat rooms", (): void => {
const f1: AbstractChatRoom = ChatRoomFactory.instantiate("1", false);
const f2: AbstractChatRoom = ChatRoomFactory.instantiate("2", false);

Expand All @@ -57,7 +57,7 @@ test("Test memberOf() with private chat rooms", (): void => {
expect(ChatRoomFactory.memberOf(c)).toStrictEqual(expected);
});

test("Test encode()", (): void => {
test("encode()", (): void => {
const f1: AbstractChatRoom = ChatRoomFactory.instantiate("1");
const f2: AbstractChatRoom = ChatRoomFactory.instantiate("2", false);

Expand Down
20 changes: 10 additions & 10 deletions chatter-api/tests/unit/Stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ beforeEach((): void => {
stream = new Stream(io);
});

test("Test attach() with multiple observers to single event", (): void => {
test("attach() with multiple observers to single event", (): void => {
const o1: IStreamObserver = new IStreamObserverStub();
const o2: IStreamObserver = new IStreamObserverStub();

Expand All @@ -23,7 +23,7 @@ test("Test attach() with multiple observers to single event", (): void => {
expect(stream.getObserverMap()).toStrictEqual(expected);
});

test("Test attach() with multiple observers to multiple events", (): void => {
test("attach() with multiple observers to multiple events", (): void => {
const o1: IStreamObserver = new IStreamObserverStub();
const o2: IStreamObserver = new IStreamObserverStub();
const o3: IStreamObserver = new IStreamObserverStub();
Expand All @@ -37,7 +37,7 @@ test("Test attach() with multiple observers to multiple events", (): void => {
expect(stream.getObserverMap()).toStrictEqual(expected);
});

test("Test getEachObserver() has no duplicate instances", (): void => {
test("getEachObserver() has no duplicate instances", (): void => {
const o1: IStreamObserver = new IStreamObserverStub();
const o2: IStreamObserver = new IStreamObserverStub();
const o3: IStreamObserver = o1;
Expand All @@ -52,21 +52,21 @@ test("Test getEachObserver() has no duplicate instances", (): void => {
expect(actual).toStrictEqual(expected);
});

test("Test onReceiveUser() with username too long", (): void => {
test("onReceiveUser() with username too long", (): void => {
const socket: Socket = null as Socket;
const status: StatusObject = stream.handleVerifyClient(socket, {username: "aaaaaaaaaaaaaaaa"});

expect(status.success).toBe(false);
});

test("Test onReceiveUser() with username too short", (): void => {
test("onReceiveUser() with username too short", (): void => {
const socket: Socket = null as Socket;
const status: StatusObject = stream.handleVerifyClient(socket, {username: ""});

expect(status.success).toBe(false);
});

test("Test notifyJoin()", (): void => {
test("notifyJoin() notifies only select observers properly", (): void => {
const o1: IStreamObserverStub = new IStreamObserverStub();
const o2: IStreamObserverStub = new IStreamObserverStub();

Expand Down Expand Up @@ -97,7 +97,7 @@ test("Test notifyJoin()", (): void => {
});
});

test("Test notifyConnect()", (): void => {
test("notifyConnect() notifies all observers properly", (): void => {
const o1: IStreamObserverStub = new IStreamObserverStub();
const o2: IStreamObserverStub = new IStreamObserverStub();

Expand All @@ -119,7 +119,7 @@ test("Test notifyConnect()", (): void => {
});
});

test("Test notifyDisconnect()", (): void => {
test("notifyDisconnect() notifies all observers properly", (): void => {
const o1: IStreamObserverStub = new IStreamObserverStub();
const o2: IStreamObserverStub = new IStreamObserverStub();

Expand All @@ -141,14 +141,14 @@ test("Test notifyDisconnect()", (): void => {
});
});

test("Test notifyClientMessage()", (): void => {
test("notifyClientMessage() notifies only select observers properly", (): void => {
const o1: IStreamObserverStub = new IStreamObserverStub();
const o2: IStreamObserverStub = new IStreamObserverStub();
const o3: IStreamObserverStub = new IStreamObserverStub();

const shouldReceive: IStreamObserverStub[] = [o1, o2];
const shouldNotReceive: IStreamObserverStub[] = [o3];
const expectedTrigger: string = "test message"
const expectedTrigger: string = "message"

stream.attach(0, o1, o2);
stream.attach(1, o3);
Expand Down
Loading

0 comments on commit fa47e1f

Please sign in to comment.