@1mill/cloudevents 4.6.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -111
- package/dist/bundle-browser/cloudevents.esm.js +2 -0
- package/dist/bundle-browser/cloudevents.esm.js.map +1 -0
- package/dist/bundle-browser/cloudevents.umd.js +2 -0
- package/dist/bundle-browser/cloudevents.umd.js.map +1 -0
- package/dist/bundle-node/cloudevents.cjs +2 -0
- package/dist/bundle-node/cloudevents.cjs.map +1 -0
- package/dist/bundle-node/cloudevents.esm.js +2 -0
- package/dist/bundle-node/cloudevents.esm.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/tests/constructor/actor.test.d.ts +1 -0
- package/dist/tests/constructor/data.test.d.ts +1 -0
- package/dist/tests/constructor/datacontenttype.test.d.ts +1 -0
- package/dist/tests/constructor/dataschema.test.d.ts +1 -0
- package/dist/tests/constructor/id.test.d.ts +1 -0
- package/dist/tests/constructor/originid.test.d.ts +1 -0
- package/dist/tests/constructor/originsource.test.d.ts +1 -0
- package/dist/tests/constructor/origintime.test.d.ts +1 -0
- package/dist/tests/constructor/origintype.test.d.ts +1 -0
- package/dist/tests/constructor/source.test.d.ts +1 -0
- package/dist/tests/constructor/specversion.test.d.ts +1 -0
- package/dist/tests/constructor/subjest.test.d.ts +1 -0
- package/dist/tests/constructor/time.test.d.ts +1 -0
- package/dist/tests/constructor/type.test.d.ts +1 -0
- package/dist/tests/constructor/wschannelid.test.d.ts +1 -0
- package/dist/utils/cloudevent.d.ts +30 -0
- package/dist/utils/cloudevent.test.d.ts +1 -0
- package/dist/utils/fetchNodeEnv.d.ts +1 -0
- package/dist/utils/fetchNodeEnv.test.d.ts +1 -0
- package/dist/utils/validateAttribute.d.ts +13 -0
- package/dist/utils/validateAttribute.test.d.ts +1 -0
- package/package.json +33 -17
- package/CHANGELOG.md +0 -66
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/src/index.js +0 -197
- package/src/tests/constructor/data.test.js +0 -29
- package/src/tests/constructor/datacontenttype.test.js +0 -77
- package/src/tests/constructor/dataschema.test.js +0 -39
- package/src/tests/constructor/id.test.js +0 -45
- package/src/tests/constructor/originactor.test.js +0 -39
- package/src/tests/constructor/originatorid.test.js +0 -39
- package/src/tests/constructor/originid.test.js +0 -40
- package/src/tests/constructor/originsource.test.js +0 -40
- package/src/tests/constructor/origintime.test.js +0 -39
- package/src/tests/constructor/origintype.test.js +0 -40
- package/src/tests/constructor/source.test.js +0 -63
- package/src/tests/constructor/specversion.test.js +0 -41
- package/src/tests/constructor/subjest.test.js +0 -39
- package/src/tests/constructor/time.test.js +0 -36
- package/src/tests/constructor/type.test.js +0 -39
- package/src/tests/constructor/wschannelid.test.js +0 -39
- package/src/tests/methods/origin/originactor.test.js +0 -74
- package/src/tests/methods/origin/originid.test.js +0 -85
- package/src/tests/methods/origin/originsource.test.js +0 -85
- package/src/tests/methods/origin/origintime.test.js +0 -85
- package/src/tests/methods/origin/origintype.test.js +0 -85
- package/src/tests/methods/origin/unit.test.js +0 -13
- package/src/tests/methods/originator/originatorid.test.js +0 -51
- package/src/tests/methods/originator/unit.test.js +0 -10
- package/src/tests/methods/wschannel/unit.test.js +0 -10
- package/src/tests/methods/wschannel/wschannelid.test.js +0 -51
- package/src/unit.test.js +0 -91
- package/src/utils/fetchNodeEnv/index.js +0 -4
- package/src/utils/fetchNodeEnv/unit.test.js +0 -55
- package/src/utils/setAttribute/index.js +0 -10
- package/src/utils/setAttribute/unit.test.js +0 -67
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.origin#origintime', () => {
|
|
5
|
-
let ce
|
|
6
|
-
let cloudevent
|
|
7
|
-
let params
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
// Cloudevent we are acting on
|
|
11
|
-
ce = new Cloudevent({
|
|
12
|
-
source: 'some-source',
|
|
13
|
-
type: 'some-type',
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
// Cloudevent we are treating as the origin
|
|
17
|
-
cloudevent = new Cloudevent({
|
|
18
|
-
source: 'source-of-origin-cloudevent',
|
|
19
|
-
type: 'type-of-origin-cloudevent',
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
params = {
|
|
23
|
-
cloudevent,
|
|
24
|
-
originid: 'some-origin-id',
|
|
25
|
-
originsource: 'some-origin-source',
|
|
26
|
-
origintime: 'some-origin-time',
|
|
27
|
-
origintype: 'some-origin-type',
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('when #origintime is not input', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
params.origintime = undefined
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
describe('when #cloudevent is not input', () => {
|
|
37
|
-
it('throws the proper error', () => {
|
|
38
|
-
const expected = 'Cloudevent "origintime" must be of type STRING'
|
|
39
|
-
params.cloudevent = undefined
|
|
40
|
-
expect(() => ce.origin(params)).to.throw(expected)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('when #cloudevent is input', () => {
|
|
45
|
-
describe('when #cloudevent#origintime does not exist', () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
cloudevent.origintime = undefined
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
describe('when #cloudevent#time does not exist', () => {
|
|
51
|
-
it('throws the proper error', () => {
|
|
52
|
-
cloudevent.time = undefined
|
|
53
|
-
const expected = 'Cloudevent "origintime" must be of type STRING'
|
|
54
|
-
expect(() => ce.origin(params)).to.throw(expected)
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
describe('when #cloudevent#time does exist', () => {
|
|
59
|
-
it('returns the input #cloudevent#time', () => {
|
|
60
|
-
ce.origin(params)
|
|
61
|
-
expect(ce.origintime).to.eq(cloudevent.time)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
describe('when #cloudevent#origintime exists', () => {
|
|
67
|
-
it('returns the input #cloudevent#origintime', () => {
|
|
68
|
-
const expected = 'some-new-origin-time'
|
|
69
|
-
|
|
70
|
-
cloudevent.origintime = expected
|
|
71
|
-
ce.origin(params)
|
|
72
|
-
|
|
73
|
-
expect(ce.origintime).to.eq(expected)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
describe('when #origintime is input', () => {
|
|
80
|
-
it('returns the input value', () => {
|
|
81
|
-
ce.origin(params)
|
|
82
|
-
expect(ce.origintime).to.eq(params.origintime)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
})
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.origin#origintype', () => {
|
|
5
|
-
let ce
|
|
6
|
-
let cloudevent
|
|
7
|
-
let params
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
// Cloudevent we are acting on
|
|
11
|
-
ce = new Cloudevent({
|
|
12
|
-
source: 'some-source',
|
|
13
|
-
type: 'some-type',
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
// Cloudevent we are treating as the origin
|
|
17
|
-
cloudevent = new Cloudevent({
|
|
18
|
-
source: 'source-of-origin-cloudevent',
|
|
19
|
-
type: 'type-of-origin-cloudevent',
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
params = {
|
|
23
|
-
cloudevent,
|
|
24
|
-
originid: 'some-origin-id',
|
|
25
|
-
originsource: 'some-origin-source',
|
|
26
|
-
origintime: 'some-origin-time',
|
|
27
|
-
origintype: 'some-origin-type',
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('when #origintype is not input', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
params.origintype = undefined
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
describe('when #cloudevent is not input', () => {
|
|
37
|
-
it('throws the proper error', () => {
|
|
38
|
-
params.cloudevent = undefined
|
|
39
|
-
const expected = 'Cloudevent "origintype" must be of type STRING'
|
|
40
|
-
expect(() => ce.origin(params)).to.throw(expected)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('when #cloudevent is input', () => {
|
|
45
|
-
describe('when #cloudevent#origintype does not exist', () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
cloudevent.origintype = undefined
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
describe('when #cloudevent#type does not exist', () => {
|
|
51
|
-
it('throws the proper error', () => {
|
|
52
|
-
cloudevent.type = undefined
|
|
53
|
-
const expected = 'Cloudevent "origintype" must be of type STRING'
|
|
54
|
-
expect(() => ce.origin(params)).to.throw(expected)
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
describe('when #cloudevent#type does exist', () => {
|
|
59
|
-
it('returns the input #cloudevent#type', () => {
|
|
60
|
-
ce.origin(params)
|
|
61
|
-
expect(ce.origintype).to.eq(cloudevent.type)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
describe('when #cloudevent#origintype exists', () => {
|
|
67
|
-
it('returns the input #cloudevent#origintype', () => {
|
|
68
|
-
const expected = 'some-new-origin-type'
|
|
69
|
-
|
|
70
|
-
cloudevent.origintype = expected
|
|
71
|
-
ce.origin(params)
|
|
72
|
-
|
|
73
|
-
expect(ce.origintype).to.eq(expected)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
describe('when #origintype is input', () => {
|
|
80
|
-
it('returns the input value', () => {
|
|
81
|
-
ce.origin(params)
|
|
82
|
-
expect(ce.origintype).to.eq(params.origintype)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.origin', () => {
|
|
5
|
-
it('returns itself', () => {
|
|
6
|
-
const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
|
|
7
|
-
const origin = new Cloudevent({ source: 'source-of-origin', type: 'type-of-origin' })
|
|
8
|
-
|
|
9
|
-
const result = ce.origin({ cloudevent: origin })
|
|
10
|
-
|
|
11
|
-
expect(result).to.eq(ce)
|
|
12
|
-
})
|
|
13
|
-
})
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.originator#originatorid', () => {
|
|
5
|
-
let ce
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
ce = new Cloudevent({
|
|
9
|
-
source: 'some-source',
|
|
10
|
-
type: 'some-type',
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('when #originatorid is not input', () => {
|
|
15
|
-
describe('when #cloudevent is not input', () => {
|
|
16
|
-
it('returns undefined', () => {
|
|
17
|
-
ce.originator({})
|
|
18
|
-
expect(ce.originatorid).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('when #cloudevent is input', () => {
|
|
23
|
-
describe('when #cloudevent#originatorid does not exist', () => {
|
|
24
|
-
it('returns undefined', () => {
|
|
25
|
-
const cloudevent = {}
|
|
26
|
-
ce.originator({ cloudevent })
|
|
27
|
-
expect(ce.originatorid).to.be.undefined
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('when #cloudevent#originatorid does exist', () => {
|
|
32
|
-
it('returns #cloudevent#originatorid', () => {
|
|
33
|
-
const expected = 'some-originator-id'
|
|
34
|
-
|
|
35
|
-
const cloudevent = { originatorid: expected }
|
|
36
|
-
ce.originator({ cloudevent })
|
|
37
|
-
|
|
38
|
-
expect(ce.originatorid).to.eq(expected)
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('when #originatorid is input', () => {
|
|
45
|
-
it('returns the input value', () => {
|
|
46
|
-
const expected = 'some-originator-id'
|
|
47
|
-
ce.originator({ originatorid: expected })
|
|
48
|
-
expect(ce.originatorid).to.eq(expected)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.originator', () => {
|
|
5
|
-
it('returns itself', () => {
|
|
6
|
-
const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
|
|
7
|
-
const result = ce.originator({ originatorid: 'some-originator-id' })
|
|
8
|
-
expect(result).to.eq(ce)
|
|
9
|
-
})
|
|
10
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.wschannel', () => {
|
|
5
|
-
it('returns itself', () => {
|
|
6
|
-
const ce = new Cloudevent({ source: 'some-source', type: 'some-type' })
|
|
7
|
-
const result = ce.wschannel({ wschannelid: 'some-wschannel-id' })
|
|
8
|
-
expect(result).to.eq(ce)
|
|
9
|
-
})
|
|
10
|
-
})
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Cloudevent } from '../../../index.js'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
|
|
4
|
-
describe('cloudevent.wschannel#wschannelid', () => {
|
|
5
|
-
let ce
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
ce = new Cloudevent({
|
|
9
|
-
source: 'some-source',
|
|
10
|
-
type: 'some-type',
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('when #wschannelid is not input', () => {
|
|
15
|
-
describe('when #cloudevent is not input', () => {
|
|
16
|
-
it('returns undefined', () => {
|
|
17
|
-
ce.wschannel({})
|
|
18
|
-
expect(ce.wschannelid).to.be.undefined
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
describe('when #cloudevent is input', () => {
|
|
23
|
-
describe('when #cloudevent#wschannelid does not exist', () => {
|
|
24
|
-
it('returns undefined', () => {
|
|
25
|
-
const cloudevent = {}
|
|
26
|
-
ce.wschannel({ cloudevent })
|
|
27
|
-
expect(ce.wschannelid).to.be.undefined
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('when #cloudevent#wschannelid does exist', () => {
|
|
32
|
-
it('returns #cloudevent#wschannelid', () => {
|
|
33
|
-
const expected = 'some-wschannel-id'
|
|
34
|
-
|
|
35
|
-
const cloudevent = { wschannelid: expected }
|
|
36
|
-
ce.wschannel({ cloudevent })
|
|
37
|
-
|
|
38
|
-
expect(ce.wschannelid).to.eq(expected)
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('when #wschannelid is input', () => {
|
|
45
|
-
it('returns the input value', () => {
|
|
46
|
-
const expected = 'some-wschannel-id'
|
|
47
|
-
ce.wschannel({ wschannelid: expected })
|
|
48
|
-
expect(ce.wschannelid).to.eq(expected)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
})
|
package/src/unit.test.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import chai, { expect } from 'chai'
|
|
2
|
-
import chaiIso8601 from 'chai-iso8601'
|
|
3
|
-
import chaiSubset from 'chai-subset'
|
|
4
|
-
import { Cloudevent } from './index.js'
|
|
5
|
-
import { useFakeTimers } from 'sinon'
|
|
6
|
-
|
|
7
|
-
chai.use(chaiIso8601)
|
|
8
|
-
chai.use(chaiSubset)
|
|
9
|
-
|
|
10
|
-
describe('new Cloudevent', () => {
|
|
11
|
-
let clock
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
clock = useFakeTimers()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
clock.restore()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('when the cloudevent is not enriched', () => {
|
|
22
|
-
it('returns the expected cloudevent', () => {
|
|
23
|
-
clock.tick(987654321) // * Jump into the future
|
|
24
|
-
|
|
25
|
-
const data = JSON.stringify({ some: 'data' })
|
|
26
|
-
const source = 'some-source'
|
|
27
|
-
const time = new Date().toISOString()
|
|
28
|
-
const type = 'some-type'
|
|
29
|
-
|
|
30
|
-
const cloudevent = new Cloudevent({ data, source, type })
|
|
31
|
-
|
|
32
|
-
clock.tick(123456789) // * Jump into the future
|
|
33
|
-
|
|
34
|
-
expect(cloudevent).to.containSubset({
|
|
35
|
-
data,
|
|
36
|
-
datacontenttype: 'application/json',
|
|
37
|
-
originsource: source,
|
|
38
|
-
origintime: time,
|
|
39
|
-
origintype: type,
|
|
40
|
-
source,
|
|
41
|
-
specversion: '1.0',
|
|
42
|
-
time,
|
|
43
|
-
type,
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
describe('when the cloudevent is enriched', () => {
|
|
49
|
-
it('returns the expected cloudevent', () => {
|
|
50
|
-
clock.tick(987654321) // * Jump into the future
|
|
51
|
-
|
|
52
|
-
const origin = new Cloudevent({
|
|
53
|
-
originactor: 'some-originactor',
|
|
54
|
-
source: 'some-origin-source',
|
|
55
|
-
type: 'some-origin-type',
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
clock.tick(123456789) // * Jump into the future
|
|
59
|
-
|
|
60
|
-
const data = JSON.stringify({ some: 'data' })
|
|
61
|
-
const source = 'some-enrichment-source'
|
|
62
|
-
const time = new Date().toISOString()
|
|
63
|
-
const type = 'some-enrichment-type'
|
|
64
|
-
const wschannelid = 'some-wschannel-id'
|
|
65
|
-
|
|
66
|
-
const cloudevent = new Cloudevent({ data, source, type })
|
|
67
|
-
.origin({ cloudevent: origin })
|
|
68
|
-
.wschannel({ wschannelid })
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
clock.tick(987654321) // * Jump into the future
|
|
72
|
-
|
|
73
|
-
expect(cloudevent).to.containSubset({
|
|
74
|
-
data,
|
|
75
|
-
datacontenttype: 'application/json',
|
|
76
|
-
dataschema: undefined,
|
|
77
|
-
originactor: origin.originactor,
|
|
78
|
-
originid: origin.id,
|
|
79
|
-
originsource: origin.source,
|
|
80
|
-
origintime: origin.time,
|
|
81
|
-
origintype: origin.type,
|
|
82
|
-
source,
|
|
83
|
-
specversion: '1.0',
|
|
84
|
-
subject: undefined,
|
|
85
|
-
time,
|
|
86
|
-
type,
|
|
87
|
-
wschannelid,
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
})
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createSandbox } from 'sinon'
|
|
2
|
-
import { expect } from 'chai'
|
|
3
|
-
import { fetchNodeEnv } from './index.js'
|
|
4
|
-
|
|
5
|
-
describe('fetchNodeEnv', () => {
|
|
6
|
-
const name = 'SOME_NAME'
|
|
7
|
-
const sandbox = createSandbox()
|
|
8
|
-
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
sandbox.restore()
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
describe('when the node global.process is not defined', () => {
|
|
14
|
-
it('returns undefined', () => {
|
|
15
|
-
sandbox.stub(global, 'process').value(undefined)
|
|
16
|
-
const result = fetchNodeEnv(name)
|
|
17
|
-
expect(result).to.be.undefined
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('when the node global.process is defined', () => {
|
|
22
|
-
describe('when the input name does not exist as an environmental variable', () => {
|
|
23
|
-
describe('when a fallback value is not input', () => {
|
|
24
|
-
it ('returns undefined', () => {
|
|
25
|
-
sandbox.stub(process, 'env').value({})
|
|
26
|
-
const result = fetchNodeEnv(name)
|
|
27
|
-
expect(result).to.be.undefined
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('when a fallback value is input', () => {
|
|
32
|
-
it ('returns the input fallback value', () => {
|
|
33
|
-
const fallbackValue = 'some-fallback-value'
|
|
34
|
-
|
|
35
|
-
sandbox.stub(process, 'env').value({})
|
|
36
|
-
|
|
37
|
-
const result = fetchNodeEnv(name, fallbackValue)
|
|
38
|
-
expect(result).to.eq(fallbackValue)
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
describe('when the input name exists as an environmental variable', () => {
|
|
44
|
-
it('returns the proper environmental variable', () => {
|
|
45
|
-
const expected = 'some-value'
|
|
46
|
-
|
|
47
|
-
const env = { [name]: expected }
|
|
48
|
-
sandbox.stub(process, 'env').value(env)
|
|
49
|
-
|
|
50
|
-
const result = fetchNodeEnv(name, 'some-fallback-value')
|
|
51
|
-
expect(result).to.eq(expected)
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
})
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const setAttribute = ({ cloudevent, deprecated = false, name, types = [], value }) => {
|
|
2
|
-
if (deprecated) { console.warn(`Cloudevent "${name}" is depricated`) }
|
|
3
|
-
|
|
4
|
-
if (types.length > 0 && !types.includes(typeof value)) {
|
|
5
|
-
const message = `Cloudevent "${name}" must be of type ${types.map(s => s.toUpperCase()).sort().join(' or ')}.`
|
|
6
|
-
throw new Error(message)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
cloudevent[name] = value
|
|
10
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import chai, { expect } from 'chai'
|
|
2
|
-
import sinon from 'sinon'
|
|
3
|
-
import sinonChai from 'sinon-chai'
|
|
4
|
-
import { setAttribute } from './index.js'
|
|
5
|
-
|
|
6
|
-
chai.use(sinonChai)
|
|
7
|
-
|
|
8
|
-
describe('setAttribute', () => {
|
|
9
|
-
const name = 'some-name'
|
|
10
|
-
let cloudevent
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
cloudevent = {}
|
|
14
|
-
sinon.spy(console, 'warn')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
console.warn.restore()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('when #deprecated is true', () => {
|
|
22
|
-
it('calls console.warn with the proper warning', () => {
|
|
23
|
-
setAttribute({ cloudevent, deprecated: true, name })
|
|
24
|
-
const expected = `Cloudevent "${name}" is depricated`
|
|
25
|
-
expect(console.warn).to.have.been.calledWith(expected)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
describe('when #deprecated is false', () => {
|
|
30
|
-
it ('does not call console.warn', () => {
|
|
31
|
-
setAttribute({ cloudevent, deprecated: false, name })
|
|
32
|
-
expect(console.warn).to.have.not.been.called
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
describe('when #types is empty', () => {
|
|
37
|
-
[1234, '1234', undefined].forEach(value => {
|
|
38
|
-
it('sets cloudevent[#name] to the input #value', () => {
|
|
39
|
-
setAttribute({ cloudevent, name, value })
|
|
40
|
-
expect(cloudevent[name]).to.eq(value)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe('when #types is not empty', () => {
|
|
46
|
-
describe('when the type of #value is not in #types', () => {
|
|
47
|
-
it('throws the proper error', () => {
|
|
48
|
-
const types = ['undefined', 'string']
|
|
49
|
-
const value = 1234
|
|
50
|
-
|
|
51
|
-
const expected = `Cloudevent "${name}" must be of type STRING or UNDEFINED`
|
|
52
|
-
|
|
53
|
-
expect(() => setAttribute({ cloudevent, name, types, value })).to.throw(expected)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('when the type of #value is in #types', () => {
|
|
58
|
-
[1234, undefined].forEach(value => {
|
|
59
|
-
it('sets cloudevent[#name] to the input #value', () => {
|
|
60
|
-
const types = ['number', 'undefined']
|
|
61
|
-
setAttribute({ cloudevent, name, types, value })
|
|
62
|
-
expect(cloudevent[name]).to.eq(value)
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
})
|