variable_specs.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {describe, it, expect} from 'test/lib/common';
  2. import {containsVariable, assignModelProperties} from '../variable';
  3. describe('containsVariable', function() {
  4. describe('when checking if a string contains a variable', function() {
  5. it('should find it with $var syntax', function() {
  6. var contains = containsVariable('this.$test.filters', 'test');
  7. expect(contains).to.be(true);
  8. });
  9. it('should not find it if only part matches with $var syntax', function() {
  10. var contains = containsVariable('this.$serverDomain.filters', 'server');
  11. expect(contains).to.be(false);
  12. });
  13. it('should find it if it ends with variable and passing multiple test strings', function() {
  14. var contains = containsVariable('show field keys from $pgmetric', 'test string2', 'pgmetric');
  15. expect(contains).to.be(true);
  16. });
  17. it('should find it with [[var]] syntax', function() {
  18. var contains = containsVariable('this.[[test]].filters', 'test');
  19. expect(contains).to.be(true);
  20. });
  21. it('should find it when part of segment', function() {
  22. var contains = containsVariable('metrics.$env.$group-*', 'group');
  23. expect(contains).to.be(true);
  24. });
  25. it('should find it its the only thing', function() {
  26. var contains = containsVariable('$env', 'env');
  27. expect(contains).to.be(true);
  28. });
  29. it('should be able to pass in multiple test strings', function() {
  30. var contains = containsVariable('asd','asd2.$env', 'env');
  31. expect(contains).to.be(true);
  32. });
  33. });
  34. });
  35. describe('assignModelProperties', function() {
  36. it('only set properties defined in defaults', function() {
  37. var target: any = {test: 'asd'};
  38. assignModelProperties(target, {propA: 1, propB: 2}, {propB: 0});
  39. expect(target.propB).to.be(2);
  40. expect(target.test).to.be('asd');
  41. });
  42. it('use default value if not found on source', function() {
  43. var target: any = {test: 'asd'};
  44. assignModelProperties(target, {propA: 1, propB: 2}, {propC: 10});
  45. expect(target.propC).to.be(10);
  46. });
  47. });