gitlab.unit.test.js 1.87 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
const gitlab = require('../routes/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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
describe('GitLab API', () => {

  /*
  test('jest.fn recalls what it has been called with', () => {
    const mock = jest.fn()
    mock('a', 'b', 'c')
    expect(mock).toHaveBeenCalledTimes(1)
    expect(mock).toHaveBeenCalledWith('a', 'b', 'c')
  }); */

  // mock
/*  it('returns an existing gitlab-userID by an email address', done => {
    let resp = {
      error: false,
      data: 1}
    axios.get.mockResolvedValue(resp)
    
    gitlab.getUserIdByEmail('rosanny.sihombing@hft-stuttgart.de', function(resp){
      try {
        expect(resp.error).toBeFalsy()
        expect(resp.data).not.toBeNull()
        done()
      } catch (error) {
        done(error)
      }
    })
  })
*/
  
  it('returns an existing gitlab-userID by an email address', done => {
    gitlab.getUserIdByEmail('rosanny.sihombing@hft-stuttgart.de', function(data){
      try {
        expect(data.error).toBeFalsy()
        expect(data.data).not.toBeNull()
        done()
      } catch (error) {
        done(error)
      }
    })
  })

  it('returns an error due to the non-exist user', done => {
    gitlab.getUserIdByEmail('test@hft-stuttgart.com', function (data) {
      try {
        expect(data.error).toBeTruthy()
        done()
      } catch (error) {
        done(error)
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
54
    })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
55
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
56

Rosanny Sihombing's avatar
Rosanny Sihombing committed
57
58
59
60
61
62
63
64
65
  it('returns the projects of a particular userId', done => {
    gitlab.getUserProjects(3, function (data) {
      try {
        expect(data.error).toBeFalsy()
        expect(data.data).not.toBeNull()
        done()
      } catch (error) {
        done(error)
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
66
    })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
67
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
68

Rosanny Sihombing's avatar
Rosanny Sihombing committed
69
70
71
72
73
74
75
76
  it('returns an error due to the wrong userID', done => {  
    gitlab.getUserProjects('abc', function (data) {
      try {
        expect(data.error).toBeTruthy()
        done()
      } catch (error) {
        done(error)
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
77
    })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
78
  })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
79
})