/
authClass.getOpenApiYAML.spec.ts
51 lines (39 loc) · 1.32 KB
/
authClass.getOpenApiYAML.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
import { expect } from 'chai'
import * as sinon from 'sinon'
import { ClientService } from '../apiServices/ClientService'
import { AuthService } from '../apiServices/AuthService'
const getRequest = require('../http/index')
describe('getOpenApiYAML', () => {
let getRequestStub: any
let AUTH
beforeEach(() => {
getRequestStub = sinon.stub(getRequest, 'getRequest')
AUTH = new AuthService('user', 'password')
})
afterEach(() => {
getRequestStub.restore()
})
it('is a function', () => {
expect(AUTH.getOpenApiYAML).to.be.a('function')
})
it('returns an object', async () => {
const value = {
yaml: 'yaml',
}
getRequestStub.resolves({
data: value,
})
const result = await AUTH.getOpenApiYAML()
expect(result).to.deep.equal(value)
expect(getRequestStub.calledWith(`${ClientService.MYTHX_API_ENVIRONMENT}/openapi.yaml`)).to.be.true
})
it('should fail if there is something wrong with the request', async () => {
getRequestStub.throws('400')
try {
await AUTH.getOpenApiYAML()
expect.fail('openApiYAML should be rejected')
} catch (err) {
expect(err.message).to.equal('MythxJS. Error with your request. 400')
}
})
})