gitlab.unit.test.ts 1.11 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
import gitlab from '../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
    const user = await gitlab.getUserByEmail('litehon958@whipjoy.com')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
8
9
10
    expect(user).not.toBeNull()
  })
  test('returns an undefined user', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
11
    const user = await gitlab.getUserByEmail('johndoe@nowhere.com')
Rosanny Sihombing's avatar
Rosanny Sihombing committed
12
    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
    const userProjects = await gitlab.getUserProjects(136)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
17
18
19
    expect(userProjects).toBeDefined()
  })
  test('returns undefined projects, due to non-existing gitlab user ID', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
20
    const userProjects = await gitlab.getUserProjects(0)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
21
    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
  test('returns a project by ID', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
25
    const project = await gitlab.getProjectById(13) // m4lab_landing_page
Rosanny Sihombing's avatar
Rosanny Sihombing committed
26
27
28
    expect(project).toBeDefined()
  })
  test('returns undefined, due to invalid project ID', async () => {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
29
    const project = await gitlab.getProjectById(0)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
30
    expect(project).toBeUndefined()
Rosanny Sihombing's avatar
Rosanny Sihombing committed
31
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
32
})