From 03032c6b7e1414ce976ef003b807d9f24095ac00 Mon Sep 17 00:00:00 2001 From: Rosanny <rosanny.sihombing@hft-stuttgart.de> Date: Mon, 27 Jun 2022 11:51:25 +0200 Subject: [PATCH] test update and minor update --- __test/integration.test.ts | 41 ++++++++++++++++++++++++++++++++++-- __test/unit.test.ts | 6 +++--- src/controller/controller.ts | 8 +++---- src/controller/gitlab.ts | 4 ++-- src/routes/project.ts | 4 ++-- src/utils/helpers.ts | 2 +- 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/__test/integration.test.ts b/__test/integration.test.ts index daf5f30..8de62c7 100644 --- a/__test/integration.test.ts +++ b/__test/integration.test.ts @@ -1,3 +1,40 @@ -test('add 1+1', () => { - expect(1+1).toBe(2) +import request from 'supertest' +const express = require('express'); + +const app = express(); +app.set('port', 8888) + +describe('Test endpoint(s)', () => { + it('should return a 200 status code', async () => { + request(app) + .get('/mailinglists') + .expect(200) + .end(function(err, res) { + if (err) throw err; + }); + }); + it('should return a 200 status code', async () => { + request(app) + .get('/projektdaten') + .expect(200) + .end(function(err, res) { + if (err) throw err; + }); + }); + it('should return a 200 status code', async () => { + request(app) + .get('/projektinformationen') + .expect(200) + .end(function(err, res) { + if (err) throw err; + }); + }); + it('should return a 200 status code', async () => { + request(app) + .get('/projectoverview?projectID=1') + .expect(200) + .end(function(err, res) { + if (err) throw err; + }); + }); }) \ No newline at end of file diff --git a/__test/unit.test.ts b/__test/unit.test.ts index 55e3912..b65c0ed 100644 --- a/__test/unit.test.ts +++ b/__test/unit.test.ts @@ -1,5 +1,5 @@ -import helpers from '../src/utils/helpers' -import gitlab from '../src/controller/gitlab' +import {helpers} from '../src/utils/helpers' +import {gitlab} from '../src/controller/gitlab' test('[/utils/helpers] convert string to array', () => { expect(helpers.stringToArray('foo')).toStrictEqual(["foo"]) @@ -14,5 +14,5 @@ test('[/controller/gitlab] get projects from gitlab', async () => { test('[/controller/gitlab] get latest pipeline status from gitlab', async () => { expect(await gitlab.getLatestPipelineStatus(97)).toBe("success") - expect(await gitlab.getLatestPipelineStatus(0)).toBeUndefined + expect(await gitlab.getLatestPipelineStatus(0)).toBeFalsy }) \ No newline at end of file diff --git a/src/controller/controller.ts b/src/controller/controller.ts index 6c23f36..61faa69 100644 --- a/src/controller/controller.ts +++ b/src/controller/controller.ts @@ -1,7 +1,7 @@ import https from 'https' -import {helpers} from '../utils/helpers' -import {gitlab} from './gitlab' -import {dbconn} from '../config/dbconn' +import { helpers } from '../utils/helpers' +import { gitlab } from './gitlab' +import { dbconn } from '../config/dbconn' const lang = 'DE' @@ -239,4 +239,4 @@ const controller = { } } -export {controller} +export { controller } diff --git a/src/controller/gitlab.ts b/src/controller/gitlab.ts index e536964..59e7831 100644 --- a/src/controller/gitlab.ts +++ b/src/controller/gitlab.ts @@ -37,8 +37,8 @@ const gitlab = { url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/' + String(projectId) + '/pipelines' }) .then(res => res.data[0].status) - .catch(err => console.error(err)) + .catch(err => console.error(err.response)) } } -export {gitlab} +export { gitlab } diff --git a/src/routes/project.ts b/src/routes/project.ts index e058933..5801947 100644 --- a/src/routes/project.ts +++ b/src/routes/project.ts @@ -1,7 +1,7 @@ -import {controller} from '../controller/controller' +import { controller } from '../controller/controller' module.exports = function (app: any) { - // ======== APP ROUTES - PROJECT ==================== +// ======== APP ROUTES - PROJECT ==================== app.get('/', function (req: any, res: any) { controller.showHome(res) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 238ec54..248382b 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -5,4 +5,4 @@ const helpers = { } } -export {helpers} +export { helpers } -- GitLab