Skip to content

Commit 7803364

Browse files
author
x244777
committed
feat: ignore tags when emit is empty object
1 parent 0bad966 commit 7803364

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

src/utils/tags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { skipTag } from '../filters';
22

3-
export const adornStandardTags = (eventField) => (uow) => (!uow[eventField] ? uow : ({
3+
export const adornStandardTags = (eventField) => (uow) => ((!uow[eventField] || Object.keys(uow[eventField]).length === 0) ? uow : ({
44
...uow,
55
[eventField]: {
66
...uow[eventField],

test/unit/utils/tags.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import sinon from 'sinon';
4+
5+
import {
6+
adornStandardTags,
7+
} from '../../../src/utils';
8+
9+
describe('utils/tags.js', () => {
10+
afterEach(sinon.restore);
11+
12+
it('should adorn tags, event field exists', () => {
13+
process.env.ACCOUNT_NAME = 'account1';
14+
process.env.STAGE = 'dev';
15+
process.env.SERVICE = 'service1';
16+
process.env.AWS_LAMBDA_FUNCTION_NAME = 'lambda1';
17+
const uow = {
18+
pipeline: 'thing-pipeline',
19+
emit: {
20+
type: 'thing-updated',
21+
partitionKey: 'thing1',
22+
timestamp: 1600144863435,
23+
thing: {
24+
id: '7588777d-19a0-49d5-856f-a657ed4b5034',
25+
timestamp: 1600144863435,
26+
},
27+
},
28+
};
29+
const event = adornStandardTags('emit')(uow);
30+
delete process.env.ACCOUNT_NAME;
31+
delete process.env.STAGE;
32+
delete process.env.SERVICE;
33+
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
34+
expect(event).to.deep.equal({
35+
...uow,
36+
emit: {
37+
...uow.emit,
38+
tags: {
39+
account: 'account1',
40+
region: 'us-west-2',
41+
stage: 'dev',
42+
source: 'service1',
43+
functionname: 'lambda1',
44+
pipeline: 'thing-pipeline',
45+
skip: true,
46+
},
47+
},
48+
});
49+
});
50+
51+
it('should not adorn tags, event field does not exist', () => {
52+
const uow = {
53+
pipeline: 'thing-pipeline',
54+
};
55+
const event = adornStandardTags('emit')(uow);
56+
expect(event).to.deep.equal(uow);
57+
});
58+
59+
it('should not adorn tags, event field is empty object', () => {
60+
const uow = {
61+
pipeline: 'thing-pipeline',
62+
emit: {},
63+
};
64+
const event = adornStandardTags('emit')(uow);
65+
expect(event).to.deep.equal(uow);
66+
});
67+
});

0 commit comments

Comments
 (0)