Commit 6d2c45af authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

add unit test

parent 0bd70889
const gitlab = require('../routes/gitlab')
const axios = require('axios')
beforeAll(() => {
// test gitlab API connection
var config = {
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects'
}
axios(config)
.then(function (response) {
expect(response.statusCode).toBe(200)
})
})
describe('GitLab API test', () => {
test("Get a gitlab userID by email", () => { // email = any email address
gitlab.getUserIdByEmail("test@email.de", function(resp){
expect(resp).not.toBeNull()
})
})
test("Get the projects of a particular user", () => { // userID = any integer
gitlab.getUserProjects(3, function(resp){
expect(resp).not.toBeNull()
})
})
})
\ No newline at end of file
const dbconn = require('../routes/dbconn')
const methods = require('../routes/methods')
beforeAll(() => {
// test DB connection
dbconn.user.query('SELECT 1 + 5 AS solution', function (err, rows) {
expect(err).toBeNull()
expect(rows[0].solution).toBe(6)
})
dbconn.project.query('SELECT 10 + 5 AS solution', function (err, rows) {
expect(err).toBeNull()
expect(rows[0].solution).toBe(15)
})
})
describe("DB methohds test", () => {
/*
test("Get a user from DB by email", () => {
let gitlabUserData = "to-be-defined"
methods.addGitlabUser(gitlabUserData, function(data, err){
expect(data).not.toBeNull()
expect(err).toBeNull()
})
}) */
test("Get a user from DB by email", () => { // email = any email address
methods.getUserByEmail("test@email.de", function(data, err){
expect(data).not.toBeNull()
expect(err).toBeNull()
})
})
test("Get a user from DB by ID", () => { // ID = any integer
methods.getUserById(100, function(data, err){
expect(data).not.toBeNull()
expect(err).toBeNull()
})
})
test("Check user email", () => { // email = any email address
methods.checkUserEmail("test@email.de", function(err, data){
expect(data).not.toBeNull()
expect(err).toBeNull()
})
})
test("Get a user by token", () => { // token = any alphanumeric
methods.checkUserEmail("1abc0qwerty", function(err, data){
expect(data).not.toBeNull()
expect(err).toBeNull()
})
})
})
describe('Sample Test', () => {
it('should test that true === true', () => {
expect(true).toBe(true)
})
})
\ No newline at end of file
This diff is collapsed.
......@@ -17,11 +17,11 @@
},
"scripts": {
"start": "nodemon app.js",
"test": ""
"test": "jest"
},
"dependencies": {
"async": "^3.1.0",
"axios": "^0.21.0",
"axios": "^0.21.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
......@@ -36,13 +36,14 @@
"fs": "0.0.1-security",
"helmet": "^3.23.3",
"i18n": "^0.8.5",
"jest": "^26.6.3",
"morgan": "^1.9.1",
"mysql": "^2.17.1",
"nodemailer": "^6.3.1",
"nodemon": "^2.0.1",
"passport": "0.3.2",
"passport-saml": "^1.4.2",
"pug": "^2.0.4"
"pug": "^3.0.2"
},
"devDependencies": {},
"engines": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment