-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.test.js
62 lines (55 loc) · 1.42 KB
/
metadata.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
61
62
const test = require('ava')
const grpc = require('@grpc/grpc-js')
const create = require('./')
test('should return metadata passed in', t => {
const meta = new grpc.Metadata()
meta.add('foo', 'bar')
const ret = create(meta)
t.is(meta, ret)
})
test('should return new metadata when simple object is passed in', t => {
const input = { foo: 'bar' }
const ret = create(input)
t.true(ret instanceof grpc.Metadata)
t.deepEqual(ret.getMap(), input)
})
test('should return new metadata when object is passed cleaning up values', t => {
const input = {
foo: 'bar',
age: 12,
prop: true,
other: null,
some: undefined
}
const ret = create(input)
t.true(ret instanceof grpc.Metadata)
const expected = {
foo: 'bar',
age: '12',
prop: 'true'
}
t.deepEqual(ret.getMap(), expected)
})
test('should return new metadata and not add empty strings', t => {
const input = {
foo: 'bar',
prop: ''
}
const ret = create(input)
t.true(ret instanceof grpc.Metadata)
t.deepEqual(ret.getMap(), { foo: 'bar' })
})
test('should return new metadata and add empty strings when option set', t => {
const input = {
foo: 'bar',
prop: ''
}
const ret = create(input, { addEmpty: true })
t.true(ret instanceof grpc.Metadata)
t.deepEqual(ret.getMap(), input)
})
test('should get undefined on invalid object', t => {
const input = 1
const ret = create(input)
t.is(ret, undefined)
})