gitlab.unit.test.js 1.23 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
2
3
4
const gitlabController = require('../src/controller/gitlabController')
const axios = require('axios')

jest.mock('axios')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
5

Rosanny Sihombing's avatar
Rosanny Sihombing committed
6
describe('GitLab API', () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
7
  test('returns an existing gitlab user by an email address', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
8
9
10
11
    axios.get.mockResolvedValue({

    })
    const user = await gitlabController.getUserByEmail('litehon958@whipjoy.com')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
12
13
14
    expect(user).not.toBeNull()
  })
  test('returns an undefined user', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
15
    const user = await gitlabController.getUserByEmail('johndoe@nowhere.com')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
16
    expect(user).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
17
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
18

Rosanny Sihombing's avatar
Rosanny Sihombing committed
19
  test('returns users project', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
20
    const userProjects = await gitlabController.getUserProjects(136)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
21
22
23
    expect(userProjects).toBeDefined()
  })
  test('returns undefined projects, due to non-existing gitlab user ID', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
24
    const userProjects = await gitlabController.getUserProjects(0)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
25
    expect(userProjects).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
26
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
27

Rosanny Sihombing's avatar
Rosanny Sihombing committed
28
  test('returns a project by ID', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
29
    const project = await gitlabController.getProjectById(13) // m4lab_landing_page
Rosanny Sihombing's avatar
Rosanny Sihombing committed
30
31
32
    expect(project).toBeDefined()
  })
  test('returns undefined, due to invalid project ID', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
33
    const project = await gitlabController.getProjectById(0)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
34
    expect(project).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
35
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
36
})