Skip to content

Commit

Permalink
Merge branch 'master' into questions-5
Browse files Browse the repository at this point in the history
  • Loading branch information
nt-nic committed Nov 13, 2023
2 parents 33baa6a + 6401cfc commit 77f3aa2
Show file tree
Hide file tree
Showing 22 changed files with 1,523 additions and 20 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/question-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Question Service CI

on:
push:
pull_request:

jobs:
build-and-run-server:
runs-on: ubuntu-latest
env:
ENV: PROD
PORT: 8004
DB_CLOUD_URI: ${{ secrets.DB_CLOUD_URI }}
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
working-directory: ./src/backend/question_backend
run: npm i
- name: Install typescript
working-directory: ./src/cypress
run: npm install --save-dev typescript
- name: Run test cases
working-directory: ./src
run: node backend/question_backend/index.js & npx cypress run --spec "cypress/e2e/question_api.cy.js"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/
src/backend/question_backend/.env
.env
docker-compose.yml
6 changes: 5 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import Signup from "./pages/Signup";
import ViewQuestions from "./pages/ViewQuestions";
import Settings from "./pages/Settings";
import UserProfile from "./pages/UserProfile";
import Home from "./pages/home";
import Home from './pages/home';
import MatchFound from "./components/matching_elements/matchFound"
import Room from "./pages/Room"
import ChatboxPage from "./pages/ChatboxPage";

// import Login from "./pages/Login";
// import Profile from "./components/profile";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
Expand Down Expand Up @@ -50,4 +52,6 @@ function App() {
);
}

// test commit

export default App;
2 changes: 1 addition & 1 deletion src/_env.file
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DATABASE_URL = "mongodb+srv://derrickkhoo2000:[email protected]/"
PORT = 5217
PORT = 3001
2 changes: 1 addition & 1 deletion src/backend/matching_backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const io = new Server(http, {
cors: {origin: "*"}
});

const ampqURL = 'amqps://ctkrippq:[email protected]/ctkrippq';
const ampqURL = process.env.AMPQURL;
const PORT = 8002;


Expand Down
2 changes: 1 addition & 1 deletion src/backend/question_backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('dotenv').config();
const cors = require("cors");
const express = require('express');
const mongoose = require('mongoose');
const mongoString = "mongodb+srv://derrickkhoo2000:[email protected]/";
const mongoString = process.env.mongoString;
const PORT = process.env.PORT || 3001;
const app = express();

Expand Down
2 changes: 1 addition & 1 deletion src/components/chatbox_elements/chatbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MessageInput from "./messageinput";

function Chatbox(props) {
const [socket, setSocket] = useState(null);
const roomID = props.roomID.roomID;
const roomID = props.roomID;

useEffect(() => {
const newSocket = io(`http://${window.location.hostname}:3000`);
Expand Down
2 changes: 0 additions & 2 deletions src/components/collab_elements/roomMainArea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ function RoomMainArea({roomID, question, detectSubmission}) {
>
Quit
</Button>
<Button style={{ backgroundColor: 'orange', color: 'black' }}>Previous</Button>
<Button style={{ backgroundColor: 'green', color: 'white' }}>Next</Button>
</Flex>
</Container>
{modal}
Expand Down
9 changes: 9 additions & 0 deletions src/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
118 changes: 118 additions & 0 deletions src/cypress/e2e/question_api.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/// <reference types="Cypress" />

const PORT = 8004;
const apiPath = `http://localhost:${PORT}/routes`;
const checkQuestionExistencePath = "checkQuestionExistence";
const addQuestionPath = "addQuestion";
const updateQuestionPath = "updateQuestion";
const deleteQuestionPath = "deleteQuestion";
var questionID = null;

const testQuestion = {
title: "Test Question",
description: "This is a test question",
category: "testing",
difficulty: "easy",
};

const updatedTestQuestion = {
title: "Updated Test Question",
description: "This is an updated test question",
category: "testing",
difficulty: "easy",
};

describe("Check that a question exists", () => {
it("should exist in question database", () => {
const body = { title: "Two Sum" };
cy.request({
method: "POST",
url: `${apiPath}/${checkQuestionExistencePath}`,
body: body,
}).then((response) => {
const status = response.status;
expect(status).to.be.equal(201);
const data = response.body;
expect(data.exists).to.be.equal(true);
});
});
});

describe("Finding a question that does not exist will show that it does not exist", () => {
it("should show that the question does not exist", () => {
const body = { title: "This question is invalid and does not exist" };
cy.request({
method: "POST",
url: `${apiPath}/${checkQuestionExistencePath}`,
body: body,
}).then((response) => {
const status = response.status;
expect(status).to.be.equal(201);
const data = response.body;
expect(data.exists).to.be.equal(false);
});
});
});



describe("adding a test question", () => {
it("should be able to add a test question", () => {
cy.request({
method: "POST",
url: `${apiPath}/${addQuestionPath}`,
body: testQuestion,
}).then((response) => {
const status = response.status;
questionID = response.body._id;
expect(status).to.be.equal(201);
});
});
});

describe("updating a test question", () => {
it("should be able to update the test question", () => {
const updatedTestQuestionId = {
title: "Updated Test Question",
description: "This is an updated test question",
category: "testing",
difficulty: "easy",
_id: questionID,
};
cy.request({
method: "PATCH",
url: `${apiPath}/${updateQuestionPath}`,
body: updatedTestQuestionId,
}).then((response) => {
const data = response.body;
expect(data.title).to.be.equal(updatedTestQuestionId.title);
expect(data.description).to.be.equal(updatedTestQuestionId.description);
});
});
});

describe("deleting a test question", () => {
it("should be able to delete the test question", () => {
cy.request({
method: "DELETE",
url: `${apiPath}/${deleteQuestionPath}`,
body: updatedTestQuestion,
}).then((response) => {
const status = response.status;
expect(status).to.be.equal(201);
});
});
});

describe("check if the test question is still there", () => {
it("should not still be there", () => {
cy.request({
method: "POST",
url: `${apiPath}/${checkQuestionExistencePath}`,
body: updatedTestQuestion,
}).then((response) => {
const data = response.body;
expect(data.exists).to.be.equal(false);
});
});
});
6 changes: 6 additions & 0 deletions src/cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('template spec', () => {
it('passes', () => {
cy.visit('https://example.cypress.io')
})
})

27 changes: 27 additions & 0 deletions src/cypress/e2e/user_api.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference types="Cypress" />

const loginUserApi = "http://localhost:4200/api/users/loginUser";

describe('logging in with admin credentials', () => {
it('should be able to login with admin credentials', () => {
const adminEmail = "[email protected]";
const adminPassword = "adminpassword";
cy.request({
method: 'POST',
url: loginUserApi,
body: {
email: adminEmail,
password: adminPassword,
}
}).then((response) => {
const status = response.status;
expect(status).to.be.equal(201);
const data = response.body;
expect(data.username).to.be.equal("admin");
expect(data.role).to.be.equal("admin");
});
})
});



5 changes: 5 additions & 0 deletions src/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions src/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions src/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
10 changes: 10 additions & 0 deletions src/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}


Loading

0 comments on commit 77f3aa2

Please sign in to comment.