diff --git a/.github/workflows/clinic-microservice-ci.yml b/.github/workflows/clinic-microservice-ci.yml index c081f827..b6d67c56 100644 --- a/.github/workflows/clinic-microservice-ci.yml +++ b/.github/workflows/clinic-microservice-ci.yml @@ -5,9 +5,9 @@ name: Clinic CI on: push: - branches: [ "main" ] + branches: ['main'] pull_request: - branches: [ "main" ] + branches: ['main'] jobs: lint-and-test-clinic: @@ -17,6 +17,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Run Docker + run: docker-compose up -d + + - name: Wait for Kafka to be ready + run: npx wait-on tcp:127.0.0.1:${{ secrets.KAFKA_PORT }} && echo "Kafka is ready!" + - name: Setup Node.js uses: actions/setup-node@v2 with: @@ -33,6 +39,9 @@ jobs: - name: Run Tests (Clinic Microservice) run: npm run test working-directory: clinic + env: MONGO_URI_TEST: ${{ secrets.MONGO_URI_TEST }} - + ZOOKEEPER_PORT: ${{ secrets.ZOOKEEPER_PORT }} + KAFKA_PORT: ${{ secrets.KAFKA_PORT }} + ZOOKEEPER_HOST_NAME: ${{ secrets.ZOOKEEPER_HOST_NAME}} diff --git a/authentication/src/api/user.js b/authentication/src/api/user.js index 00d280c3..449a19dd 100644 --- a/authentication/src/api/user.js +++ b/authentication/src/api/user.js @@ -102,9 +102,6 @@ export const user = (app) => { } }); - // - - // app.delete('/users/:id', async (req, res) => { try { const userId = req.params.id; @@ -173,8 +170,9 @@ export const user = (app) => { } }); - app.post('/check-admin/:request', async (req, res) => { + app.post('/admins/:request', async (req, res) => { try { + let signupData = null; const requestFrom = req.params.request; // clinic, pharmacy const userName = req.body.userName; const email = req.body.email; @@ -203,21 +201,6 @@ export const user = (app) => { throw new Error('invalid system'); } - res.status(OK_REQUEST_CODE_200).end(); - } catch (error) { - if (error.response) { - res - .status(BAD_REQUEST_CODE_400) - .send({ message: error.response.data.errMessage }); - } else { - res.status(ERROR_STATUS_CODE).send({ message: error.message }); - } - } - }); - - app.post('/admins/:request', async (req, res) => { - try { - let signupData = null; switch (requestFrom) { case CLINIC_REQ: signupData = await axios.post(ADMIN_Clinic_SIGNUP_URL, req.body); diff --git a/authentication/src/tests/api-tests/AuthenticationAPI.test.js b/authentication/src/tests/api-tests/AuthenticationAPI.test.js index 94fe4304..bab7ba1c 100644 --- a/authentication/src/tests/api-tests/AuthenticationAPI.test.js +++ b/authentication/src/tests/api-tests/AuthenticationAPI.test.js @@ -173,8 +173,6 @@ describe('POST /admins/:request', () => { const type = PHARMACY_ADMIN_ENUM; const email = faker.internet.email(); - // const userId = faker.database.mongodbObjectId(); - // const userName = faker.internet.userName(); const user = new User(generateUser(userId, email, userName, type)); await user.save(); const res = await request(app).post(`/admins/${PHARMACY_REQ}`).send({ userId: userId, type: type, email: email, userName: userName, password: faker.internet.password() }); diff --git a/clinic/src/producers/AppointmentProducer.js b/clinic/src/producers/AppointmentProducer.js index be55114f..33c8c38d 100644 --- a/clinic/src/producers/AppointmentProducer.js +++ b/clinic/src/producers/AppointmentProducer.js @@ -5,17 +5,18 @@ import { OK_STATUS_CODE, } from '../utils/Constants.js'; -export const appointmentProducer = (app) => { - const client = new KafkaNode.KafkaClient({ kafkaHost: 'localhost:9092' }); - const producer = new KafkaNode.Producer(client); +const client = new KafkaNode.KafkaClient({ kafkaHost: 'localhost:9092' }); +const producer = new KafkaNode.Producer(client); + +const appointmentProducer = (app) => { const kafka_topic = 'notifications'; - producer.on('ready', async function () { - console.log('Appointment Producer is ready'); + producer.on('ready', function () { + console.log('Appointment producer is ready'); }); producer.on('error', function (err) { - console.log('Appointment Producer is in error state'); + console.log('Appointment producer is in error state'); console.log(err); }); @@ -58,3 +59,5 @@ export const appointmentProducer = (app) => { } }); }; + +export { appointmentProducer, producer }; diff --git a/clinic/src/utils/TestingUtils.js b/clinic/src/utils/TestingUtils.js index 81f045b8..aeff9e24 100644 --- a/clinic/src/utils/TestingUtils.js +++ b/clinic/src/utils/TestingUtils.js @@ -1,3 +1,4 @@ +const { producer } = require('../producers/AppointmentProducer.js'); const mongoose = require('mongoose'); const dotenv = require('dotenv'); dotenv.config(); @@ -14,6 +15,7 @@ const connectDBTest = async () => { const disconnectDBTest = async () => { try { + producer.close(); const collections = mongoose.connection.collections; for (const key in collections) { diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..e2add088 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + zookeeper: + image: wurstmeister/zookeeper + ports: + - ${ZOOKEEPER_PORT}:${ZOOKEEPER_PORT} + environment: + - ALLOW_ANONYMOUS_LOGIN=yes + + kafka: + image: wurstmeister/kafka + container_name: kafka + ports: + - ${KAFKA_PORT}:${KAFKA_PORT} + volumes: + - ./data/kafka:/var/run/docker.sock + environment: + - KAFKA_BROKER_ID=1 + - KAFKA_LISTENERS=PLAINTEXT://:${KAFKA_PORT} + - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:${KAFKA_PORT} + - KAFKA_ZOOKEEPER_CONNECT=${ZOOKEEPER_HOST_NAME}:${ZOOKEEPER_PORT} + - KAFKA_CREATE_TOPICS=notifications:1:1,out_of_stock:1:1 + - ALLOW_PLAINTEXT_LISTENER=yes + depends_on: + - zookeeper