Skip to content

Test firebase emulator #66

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

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
483525f
setup jest
chiaryan Nov 1, 2024
53016e1
update action
chiaryan Nov 1, 2024
365616a
add trigger workflow-dispatch
chiaryan Nov 1, 2024
0d77bfe
asd
chiaryan Nov 1, 2024
ac09202
asd
chiaryan Nov 1, 2024
06b839c
asd
chiaryan Nov 1, 2024
1d0f6fe
asd
chiaryan Nov 1, 2024
54ad800
asd
chiaryan Nov 1, 2024
415161e
asd2
chiaryan Nov 1, 2024
8b054f7
asd
chiaryan Nov 1, 2024
62a72a9
asd
chiaryan Nov 1, 2024
547a2a1
unit testing for question api functions
chiaryan Nov 2, 2024
ed871a9
Merge branch 'staging' into frontend-unit-test
chiaryan Nov 2, 2024
97d6b6c
mock getToken for question.test.ts
chiaryan Nov 2, 2024
a23a7b4
add unit test for utils/encode
chiaryan Nov 2, 2024
435765a
Add testing workflow part 1..
chiaryan Nov 2, 2024
5a8f8ff
asd
chiaryan Nov 2, 2024
fdb4c1a
add "unit test" for ReadQuestion
chiaryan Nov 3, 2024
d047aa1
add test for not found
chiaryan Nov 3, 2024
ba541a5
update workflow to add credentials
chiaryan Nov 3, 2024
89577e4
asd
chiaryan Nov 3, 2024
07131a8
asd2
chiaryan Nov 3, 2024
f1a0e36
asd3
chiaryan Nov 3, 2024
0208df5
asd3
chiaryan Nov 3, 2024
77b8d46
asd4
chiaryan Nov 3, 2024
221d737
remove file
chiaryan Nov 3, 2024
75a5c35
Merge branch 'frontend-unit-test' into n11-unit-tests
chiaryan Nov 3, 2024
da6001d
fix test.yml
chiaryan Nov 3, 2024
c923f0c
test start firestore emulator
chiaryan Nov 4, 2024
e627706
asd
chiaryan Nov 4, 2024
2a9feeb
asd
chiaryan Nov 4, 2024
b0c13d3
asd
chiaryan Nov 4, 2024
0aed69e
asd
chiaryan Nov 4, 2024
1c6ae4c
asd
chiaryan Nov 4, 2024
0a9a483
asd
chiaryan Nov 4, 2024
44e2c54
try using emulator
chiaryan Nov 4, 2024
bc0d9ed
try start first
chiaryan Nov 4, 2024
8e67cd1
asd
chiaryan Nov 4, 2024
9bb66e8
asd
chiaryan Nov 4, 2024
c616fb6
asd
chiaryan Nov 4, 2024
33077b9
try exec
chiaryan Nov 4, 2024
f1e4d6f
asd
chiaryan Nov 4, 2024
de7dcb9
asd
chiaryan Nov 4, 2024
1cfaa33
asd
chiaryan Nov 4, 2024
2087509
asd
chiaryan Nov 4, 2024
647a2ac
try install firebase-tools
chiaryan Nov 4, 2024
35cc537
asd
chiaryan Nov 4, 2024
526db4a
asd
chiaryan Nov 4, 2024
c229de2
asd
chiaryan Nov 4, 2024
70f0bbb
asd
chiaryan Nov 4, 2024
ec6c9a0
update read_test
chiaryan Nov 4, 2024
707d862
Add helpers for test functions
chiaryan Nov 4, 2024
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
123 changes: 22 additions & 101 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,124 +10,45 @@ on:
branches:
- main
- staging
workflow_dispatch:

jobs:
test:
test-firebase:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose

- name: Create Environment Files
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up .env
env:
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
MATCHING_SERVICE_URL: ${{ vars.MATCHING_SERVICE_URL }}
HISTORY_SERVICE_URL: ${{ vars.HISTORY_SERVICE_URL }}
SIGNALLING_SERVICE_URL: ${{ vars.SIGNALLING_SERVICE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
HISTORY_FIREBASE_CREDENTIAL_PATH: ${{ vars.HISTORY_SERVICE_FIREBASE_CREDENTIAL_PATH }}
DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }}
USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }}
MATCHING_SERVICE_PORT: ${{ vars.MATCHING_SERVICE_PORT }}
HISTORY_SERVICE_PORT: ${{ vars.HISTORY_SERVICE_PORT }}
SIGNALLING_SERVICE_PORT: ${{ vars.SIGNALLING_SERVICE_PORT }}
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
REDIS_URL: ${{ vars.REDIS_URL }}
QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: |
cd ./apps/frontend
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_MATCHING_SERVICE_URL=$MATCHING_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_HISTORY_SERVICE_URL=$HISTORY_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_SIGNALLING_SERVICE_URL=$SIGNALLING_SERVICE_URL" >> .env

