Socialify

Folder ..

Viewing setup.test.js
53 lines (45 loc) • 1.2 KB

 1
 2
 3
 4
 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
import GDrive from 'main/application/sync/gdrive'
import AuthWindow from 'main/window/auth'

const mockCloseAuth = jest.fn()
const mockRemoveMenu = jest.fn()
jest.mock('main/window/auth', () => {
  return jest.fn().mockImplementation(() => {
    return {
      removeMenu: mockRemoveMenu,
      authenticate: jest.fn(() => Promise.resolve('AUTH_CODE')),
      close: mockCloseAuth
    }
  })
})

describe('#setup', () => {
  let sync

  beforeEach(() => {
    sync = new GDrive()
    sync.initialize({}, {})
  })

  afterEach(() => {
    jest.clearAllMocks()
  })

  test('opens auth window with auth url', () => {
    return sync.setup().then(() => {
      expect(AuthWindow).toHaveBeenCalledWith(
        'https://example.com/google_oauth2'
      )
    })
  })

  test('removes menu from auth window', () => {
    return sync.setup().then(() => {
      expect(mockRemoveMenu).toHaveBeenCalledTimes(1)
    })
  })

  test('closes auth window on authentication done', () => {
    return sync.setup().then(() => {
      expect(mockCloseAuth).toHaveBeenCalledTimes(1)
    })
  })

  test('calls get token with auth code', () => {
    return sync.setup().then(() => {
      expect(sync.client.auth.getToken).toHaveBeenCalledWith('AUTH_CODE')
    })
  })
})