forked from TheDeveloper/http-aws-es
-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathAmazonTransport.test.js
60 lines (51 loc) · 1.52 KB
/
AmazonTransport.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict'
const assert = require('assert')
const { Transport } = require('@elastic/elasticsearch')
const AWS = require('aws-sdk')
const awsConfig = new AWS.Config({
accessKeyId: 'foo',
secretAccessKey: 'bar',
sessionToken: 'baz'
})
const AmazonTransport = require('../src/AmazonTransport')(awsConfig)
describe('AmazonTransport', function () {
it('extends Transport', function () {
assert(AmazonTransport.prototype instanceof Transport)
})
describe('.request()', function () {
const transport = new AmazonTransport({
connectionPool: {
getConnection: () => null
}
})
it('calls the callback if provided', function (done) {
transport.request({}, {}, () => done())
})
it('returns a Promise if callback not provided', function (done) {
transport.request({}, {}).catch(() => done())
})
it('accepts callback in place of options', function (done) {
transport.request({}, () => done())
})
it('waits for AWSConfig.getCredentials()', function (done) {
const mockAwsConfig = {
credentials: {},
getCredentials (next) {
next({
accessKeyId: 'foo',
secretAccessKey: 'bar',
sessionToken: 'baz'
})
done()
}
}
const AmazonTransport = require('../src/AmazonTransport')(mockAwsConfig)
const transport = new AmazonTransport({
connectionPool: {
getConnection: () => null
}
})
transport.request({}, {}, () => {})
})
})
})