forked from CS3219-AY2324S1/ay2324s1-course-assessment-g44
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CS3219-AY2324S1#94 from zylee348/CI-CD
CI merge
- Loading branch information
Showing
14 changed files
with
1,334 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}) | ||
}); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
|
Oops, something went wrong.