|
| 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