-
Notifications
You must be signed in to change notification settings - Fork 1
/
cobot.test.js
41 lines (36 loc) · 1.14 KB
/
cobot.test.js
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
const axios = require('axios')
const Cobot = require('./cobot')
jest.mock('axios')
describe('models/cobot', () => {
describe('.authorize', () => {
test('should fetch a new token', () => {
const resp = { data: { access_token: 'meow' } }
jest.spyOn(axios, 'post').mockResolvedValue(resp)
return Cobot.authorize().then(cobot => {
expect(axios.post).toBeCalled()
expect(cobot).toBeInstanceOf(Cobot)
expect(cobot.token).toBe('meow')
})
})
})
describe('.cards', () => {
test('returns a structured list of cards', () => {
const resp = {
data: [
{ membership: { id: 'foo', name: 'John' }, token: '001' },
{ membership: { id: 'bar', name: 'Jane' }, token: '002' },
],
}
const expected = [
{ name: 'John', number: '001' },
{ name: 'Jane', number: '002' },
]
jest.spyOn(axios, 'get').mockResolvedValue(resp)
// TODO: why doesnt this work? It should...
// axios.get.mockResolvedValue(resp)
return new Cobot('fake-value')
.cards()
.then(actual => expect(actual).toEqual(expected))
})
})
})