|
4 | 4 | import { assert } from "chai"; |
5 | 5 | import { areTagsEqual, isJsonContentType, isConfigSettingEqual } from "../src/internal/utils"; |
6 | 6 | import { ConfigurationSetting, FeatureFlagValue, SetConfigurationSettingParam } from "@azure/app-configuration"; |
| 7 | +import { MsFeatureFlagValue } from "../src/featureFlag"; |
7 | 8 |
|
8 | 9 | describe("Test the utility methods", () => { |
9 | 10 | it("Determine the content type is json contentType", async () => { |
@@ -244,9 +245,92 @@ describe("Test the utility methods", () => { |
244 | 245 | isReadOnly: true |
245 | 246 | }; |
246 | 247 |
|
| 248 | + const testKeyValue7: SetConfigurationSettingParam<MsFeatureFlagValue> = { |
| 249 | + key: "FeatureX", |
| 250 | + label: "test", |
| 251 | + value: { |
| 252 | + id: "time001", |
| 253 | + enabled: true, |
| 254 | + description: "", |
| 255 | + conditions: { |
| 256 | + clientFilters: [] |
| 257 | + }, |
| 258 | + allocation: { |
| 259 | + percentile: [ |
| 260 | + { |
| 261 | + variant: "Off", |
| 262 | + from: 0, |
| 263 | + to: 23 |
| 264 | + }, |
| 265 | + { |
| 266 | + variant: "On", |
| 267 | + from: 23, |
| 268 | + to: 100 |
| 269 | + } |
| 270 | + ], |
| 271 | + group: [ |
| 272 | + { |
| 273 | + variant: "On", |
| 274 | + groups: [ |
| 275 | + "m1" |
| 276 | + ] |
| 277 | + }, |
| 278 | + { |
| 279 | + variant: "Off", |
| 280 | + groups: [ |
| 281 | + "m2", |
| 282 | + "m3" |
| 283 | + ] |
| 284 | + } |
| 285 | + ], |
| 286 | + user: [ |
| 287 | + { |
| 288 | + variant: "Off", |
| 289 | + users: [ |
| 290 | + "user1", |
| 291 | + "user3" |
| 292 | + ] |
| 293 | + }, |
| 294 | + { |
| 295 | + variant: "On", |
| 296 | + users: [ |
| 297 | + "user2" |
| 298 | + ] |
| 299 | + } |
| 300 | + ], |
| 301 | + seed: "bcngrfgnfgn", |
| 302 | + default_when_enabled: "On", |
| 303 | + default_when_disabled: "On" |
| 304 | + }, |
| 305 | + variants: [ |
| 306 | + { |
| 307 | + name: "Off", |
| 308 | + configuration_value: false |
| 309 | + }, |
| 310 | + { |
| 311 | + name: "On", |
| 312 | + configuration_value: true |
| 313 | + } |
| 314 | + ] |
| 315 | + }, |
| 316 | + contentType: "application/vnd.microsoft.appconfig.ff+json;charset=utf-8", |
| 317 | + tags: {tag1: "tag1"} |
| 318 | + }; |
| 319 | + |
| 320 | + const testKeyValue8: ConfigurationSetting = { |
| 321 | + key: "FeatureX", |
| 322 | + label: "test", |
| 323 | + value: "{\"id\":\"time001\",\"enabled\":true,\"description\":\"\",\"conditions\":{\"client_filters\":[]},\"allocation\":{\"percentile\":[{\"variant\":\"Off\",\"from\":0,\"to\":23},{\"variant\":\"On\",\"from\":23,\"to\":100}],\"group\":[{\"variant\":\"On\",\"groups\":[\"m1\"]},{\"variant\":\"Off\",\"groups\":[\"m2\",\"m3\"]}],\"user\":[{\"variant\":\"Off\",\"users\":[\"user1\",\"user3\"]},{\"variant\":\"On\",\"users\":[\"user2\"]}],\"seed\":\"bcngrfgnfgn\",\"default_when_enabled\":\"On\",\"default_when_disabled\":\"On\"},\"variants\":[{\"name\":\"Off\",\"configuration_value\":false},{\"name\":\"On\",\"configuration_value\":true}]}", |
| 324 | + contentType: "application/vnd.microsoft.appconfig.ff+json;charset=utf-8", |
| 325 | + tags: {tag1: "tag1"}, |
| 326 | + isReadOnly: true |
| 327 | + }; |
| 328 | + |
| 329 | + |
247 | 330 | assert.isTrue(isConfigSettingEqual(testKeyValue1, testKeyValue2)); |
248 | 331 | assert.isTrue(isConfigSettingEqual(testKeyValue3, testKeyValue4)); |
249 | 332 | assert.isTrue(isConfigSettingEqual(testKeyValue5, testKeyValue6)); |
| 333 | + assert.isTrue(isConfigSettingEqual(testKeyValue7, testKeyValue8)); |
250 | 334 | }); |
251 | 335 |
|
252 | 336 | it("Determine if feature flag values with different values are not equal", async()=> { |
@@ -339,9 +423,91 @@ describe("Test the utility methods", () => { |
339 | 423 | isReadOnly: true |
340 | 424 | }; |
341 | 425 |
|
| 426 | + const testKeyValue9: SetConfigurationSettingParam<MsFeatureFlagValue> = { |
| 427 | + key: "FeatureX", |
| 428 | + label: "test", |
| 429 | + value: { |
| 430 | + id: "time001", |
| 431 | + enabled: true, |
| 432 | + description: "", |
| 433 | + conditions: { |
| 434 | + clientFilters: [] |
| 435 | + }, |
| 436 | + allocation: { |
| 437 | + percentile: [ |
| 438 | + { |
| 439 | + variant: "Off", |
| 440 | + from: 0, |
| 441 | + to: 23 |
| 442 | + }, |
| 443 | + { |
| 444 | + variant: "On", |
| 445 | + from: 23, |
| 446 | + to: 100 |
| 447 | + } |
| 448 | + ], |
| 449 | + group: [ |
| 450 | + { |
| 451 | + variant: "On", |
| 452 | + groups: [ |
| 453 | + "m1" |
| 454 | + ] |
| 455 | + }, |
| 456 | + { |
| 457 | + variant: "Off", |
| 458 | + groups: [ |
| 459 | + "m2", |
| 460 | + "m3" |
| 461 | + ] |
| 462 | + } |
| 463 | + ], |
| 464 | + user: [ |
| 465 | + { |
| 466 | + variant: "Off", |
| 467 | + users: [ |
| 468 | + "user1", |
| 469 | + "user3" |
| 470 | + ] |
| 471 | + }, |
| 472 | + { |
| 473 | + variant: "On", |
| 474 | + users: [ |
| 475 | + "user2" |
| 476 | + ] |
| 477 | + } |
| 478 | + ], |
| 479 | + seed: "bcngrfgnfgn", |
| 480 | + default_when_enabled: "On", |
| 481 | + default_when_disabled: "On" |
| 482 | + }, |
| 483 | + variants: [ |
| 484 | + { |
| 485 | + name: "Off", |
| 486 | + configuration_value: false |
| 487 | + }, |
| 488 | + { |
| 489 | + name: "On", |
| 490 | + configuration_value: true |
| 491 | + } |
| 492 | + ] |
| 493 | + }, |
| 494 | + contentType: "application/vnd.microsoft.appconfig.ff+json;charset=utf-8", |
| 495 | + tags: { tag1: "tag1" } |
| 496 | + }; |
| 497 | + |
| 498 | + const testKeyValue10: ConfigurationSetting = { |
| 499 | + key: "FeatureX", |
| 500 | + label: "test", |
| 501 | + value: "{\"id\":\"time001\",\"enabled\":true,\"description\":\"\",\"conditions\":{\"client_filters\":[]},\"allocation\":{\"percentile\":[{\"variant\":\"Off\",\"from\":0,\"to\":23},{\"variant\":\"On\",\"from\":23,\"to\":100}],\"group\":[{\"variant\":\"On\",\"groups\":[\"m1\"]},{\"variant\":\"Off\",\"groups\":[\"m2\",\"m3\"]}],\"user\":[{\"variant\":\"Off\",\"users\":[\"user1\",\"user3\"]},{\"variant\":\"On\",\"users\":[\"user2\"]}],\"seed\":\"bcngrfgnfgn\",\"default_when_enabled\":\"On\",\"default_when_disabled\":\"On\"},\"variants\":[{\"name\":\"Off\",\"configuration_value\":false},{\"name\":\"On\",\"configuration_value\":true,\"status_override\":\"None\"}]}", |
| 502 | + contentType: "application/vnd.microsoft.appconfig.ff+json;charset=utf-8", |
| 503 | + tags: {}, |
| 504 | + isReadOnly: true |
| 505 | + }; |
| 506 | + |
342 | 507 | assert.isFalse(isConfigSettingEqual(testKeyValue1, testKeyValue2)); |
343 | 508 | assert.isFalse(isConfigSettingEqual(testKeyValue3, testKeyValue4)); |
344 | 509 | assert.isFalse(isConfigSettingEqual(testKeyValue5, testKeyValue6)); |
345 | 510 | assert.isFalse(isConfigSettingEqual(testKeyValue7, testKeyValue8)); |
| 511 | + assert.isFalse(isConfigSettingEqual(testKeyValue9, testKeyValue10)); |
346 | 512 | }); |
347 | 513 | }); |
0 commit comments