|
| 1 | +import { Template } from '@aws-cdk/assertions'; |
| 2 | +import * as cdk from '@aws-cdk/core'; |
| 3 | +import * as iotevents from '../lib'; |
| 4 | + |
| 5 | +test('Default property', () => { |
| 6 | + const stack = new cdk.Stack(); |
| 7 | + |
| 8 | + // WHEN |
| 9 | + new iotevents.Input(stack, 'MyInput', { |
| 10 | + attributeJsonPaths: ['payload.temperature'], |
| 11 | + }); |
| 12 | + |
| 13 | + // THEN |
| 14 | + Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::Input', { |
| 15 | + InputDefinition: { |
| 16 | + Attributes: [{ JsonPath: 'payload.temperature' }], |
| 17 | + }, |
| 18 | + }); |
| 19 | +}); |
| 20 | + |
| 21 | +test('can get input name', () => { |
| 22 | + const stack = new cdk.Stack(); |
| 23 | + // GIVEN |
| 24 | + const input = new iotevents.Input(stack, 'MyInput', { |
| 25 | + attributeJsonPaths: ['payload.temperature'], |
| 26 | + }); |
| 27 | + |
| 28 | + // WHEN |
| 29 | + new cdk.CfnResource(stack, 'Res', { |
| 30 | + type: 'Test::Resource', |
| 31 | + properties: { |
| 32 | + InputName: input.inputName, |
| 33 | + }, |
| 34 | + }); |
| 35 | + |
| 36 | + // THEN |
| 37 | + Template.fromStack(stack).hasResourceProperties('Test::Resource', { |
| 38 | + InputName: { Ref: 'MyInput08947B23' }, |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
| 42 | +test('can set physical name', () => { |
| 43 | + const stack = new cdk.Stack(); |
| 44 | + |
| 45 | + // WHEN |
| 46 | + new iotevents.Input(stack, 'MyInput', { |
| 47 | + inputName: 'test_input', |
| 48 | + attributeJsonPaths: ['payload.temperature'], |
| 49 | + }); |
| 50 | + |
| 51 | + // THEN |
| 52 | + Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::Input', { |
| 53 | + InputName: 'test_input', |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +test('can import a Input by inputName', () => { |
| 58 | + const stack = new cdk.Stack(); |
| 59 | + |
| 60 | + // WHEN |
| 61 | + const inputName = 'test-input-name'; |
| 62 | + const topicRule = iotevents.Input.fromInputName(stack, 'InputFromInputName', inputName); |
| 63 | + |
| 64 | + // THEN |
| 65 | + expect(topicRule).toMatchObject({ |
| 66 | + inputName, |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +test('cannot be created with an empty array of attributeJsonPaths', () => { |
| 71 | + const stack = new cdk.Stack(); |
| 72 | + |
| 73 | + expect(() => { |
| 74 | + new iotevents.Input(stack, 'MyInput', { |
| 75 | + attributeJsonPaths: [], |
| 76 | + }); |
| 77 | + }).toThrow('attributeJsonPaths property cannot be empty'); |
| 78 | +}); |
0 commit comments