cd ../question-service
cd ./apps/question-service

echo "FIREBASE_CREDENTIAL_PATH=$QUESTION_FIREBASE_CREDENTIAL_PATH" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env

cd ../user-service
echo "DB_CLOUD_URI=$DB_CLOUD_URI" >> .env
echo "PORT=$USER_SERVICE_PORT" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env

cd ../matching-service
echo "PORT=$MATCHING_SERVICE_PORT" >> .env
echo "MATCH_TIMEOUT=$MATCHING_SERVICE_TIMEOUT" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
echo "REDIS_URL=$REDIS_URL" >> .env
echo "QUESTION_SERVICE_GRPC_URL=$QUESTION_SERVICE_GRPC_URL" >> .env

cd ../history-service
echo "FIREBASE_CREDENTIAL_PATH=$HISTORY_FIREBASE_CREDENTIAL_PATH" >> .env
echo "PORT=$HISTORY_SERVICE_PORT" >> .env

cd ../signalling-service
echo "PORT=$SIGNALLING_SERVICE_PORT" >> .env

- name: Create Database Credential Files

- name: Set up credentials
env:
QUESTION_FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
HISTORY_FIREBASE_JSON: ${{ secrets.HISTORY_SERVICE_FIREBASE_CREDENTIAL }}
HISTORY_FIREBASE_CREDENTIAL_PATH: ${{ vars.HISTORY_SERVICE_FIREBASE_CREDENTIAL_PATH }}
run: |
cd ./apps/question-service
echo "$QUESTION_FIREBASE_JSON" > "./$QUESTION_FIREBASE_CREDENTIAL_PATH"

cd ../history-service
echo "$HISTORY_FIREBASE_JSON" > "./$HISTORY_FIREBASE_CREDENTIAL_PATH"
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'

- name: Build and Run Services
- name: Install Go dependencies
run: |
cd ./apps
docker-compose up --build -d

- name: Wait for services to be ready
run: sleep 30
cd ./apps/question-service
go mod tidy

- name: Install websocat
run: |
sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
sudo chmod a+x /usr/local/bin/websocat
websocat --version
- name: Install firebase tools
run: curl -sL firebase.tools | bash

- name: Run Tests
env:
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
MATCHING_SERVICE_URL: ${{ vars.MATCHING_SERVICE_URL }}
HISTORY_SERVICE_URL: ${{ vars.HISTORY_SERVICE_URL }}
SIGNALLING_SERVICE_URL: ${{ vars.SIGNALLING_SERVICE_URL }}
run: |
echo "Testing Question Service..."
curl -sSL -o /dev/null $QUESTION_SERVICE_URL && echo "Question Service is up"
echo "Testing User Service..."
curl -fsSL -o /dev/null $USER_SERVICE_URL && echo "User Service is up"
echo "Testing Frontend..."
curl -fsSL -o /dev/null $FRONTEND_URL && echo "Frontend is up"
echo "Testing History Service..."
curl -fsSL -o /dev/null $HISTORY_SERVICE_URL && echo "History Service is up"
echo "Testing Matching Service..."
if ! (echo "Hello" | websocat $MATCHING_SERVICE_URL); then
echo "WebSocket for Matching Service is not live"
else
echo "WebSocket for Matching Service is live"
fi
# Add in test for matching service in the future
echo "Testing Signalling Service..."
if ! (echo "Hello" | websocat $SIGNALLING_SERVICE_URL); then
echo "WebSocket for Signalling Service is not live"
else
echo "WebSocket for Signalling Service is live"
fi
# We can add more tests here
- name: Try starting
run: firebase emulators:exec --only firestore 'cd ./apps/question-service; go test ./...'
9 changes: 9 additions & 0 deletions apps/frontend/__tests__/Datetime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { formatTime } from "@/utils/DateTime"

describe("datetime module", () => {
it("formats a time correctly", () => {
expect(formatTime(10)).toBe("00:10")
});
})


34 changes: 34 additions & 0 deletions apps/frontend/__tests__/dependencymocking.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { GetQuestions } from "@/app/services/question"
import { getToken } from "@/app/services/login-store";

const TOKEN = 'mocktoken';

jest.mock("@/app/services/login-store", () => {
return {
__esModule: true,
getToken: jest.fn(() => TOKEN)
};
})

beforeEach(() => {
global.fetch = jest.fn().mockResolvedValue({
async json() {
return {}
}
});
})

describe("mock", () => {

it("mocks correctly", async () => {
await GetQuestions()
expect(jest.mocked(getToken).mock.calls).toEqual([[]])
expect(jest.mocked(fetch).mock.calls[0][1]).toEqual({
"headers": {
"Authorization": `Bearer ${TOKEN}`,
},
"method": "GET",
})
});

})
Loading
Loading