|
14 | 14 |
|
15 | 15 | 'use strict'; |
16 | 16 |
|
| 17 | +const Composer = require('../lib/composer'); |
17 | 18 | const Cucumber = require('cucumber'); |
18 | 19 | const path = require('path'); |
19 | 20 |
|
@@ -64,113 +65,167 @@ function runCucumberTest (featureSource) { |
64 | 65 |
|
65 | 66 | describe('Cucumber', () => { |
66 | 67 |
|
67 | | - it('should rethrow any errors if errors are not expected', () => { |
68 | | - const featureSource = ` |
69 | | - Feature: test |
70 | | - Background: |
71 | | - Given I have deployed the business network archive basic-sample-network.bna |
72 | | - Scenario: test |
73 | | - Given I have added the following asset of type org.acme.sample.SampleAsset |
74 | | - | assetId | owner | value | |
75 | | - |
76 | | - When I add the following asset of type org.acme.sample.SampleAsset |
77 | | - | assetId | owner | value | |
78 | | - |
79 | | - `; |
80 | | - return runCucumberTest(featureSource) |
81 | | - .should.eventually.be.false; |
82 | | - }); |
83 | | - |
84 | | - it('should handle any errors if errors are expected', async () => { |
85 | | - const featureSource = ` |
86 | | - Feature: test |
87 | | - Background: |
88 | | - Given I have deployed the business network archive basic-sample-network.bna |
89 | | - Scenario: test |
90 | | - Given I have added the following asset of type org.acme.sample.SampleAsset |
91 | | - | assetId | owner | value | |
92 | | - |
93 | | - When I add the following asset of type org.acme.sample.SampleAsset |
94 | | - | assetId | owner | value | |
95 | | - |
96 | | - Then I should get an error |
97 | | - `; |
98 | | - |
99 | | - let result = await runCucumberTest(featureSource); |
100 | | - return result.should.be.true; |
101 | | - |
102 | | - }); |
| 68 | + describe('error handling', () => { |
| 69 | + |
| 70 | + it('should rethrow any errors if errors are not expected', () => { |
| 71 | + const featureSource = ` |
| 72 | + Feature: test |
| 73 | + Background: |
| 74 | + Given I have deployed the business network archive basic-sample-network.bna |
| 75 | + Scenario: test |
| 76 | + Given I have added the following asset of type org.acme.sample.SampleAsset |
| 77 | + | assetId | owner | value | |
| 78 | + |
| 79 | + When I add the following asset of type org.acme.sample.SampleAsset |
| 80 | + | assetId | owner | value | |
| 81 | + |
| 82 | + `; |
| 83 | + return runCucumberTest(featureSource) |
| 84 | + .should.eventually.be.false; |
| 85 | + }); |
| 86 | + |
| 87 | + it('should handle any errors if errors are expected', async () => { |
| 88 | + const featureSource = ` |
| 89 | + Feature: test |
| 90 | + Background: |
| 91 | + Given I have deployed the business network archive basic-sample-network.bna |
| 92 | + Scenario: test |
| 93 | + Given I have added the following asset of type org.acme.sample.SampleAsset |
| 94 | + | assetId | owner | value | |
| 95 | + |
| 96 | + When I add the following asset of type org.acme.sample.SampleAsset |
| 97 | + | assetId | owner | value | |
| 98 | + |
| 99 | + Then I should get an error |
| 100 | + `; |
| 101 | + |
| 102 | + let result = await runCucumberTest(featureSource); |
| 103 | + return result.should.be.true; |
| 104 | + |
| 105 | + }); |
| 106 | + |
| 107 | + it('should throw if multiple errors are caught when errors are expected', () => { |
| 108 | + const featureSource = ` |
| 109 | + Feature: test |
| 110 | + Background: |
| 111 | + Given I have deployed the business network archive basic-sample-network.bna |
| 112 | + Scenario: test |
| 113 | + Given I have added the following asset of type org.acme.sample.SampleAsset |
| 114 | + | assetId | owner | value | |
| 115 | + |
| 116 | + When I add the following asset of type org.acme.sample.SampleAsset |
| 117 | + | assetId | owner | value | |
| 118 | + |
| 119 | + And I add the following asset of type org.acme.sample.SampleAsset |
| 120 | + | assetId | owner | value | |
| 121 | + |
| 122 | + Then I should get an error |
| 123 | + `; |
| 124 | + return runCucumberTest(featureSource) |
| 125 | + .should.eventually.be.false; |
| 126 | + }); |
| 127 | + |
| 128 | + it('should throw if errors are expected but none are thrown', () => { |
| 129 | + const featureSource = ` |
| 130 | + Feature: test |
| 131 | + Background: |
| 132 | + Given I have deployed the business network archive basic-sample-network.bna |
| 133 | + Scenario: test |
| 134 | + Given I have added the following asset of type org.acme.sample.SampleAsset |
| 135 | + | assetId | owner | value | |
| 136 | + |
| 137 | + Then I should get an error |
| 138 | + `; |
| 139 | + return runCucumberTest(featureSource) |
| 140 | + .should.eventually.be.false; |
| 141 | + }); |
| 142 | + |
| 143 | + it('should handle any errors that are expected and match the regular expression', () => { |
| 144 | + const featureSource = ` |
| 145 | + Feature: test |
| 146 | + Background: |
| 147 | + Given I have deployed the business network archive basic-sample-network.bna |
| 148 | + Scenario: test |
| 149 | + Given I have added the following asset of type org.acme.sample.SampleAsset |
| 150 | + | assetId | owner | value | |
| 151 | + |
| 152 | + When I add the following asset of type org.acme.sample.SampleAsset |
| 153 | + | assetId | owner | value | |
| 154 | + |
| 155 | + Then I should get an error matching /.*/ |
| 156 | + `; |
| 157 | + return runCucumberTest(featureSource) |
| 158 | + .should.eventually.be.true; |
| 159 | + }); |
| 160 | + |
| 161 | + it('should throw if errors are expected but they do not match the regular expression', () => { |
| 162 | + const featureSource = ` |
| 163 | + Feature: test |
| 164 | + Background: |
| 165 | + Given I have deployed the business network archive basic-sample-network.bna |
| 166 | + Scenario: test |
| 167 | + Given I have added the following asset of type org.acme.sample.SampleAsset |
| 168 | + | assetId | owner | value | |
| 169 | + |
| 170 | + When I add the following asset of type org.acme.sample.SampleAsset |
| 171 | + | assetId | owner | value | |
| 172 | + |
| 173 | + Then I should get an error matching /blah blah blah/ |
| 174 | + `; |
| 175 | + return runCucumberTest(featureSource) |
| 176 | + .should.eventually.be.false; |
| 177 | + }); |
103 | 178 |
|
104 | | - it('should throw if multiple errors are caught when errors are expected', () => { |
105 | | - const featureSource = ` |
106 | | - Feature: test |
107 | | - Background: |
108 | | - Given I have deployed the business network archive basic-sample-network.bna |
109 | | - Scenario: test |
110 | | - Given I have added the following asset of type org.acme.sample.SampleAsset |
111 | | - | assetId | owner | value | |
112 | | - |
113 | | - When I add the following asset of type org.acme.sample.SampleAsset |
114 | | - | assetId | owner | value | |
115 | | - |
116 | | - And I add the following asset of type org.acme.sample.SampleAsset |
117 | | - | assetId | owner | value | |
118 | | - |
119 | | - Then I should get an error |
120 | | - `; |
121 | | - return runCucumberTest(featureSource) |
122 | | - .should.eventually.be.false; |
123 | 179 | }); |
124 | 180 |
|
125 | | - it('should throw if errors are expected but none are thrown', () => { |
126 | | - const featureSource = ` |
127 | | - Feature: test |
128 | | - Background: |
129 | | - Given I have deployed the business network archive basic-sample-network.bna |
130 | | - Scenario: test |
131 | | - Given I have added the following asset of type org.acme.sample.SampleAsset |
132 | | - | assetId | owner | value | |
133 | | - |
134 | | - Then I should get an error |
135 | | - `; |
136 | | - return runCucumberTest(featureSource) |
137 | | - .should.eventually.be.false; |
138 | | - }); |
139 | | - |
140 | | - it('should handle any errors that are expected and match the regular expression', () => { |
141 | | - const featureSource = ` |
142 | | - Feature: test |
143 | | - Background: |
144 | | - Given I have deployed the business network archive basic-sample-network.bna |
145 | | - Scenario: test |
146 | | - Given I have added the following asset of type org.acme.sample.SampleAsset |
147 | | - | assetId | owner | value | |
148 | | - |
149 | | - When I add the following asset of type org.acme.sample.SampleAsset |
150 | | - | assetId | owner | value | |
151 | | - |
152 | | - Then I should get an error matching /.*/ |
153 | | - `; |
154 | | - return runCucumberTest(featureSource) |
155 | | - .should.eventually.be.true; |
156 | | - }); |
| 181 | + describe('#convertValueToType', () => { |
| 182 | + |
| 183 | + it('should handle boolean values', () => { |
| 184 | + const composer = new Composer(); |
| 185 | + composer.convertValueToType('false', 'Boolean').should.be.false; |
| 186 | + composer.convertValueToType('true', 'Boolean').should.be.true; |
| 187 | + (() => { |
| 188 | + composer.convertValueToType('blah', 'Boolean'); |
| 189 | + }).should.throw(/Invalid value "blah" for type "Boolean"/); |
| 190 | + }); |
| 191 | + |
| 192 | + it('should handle date values', () => { |
| 193 | + const composer = new Composer(); |
| 194 | + composer.convertValueToType('2018-04-20T15:06:37.919Z', 'DateTime').toISOString().should.equal('2018-04-20T15:06:37.919Z'); |
| 195 | + (() => { |
| 196 | + composer.convertValueToType('blah', 'DateTime'); |
| 197 | + }).should.throw(/Invalid value "blah" for type "DateTime"/); |
| 198 | + }); |
| 199 | + |
| 200 | + it('should handle double values', () => { |
| 201 | + const composer = new Composer(); |
| 202 | + composer.convertValueToType('3.142', 'Double').should.equal(3.142); |
| 203 | + (() => { |
| 204 | + composer.convertValueToType('blah', 'Double'); |
| 205 | + }).should.throw(/Invalid value "blah" for type "Double"/); |
| 206 | + }); |
| 207 | + |
| 208 | + it('should handle integer values', () => { |
| 209 | + const composer = new Composer(); |
| 210 | + composer.convertValueToType('1234', 'Integer').should.equal(1234); |
| 211 | + (() => { |
| 212 | + composer.convertValueToType('blah', 'Integer'); |
| 213 | + }).should.throw(/Invalid value "blah" for type "Integer"/); |
| 214 | + }); |
| 215 | + |
| 216 | + it('should handle long values', () => { |
| 217 | + const composer = new Composer(); |
| 218 | + composer.convertValueToType('12345678', 'Long').should.equal(12345678); |
| 219 | + (() => { |
| 220 | + composer.convertValueToType('blah', 'Long'); |
| 221 | + }).should.throw(/Invalid value "blah" for type "Long"/); |
| 222 | + }); |
| 223 | + |
| 224 | + it('should handle string values', () => { |
| 225 | + const composer = new Composer(); |
| 226 | + composer.convertValueToType('12345678', 'String').should.equal('12345678'); |
| 227 | + }); |
157 | 228 |
|
158 | | - it('should throw if errors are expected but they do not match the regular expression', () => { |
159 | | - const featureSource = ` |
160 | | - Feature: test |
161 | | - Background: |
162 | | - Given I have deployed the business network archive basic-sample-network.bna |
163 | | - Scenario: test |
164 | | - Given I have added the following asset of type org.acme.sample.SampleAsset |
165 | | - | assetId | owner | value | |
166 | | - |
167 | | - When I add the following asset of type org.acme.sample.SampleAsset |
168 | | - | assetId | owner | value | |
169 | | - |
170 | | - Then I should get an error matching /blah blah blah/ |
171 | | - `; |
172 | | - return runCucumberTest(featureSource) |
173 | | - .should.eventually.be.false; |
174 | 229 | }); |
175 | 230 |
|
176 | 231 | }); |
0 commit comments