From bfd88ffefcfe1cb5fa31c720870dc2162c9cc2f2 Mon Sep 17 00:00:00 2001 From: Rosanny <rosanny.sihombing@hft-stuttgart.de> Date: Mon, 4 Jul 2022 13:50:23 +0200 Subject: [PATCH] tests in JS --- __test/integration.test.js | 40 ++++++++++++++++++++++++++++++++++++++ __test/integration.test.ts | 3 --- __test/unit.test.js | 18 +++++++++++++++++ __test/unit.test.ts | 18 ----------------- 4 files changed, 58 insertions(+), 21 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 daf5f30..0000000 --- a/__test/integration.test.ts +++ /dev/null @@ -1,3 +0,0 @@ -test('add 1+1', () => { - expect(1+1).toBe(2) -}) \ No newline at end of file diff --git a/__test/unit.test.js b/__test/unit.test.js new file mode 100644 index 0000000..a45a51f --- /dev/null +++ b/__test/unit.test.js @@ -0,0 +1,18 @@ +import { helpers } from '../built/utils/helpers' +import { gitlab } from '../built/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 55e3912..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)).toBeUndefined -}) \ No newline at end of file -- GitLab