gitlab.unit.test.js 1.1 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
const gitlab = require('../functions/gitlab')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
2
3
//const axios = require('axios')
//jest.mock('axios')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
4

Rosanny Sihombing's avatar
Rosanny Sihombing committed
5
describe('GitLab API', () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
6
  test('returns an existing gitlab user by an email address', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
7
    let user = await gitlab.getUserByEmail('litehon958@whipjoy.com')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
8
9
10
11
12
    expect(user).not.toBeNull()
  })
  test('returns an undefined user', async () => {
    let user = await gitlab.getUserByEmail('johndoe@nowhere.com')
    expect(user).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
13
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
14

Rosanny Sihombing's avatar
Rosanny Sihombing committed
15
  test('returns users project', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
16
    let userProjects = await gitlab.getUserProjects(136)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
17
18
19
20
21
    expect(userProjects).toBeDefined()
  })
  test('returns undefined projects, due to non-existing gitlab user ID', async () => {
    let userProjects = await gitlab.getUserProjects(0)
    expect(userProjects).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
22
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
23

Rosanny Sihombing's avatar
Rosanny Sihombing committed
24
25
26
27
28
29
30
  test('returns a project by ID', async () => {
    let project = await gitlab.getProjectById(13) // m4lab_landing_page
    expect(project).toBeDefined()
  })
  test('returns undefined, due to invalid project ID', async () => {
    let project = await gitlab.getProjectById(0)
    expect(project).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
31
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
32
})