diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..11c92b7035 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,74 @@ +name: Run Tests + +on: + push: + branches: + - main + - staging + pull_request: + branches: + - main + - staging + +jobs: + test: + 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 + env: + QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }} + USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }} + DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }} + USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }} + run: | + cd ./apps/frontend + echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env + echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env + + cd ../question-service + echo "FIREBASE_CREDENTIAL_PATH=$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 + + - name: Create Database Credential Files + env: + FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }} + FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }} + run: | + cd ./apps/question-service + echo "$FIREBASE_JSON" > "./$FIREBASE_CREDENTIAL_PATH" + + - name: Build and Run Services + run: | + cd ./apps + docker-compose up --build -d + + - name: Wait for services to be ready + run: sleep 30 + + - name: Run Tests + env: + FRONTEND_URL: ${{ vars.FRONTEND_URL }} + USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }} + QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }} + run: | + curl -sSL -o /dev/null $QUESTION_SERVICE_URL + curl -fsSL -o /dev/null $USER_SERVICE_URL + curl -fsSL -o /dev/null $FRONTEND_URL + + # We can add more tests here diff --git a/apps/frontend/.env.example b/apps/frontend/.env.example index e9374508e5..a6c274c271 100644 --- a/apps/frontend/.env.example +++ b/apps/frontend/.env.example @@ -1,3 +1,3 @@ -# Replace with the corresponding url, credentials and endpoint +# URL endpoints of the services NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080/" NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/" \ No newline at end of file diff --git a/apps/question-service/.env.example b/apps/question-service/.env.example index 2acc980209..88d758a7be 100644 --- a/apps/question-service/.env.example +++ b/apps/question-service/.env.example @@ -1,3 +1,4 @@ +# Path to the firebase credential json FIREBASE_CREDENTIAL_PATH=cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json # Secret for creating JWT signature diff --git a/apps/user-service/.env.sample b/apps/user-service/.env.sample index b3518e0224..e8f773b6d4 100644 --- a/apps/user-service/.env.sample +++ b/apps/user-service/.env.sample @@ -1,9 +1,8 @@ +# Mongo DB connection URL DB_CLOUD_URI= -DB_LOCAL_URI=mongodb://127.0.0.1:27017/peerprepUserServiceDB -PORT=3001 -# Will use cloud MongoDB Atlas database -ENV=PROD +# Port for the user-service +PORT=3001 # Secret for creating JWT signature JWT_SECRET=you-can-replace-this-with-your-own-secret diff --git a/apps/user-service/model/repository.js b/apps/user-service/model/repository.js index 5d56b91e71..feeb8ac1a9 100644 --- a/apps/user-service/model/repository.js +++ b/apps/user-service/model/repository.js @@ -3,12 +3,9 @@ import "dotenv/config"; import { connect } from "mongoose"; export async function connectToDB() { - let mongoDBUri = - process.env.ENV === "PROD" - ? process.env.DB_CLOUD_URI - : process.env.DB_LOCAL_URI; + let mongoDBUri = process.env.DB_CLOUD_URI; - await connect(mongoDBUri); + await connect(mongoDBUri) } export async function createUser(username, email, password) { diff --git a/apps/user-service/package-lock.json b/apps/user-service/package-lock.json index b78445f96c..65a36b2df8 100644 --- a/apps/user-service/package-lock.json +++ b/apps/user-service/package-lock.json @@ -14,7 +14,7 @@ "dotenv": "^16.4.5", "express": "^4.21.0", "jsonwebtoken": "^9.0.2", - "mongoose": "^8.5.4" + "mongoose": "^8.7.0" }, "devDependencies": { "nodemon": "^3.1.4" @@ -40,9 +40,9 @@ } }, "node_modules/@mongodb-js/saslprep": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.8.tgz", - "integrity": "sha512-qKwC/M/nNNaKUBMQ0nuzm47b7ZYWQHN3pcXq4IIcoSBc2hOIrflAxJduIvvqmhoz3gR2TacTAs8vlsCVPkiEdQ==", + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.9.tgz", + "integrity": "sha512-tVkljjeEaAhCqTzajSdgbQ6gE6f3oneVwa3iXR6csiEwXXOFsiC6Uh9iAjAhXPtqa/XMDHWjjeNH/77m/Yq2dw==", "dependencies": { "sparse-bitfield": "^3.0.3" } @@ -1157,9 +1157,9 @@ } }, "node_modules/mongodb": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz", - "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.9.0.tgz", + "integrity": "sha512-UMopBVx1LmEUbW/QE0Hw18u583PEDVQmUmVzzBRH0o/xtE9DBRA5ZYLOjpLIa03i8FXjzvQECJcqoMvCXftTUA==", "dependencies": { "@mongodb-js/saslprep": "^1.1.5", "bson": "^6.7.0", @@ -1211,13 +1211,13 @@ } }, "node_modules/mongoose": { - "version": "8.5.4", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.5.4.tgz", - "integrity": "sha512-nG3eehhWf9l1q80WuHvp5DV+4xDNFpDWLE5ZgcFD5tslUV2USJ56ogun8gaZ62MKAocJnoStjAdno08b8U57hg==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.7.0.tgz", + "integrity": "sha512-rUCSF1mMYQXjXYdqEQLLlMD3xbcj2j1/hRn+9VnVj7ipzru/UoUZxlj/hWmteKMAh4EFnDZ+BIrmma9l/0Hi1g==", "dependencies": { "bson": "^6.7.0", "kareem": "2.6.3", - "mongodb": "6.7.0", + "mongodb": "6.9.0", "mpath": "0.9.0", "mquery": "5.0.0", "ms": "2.1.3", diff --git a/apps/user-service/package.json b/apps/user-service/package.json index 94174a115b..5d16cf9d59 100644 --- a/apps/user-service/package.json +++ b/apps/user-service/package.json @@ -21,6 +21,6 @@ "dotenv": "^16.4.5", "express": "^4.21.0", "jsonwebtoken": "^9.0.2", - "mongoose": "^8.5.4" + "mongoose": "^8.7.0" } } diff --git a/services/question-service/.gitignore b/services/question-service/.gitignore deleted file mode 100644 index 74b9fb5300..0000000000 --- a/services/question-service/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# please add all private keys here -cs3219-g24-staging-firebase-adminsdk-suafv-9c0d1b2299.json -cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json