diff --git a/__tests__/method.unit.test.ts b/__tests/db.unit.test.js similarity index 54% rename from __tests__/method.unit.test.ts rename to __tests/db.unit.test.js index deb347e6e18c7222299dcb73e61a2b8ba35f5bb7..f1d8d697247e2496d9f3f69a0e368aa85342b43e 100644 --- a/__tests__/method.unit.test.ts +++ b/__tests/db.unit.test.js @@ -1,50 +1,50 @@ -import methods from '../functions/methods' +const dbController = require('../../src/controller/dbController') describe('DB methohds test', () => { it('returns a user from DB by email', async () => { - const user = await methods.getUserByEmail('litehon958@whipjoy.com') + const user = await dbController.getUserByEmail('litehon958@whipjoy.com') expect(user).not.toBeNull() }) it('returns a null user', async () => { - const user = await methods.getUserByEmail('jondoe@nowhere.com') // a non-exist user + const user = await dbController.getUserByEmail('jondoe@nowhere.com') // a non-exist user expect(user).toBeNull() }) it("returns a user's email", async () => { - const email = await methods.getUserEmailById(1) + const email = await dbController.getUserEmailById(1) expect(email).not.toBeNull() }) it("returns null instead of a user's email", async () => { - const email = await methods.getUserEmailById(1005) // no user has this ID + const email = await dbController.getUserEmailById(1005) // no user has this ID expect(email).toBeNull() }) it('returns null from DB by token', async () => { - const user = await methods.getUserByToken('12345678') // unvalid token + const user = await dbController.getUserByToken('12345678') // unvalid token expect(user).toBeNull() // for valid token = expect(user).not.toBeNull() }) it("returns a user's verification token, if any", async () => { - const token = await methods.getVerificationTokenByUserId(1) + const token = await dbController.getVerificationTokenByUserId(1) expect(token).toBeNull() }) it("returns a user's ID, if any", async () => { - const token = await methods.getUserIdByVerificationToken('12345678') // unvalid token + const token = await dbController.getUserIdByVerificationToken('12345678') // unvalid token expect(token).toBeNull() // for valid token = expect(user).not.toBeNull() }) it("returns a user's GitLab_ID, if any", async () => { - const id = await methods.getGitlabId(1) + const id = await dbController.getGitlabId(1) expect(id).not.toBeNull() }) it('checks user email', async () => { - const user = await methods.checkUserEmail('litehon958@whipjoy.com') + const user = await dbController.checkUserEmail('litehon958@whipjoy.com') expect(user).not.toBeNull() }) it('checks user email and return null', async () => { - const user = await methods.checkUserEmail('jondoe@nowhere.com') // a non-exist user + const user = await dbController.checkUserEmail('jondoe@nowhere.com') // a non-exist user expect(user).toBeNull() }) }) diff --git a/__tests__/gitlab.unit.test.ts b/__tests/gitlab.unit.test.js similarity index 52% rename from __tests__/gitlab.unit.test.ts rename to __tests/gitlab.unit.test.js index df8aa3a395e5e95741d3a285a0a22c0bce1eede2..babb56898f54b4cd27d98eb64527e4205b933a7e 100644 --- a/__tests__/gitlab.unit.test.ts +++ b/__tests/gitlab.unit.test.js @@ -1,32 +1,36 @@ -import gitlab from '../functions/gitlab' -// const axios = require('axios') -// jest.mock('axios') +const gitlabController = require('../src/controller/gitlabController') +const axios = require('axios') + +jest.mock('axios') describe('GitLab API', () => { test('returns an existing gitlab user by an email address', async () => { - const user = await gitlab.getUserByEmail('litehon958@whipjoy.com') + axios.get.mockResolvedValue({ + + }) + const user = await gitlabController.getUserByEmail('litehon958@whipjoy.com') expect(user).not.toBeNull() }) test('returns an undefined user', async () => { - const user = await gitlab.getUserByEmail('johndoe@nowhere.com') + const user = await gitlabController.getUserByEmail('johndoe@nowhere.com') expect(user).toBeUndefined() }) test('returns users project', async () => { - const userProjects = await gitlab.getUserProjects(136) + const userProjects = await gitlabController.getUserProjects(136) expect(userProjects).toBeDefined() }) test('returns undefined projects, due to non-existing gitlab user ID', async () => { - const userProjects = await gitlab.getUserProjects(0) + const userProjects = await gitlabController.getUserProjects(0) expect(userProjects).toBeUndefined() }) test('returns a project by ID', async () => { - const project = await gitlab.getProjectById(13) // m4lab_landing_page + const project = await gitlabController.getProjectById(13) // m4lab_landing_page expect(project).toBeDefined() }) test('returns undefined, due to invalid project ID', async () => { - const project = await gitlab.getProjectById(0) + const project = await gitlabController.getProjectById(0) expect(project).toBeUndefined() }) }) diff --git a/__tests/public.endpoint.test.js b/__tests/public.endpoint.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e9f52bab1fbc0eee9e82b286a6b56c42e560c3e8 --- /dev/null +++ b/__tests/public.endpoint.test.js @@ -0,0 +1,16 @@ +const request = require('supertest') +const express = require('express') + +const app = express() +app.set('port', 9989) + +describe('Test endpoint(s)', () => { + it('should return a 200 status code', () => { + request(app) + .get('/contact') + .expect(200) + .end(function (err, res) { + if (err) throw err + }) + }) +}) diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000000000000000000000000000000000000..758fa1330e87740bfa99095c8a02946ef29213aa --- /dev/null +++ b/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +}