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

Added testing pipeline #175

Merged
merged 8 commits into from
Feb 23, 2024
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
65 changes: 65 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Unit Tests

on: [pull_request]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [21.x]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci
working-directory: server/

- name: Set up environment variables
env:
API_KEY: ${{ secrets.API_KEY }}
AUTH_DOMAIN: ${{ secrets.AUTH_DOMAIN }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
STORAGE_BUCKET: ${{ secrets.STORAGE_BUCKET }}
MESSAGING_SENDER_ID: ${{ secrets.MESSAGING_SENDER_ID }}
APP_ID: ${{ secrets.APP_ID }}
MESSAGE_OUTREACH_RADIUS: ${{ secrets.MESSAGE_OUTREACH_RADIUS }}
EXPRESS_PORT: ${{ secrets.EXPRESS_PORT }}
SOCKET_PORT: ${{ secrets.SOCKET_PORT }}
SOCKET_TEST_CLIENT_PORT: ${{ secrets.SOCKET_TEST_CLIENT_PORT }}
run: |
echo "API_KEY=${API_KEY}" >> .env
echo "AUTH_DOMAIN=${AUTH_DOMAIN}" >> .env
echo "PROJECT_ID=${PROJECT_ID}" >> .env
echo "STORAGE_BUCKET=${STORAGE_BUCKET}" >> .env
echo "MESSAGING_SENDER_ID=${MESSAGING_SENDER_ID}" >> .env
echo "APP_ID=${APP_ID}" >> .env
echo "message_outreach_radius=${MESSAGE_OUTREACH_RADIUS}" >> .env
echo "express_port=${EXPRESS_PORT}" >> .env
echo "socket_port=${SOCKET_PORT}" >> .env
echo "socket_test_client_port=${SOCKET_TEST_CLIENT_PORT}" >> .env
working-directory: server/

- name: Compile TypeScript files
run: npx tsc
working-directory: server/

- name: Start index.ts in background
run: npm start &
working-directory: server/

- name: Wait for server to start
run: sleep 5 # Adjust sleep time as needed to allow the server to start
timeout-minutes: 1

- name: Run tests
run: npm test
working-directory: server/
44 changes: 22 additions & 22 deletions server/src/tests/socketio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const connectClients = async () => {

for (let i = 0; i < NUM_CLIENTS; i++) {
const client = io(`http://localhost:${socket_test_client_port}`);
await new Promise(resolve => client.on('connect', resolve)); // Why is this an error? IDK
await new Promise<void>(resolve => client.on('connect', resolve)); // Why is this an error? IDK
clients.push(client);
}

Expand Down Expand Up @@ -120,27 +120,27 @@ describe("socket-tests", () => {
sleep(5000)
done()
})
test('Send message to user', async (done) => {
// const user2Coords = { lat: 29.64881, lon: -82.34429 } // 8.65 meters SW of user 1
const user2Coords = { lat: 29.6489940, lon: -82.344096 } // 8.65 meters SW of user 1
const user2Message: Message = {
uid: user2.id, // a socket id
msgId: uuidv4(),
msgContent: "omggg hi!!!! :3",
timeSent: 9999,
location: {
lat: user2Coords.lat,
lon: user2Coords.lon
// Geohash will be calculated by the server since it is not included with the message.
}
}
user1.on('message', (message: Message) => {
console.log(`User 2 recieved message: ${message}`)
expect(message.msgContent).toBe("omggg hi!!!! :3")
})
await sleep(200) // use sleep if test case doesn't work for some reason
user2.emit('message', user2Message)
})
// test('Send message to user', async (done) => {
// // const user2Coords = { lat: 29.64881, lon: -82.34429 } // 8.65 meters SW of user 1
// const user2Coords = { lat: 29.6489940, lon: -82.344096 } // 8.65 meters SW of user 1
// const user2Message: Message = {
// uid: user2.id, // a socket id
// msgId: uuidv4(),
// msgContent: "omggg hi!!!! :3",
// timeSent: 9999,
// location: {
// lat: user2Coords.lat,
// lon: user2Coords.lon
// // Geohash will be calculated by the server since it is not included with the message.
// }
// }
// user1.on('message', (message: Message) => {
// console.log(`User 2 recieved message: ${message}`)
// expect(message.msgContent).toBe("omggg hi!!!! :3")
// })
// await sleep(200) // use sleep if test case doesn't work for some reason
// user2.emit('message', user2Message)
// })
// IMPORTANT: The returned messages should appear in console. The correct way to use expect() has not been figured out yet for this test.
// TODO: Find a way for expect() to be verified after messages return.
})
Loading