Commit 689b3cfa authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

update test

parent 82644e44
import methods from '../functions/methods' const dbController = require('../../src/controller/dbController')
describe('DB methohds test', () => { describe('DB methohds test', () => {
it('returns a user from DB by email', async () => { 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() expect(user).not.toBeNull()
}) })
it('returns a null user', async () => { 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() expect(user).toBeNull()
}) })
it("returns a user's email", async () => { it("returns a user's email", async () => {
const email = await methods.getUserEmailById(1) const email = await dbController.getUserEmailById(1)
expect(email).not.toBeNull() expect(email).not.toBeNull()
}) })
it("returns null instead of a user's email", async () => { 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() expect(email).toBeNull()
}) })
it('returns null from DB by token', async () => { 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() expect(user).toBeNull() // for valid token = expect(user).not.toBeNull()
}) })
it("returns a user's verification token, if any", async () => { 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() expect(token).toBeNull()
}) })
it("returns a user's ID, if any", async () => { 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() expect(token).toBeNull() // for valid token = expect(user).not.toBeNull()
}) })
it("returns a user's GitLab_ID, if any", async () => { 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() expect(id).not.toBeNull()
}) })
it('checks user email', async () => { 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() expect(user).not.toBeNull()
}) })
it('checks user email and return null', async () => { 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() expect(user).toBeNull()
}) })
}) })
import gitlab from '../functions/gitlab' const gitlabController = require('../src/controller/gitlabController')
// const axios = require('axios') const axios = require('axios')
// jest.mock('axios')
jest.mock('axios')
describe('GitLab API', () => { describe('GitLab API', () => {
test('returns an existing gitlab user by an email address', async () => { 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() expect(user).not.toBeNull()
}) })
test('returns an undefined user', async () => { 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() expect(user).toBeUndefined()
}) })
test('returns users project', async () => { test('returns users project', async () => {
const userProjects = await gitlab.getUserProjects(136) const userProjects = await gitlabController.getUserProjects(136)
expect(userProjects).toBeDefined() expect(userProjects).toBeDefined()
}) })
test('returns undefined projects, due to non-existing gitlab user ID', async () => { 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() expect(userProjects).toBeUndefined()
}) })
test('returns a project by ID', async () => { 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() expect(project).toBeDefined()
}) })
test('returns undefined, due to invalid project ID', async () => { test('returns undefined, due to invalid project ID', async () => {
const project = await gitlab.getProjectById(0) const project = await gitlabController.getProjectById(0)
expect(project).toBeUndefined() expect(project).toBeUndefined()
}) })
}) })
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
})
})
})
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
}
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