* Validates the variant schema of a config. * @param {!JsonObject} variant * @param {string} experimentName * @param {string} variantName * @throws {!Error}
(variant, experimentName, variantName)
| 206 | * @throws {!Error} |
| 207 | */ |
| 208 | function assertVariant(variant, experimentName, variantName) { |
| 209 | // Assert that the variant is an object |
| 210 | userAssert( |
| 211 | isObject(variant), |
| 212 | `${experimentName}.variants.${variantName} must be an object.` |
| 213 | ); |
| 214 | |
| 215 | // Assert the variant weight |
| 216 | userAssert( |
| 217 | variant['weight'] !== undefined && typeof variant['weight'] === 'number', |
| 218 | `${experimentName}.variants.${variantName} must have a number weight.` |
| 219 | ); |
| 220 | |
| 221 | // Assert the variant weight is a percentage |
| 222 | const percentage = variant['weight']; |
| 223 | userAssert( |
| 224 | percentage > 0 && percentage < 100, |
| 225 | 'Invalid weight percentage %s.' + |
| 226 | ` ${experimentName}.variants.${variantName}` + |
| 227 | ' Has to be greater than 0 and less than 100', |
| 228 | percentage |
| 229 | ); |
| 230 | |
| 231 | // Assert the variant mutations |
| 232 | userAssert( |
| 233 | variant['mutations'] && isArray(variant['mutations']), |
| 234 | `${experimentName}.variants.${variantName} must have a mutations array.` |
| 235 | ); |
| 236 | } |
no test coverage detected