From ed0d511b31c85edf9a249eb640b2c9ee474f3bf9 Mon Sep 17 00:00:00 2001 From: Rosanny <rosanny.sihombing@hft-stuttgart.de> Date: Mon, 4 Jul 2022 13:07:31 +0200 Subject: [PATCH] unit test in JS --- __test/integration.test.js | 40 ++++++++++++++++++++++++++++++++++++++ __test/integration.test.ts | 40 -------------------------------------- __test/unit.test.js | 18 +++++++++++++++++ __test/unit.test.ts | 18 ----------------- 4 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 __test/integration.test.js delete mode 100644 __test/integration.test.ts create mode 100644 __test/unit.test.js delete mode 100644 __test/unit.test.ts diff --git a/__test/integration.test.js b/__test/integration.test.js new file mode 100644 index 0000000..3888d47 --- /dev/null +++ b/__test/integration.test.js @@ -0,0 +1,40 @@ +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 + }) + }) +}) diff --git a/__test/integration.test.ts b/__test/integration.test.ts deleted file mode 100644 index 8de62c7..0000000 --- a/__test/integration.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -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.js b/__test/unit.test.js new file mode 100644 index 0000000..d1f44d0 --- /dev/null +++ b/__test/unit.test.js @@ -0,0 +1,18 @@ +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']) + expect(helpers.stringToArray('foo,bar')).toStrictEqual(['foo', 'bar']) + expect(helpers.stringToArray('')).toBeNull + expect(helpers.stringToArray(String(null))).toBeNull +}) + +test('[/controller/gitlab] get projects from gitlab', async () => { + expect(await gitlab.getProjects(100, 0)).not.toBeNull +}) + +test('[/controller/gitlab] get latest pipeline status from gitlab', async () => { + expect(await gitlab.getLatestPipelineStatus(97)).toBe('success') + expect(await gitlab.getLatestPipelineStatus(0)).toBeFalsy +}) diff --git a/__test/unit.test.ts b/__test/unit.test.ts deleted file mode 100644 index b65c0ed..0000000 --- a/__test/unit.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -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"]) - expect(helpers.stringToArray('foo,bar')).toStrictEqual(["foo","bar"]) - expect(helpers.stringToArray('')).toBeNull - expect(helpers.stringToArray(String(null))).toBeNull -}); - -test('[/controller/gitlab] get projects from gitlab', async () => { - expect(await gitlab.getProjects(100, 0)).not.toBeNull -}) - -test('[/controller/gitlab] get latest pipeline status from gitlab', async () => { - expect(await gitlab.getLatestPipelineStatus(97)).toBe("success") - expect(await gitlab.getLatestPipelineStatus(0)).toBeFalsy -}) \ No newline at end of file -- GitLab