Socialify

Folder ..

Viewing disconnect.test.js
29 lines (24 loc) • 645.0 B

 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
import GDrive from 'main/application/sync/gdrive'

describe('#disconnect', () => {
  let sync, cryptor

  beforeEach(() => {
    cryptor = {
      decrypt: jest.fn(
        () => '{"access_token": "qwert","refresh_token": "asdf"}'
      ),
      encrypt: jest.fn()
    }
    sync = new GDrive()
    sync.initialize({}, cryptor)
    sync.disconnect()
  })

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

  test('reads tokens from storage', () => {
    expect(cryptor.decrypt).toHaveBeenCalled()
  })

  test('removes access token from credentials', () => {
    expect(cryptor.encrypt).toHaveBeenCalledWith('{"refresh_token":"asdf"}')
  })
})