/
authClass.loginWithSignature.spec.ts
54 lines (40 loc) · 1.33 KB
/
authClass.loginWithSignature.spec.ts
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
54
import { expect } from 'chai'
import * as sinon from 'sinon'
import { AuthService } from '../apiServices/AuthService'
import { JwtTokensInterface } from '..'
const postRequest = require('../http/index')
describe('loginWithSignature', () => {
const tokens: JwtTokensInterface = {
access: 'access',
refresh: 'refresh',
}
let postRequestStub: any
let AUTH
beforeEach(() => {
postRequestStub = sinon.stub(postRequest, 'postRequest')
AUTH = new AuthService('user', 'password')
})
afterEach(() => {
postRequestStub.restore()
delete AUTH.jwtTokens
})
it('is a function', () => {
expect(AUTH.loginWithSignature).to.be.a('function')
})
it('should return and set access and refresh tokens', async () => {
postRequestStub.resolves({
data: { jwtTokens: tokens },
})
const result = await AUTH.loginWithSignature()
expect(result).to.equal(tokens)
})
it('should fail if there is something wrong with the request', async () => {
postRequestStub.throws('400')
try {
await AUTH.loginWithSignature()
expect.fail('loginWithSignature should be rejected')
} catch (err) {
expect(err.message).to.equal('MythxJS. Error with your request. 400')
}
})
})