Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validation-strategy.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * @filedescription Merge Strategy Tests
  3. */
  4. /* global it, describe, beforeEach */
  5. "use strict";
  6. //-----------------------------------------------------------------------------
  7. // Requirements
  8. //-----------------------------------------------------------------------------
  9. const assert = require("chai").assert;
  10. const { ValidationStrategy } = require("../src/");
  11. //-----------------------------------------------------------------------------
  12. // Class
  13. //-----------------------------------------------------------------------------
  14. describe("ValidationStrategy", () => {
  15. describe("boolean", () => {
  16. it("should not throw an error when the value is a boolean", () => {
  17. ValidationStrategy.boolean(true);
  18. });
  19. it("should throw an error when the value is null", () => {
  20. assert.throws(() => {
  21. ValidationStrategy.boolean(null);
  22. }, /Expected a Boolean/);
  23. });
  24. it("should throw an error when the value is a string", () => {
  25. assert.throws(() => {
  26. ValidationStrategy.boolean("foo");
  27. }, /Expected a Boolean/);
  28. });
  29. it("should throw an error when the value is a number", () => {
  30. assert.throws(() => {
  31. ValidationStrategy.boolean(123);
  32. }, /Expected a Boolean/);
  33. });
  34. it("should throw an error when the value is an object", () => {
  35. assert.throws(() => {
  36. ValidationStrategy.boolean({});
  37. }, /Expected a Boolean/);
  38. });
  39. });
  40. describe("number", () => {
  41. it("should not throw an error when the value is a number", () => {
  42. ValidationStrategy.number(25);
  43. });
  44. it("should throw an error when the value is null", () => {
  45. assert.throws(() => {
  46. ValidationStrategy.number(null);
  47. }, /Expected a number/);
  48. });
  49. it("should throw an error when the value is a string", () => {
  50. assert.throws(() => {
  51. ValidationStrategy.number("foo");
  52. }, /Expected a number/);
  53. });
  54. it("should throw an error when the value is a boolean", () => {
  55. assert.throws(() => {
  56. ValidationStrategy.number(true);
  57. }, /Expected a number/);
  58. });
  59. it("should throw an error when the value is an object", () => {
  60. assert.throws(() => {
  61. ValidationStrategy.number({});
  62. }, /Expected a number/);
  63. });
  64. });
  65. describe("object", () => {
  66. it("should not throw an error when the value is an object", () => {
  67. ValidationStrategy.object({});
  68. });
  69. it("should throw an error when the value is null", () => {
  70. assert.throws(() => {
  71. ValidationStrategy.object(null);
  72. }, /Expected an object/);
  73. });
  74. it("should throw an error when the value is a string", () => {
  75. assert.throws(() => {
  76. ValidationStrategy.object("");
  77. }, /Expected an object/);
  78. });
  79. });
  80. describe("array", () => {
  81. it("should not throw an error when the value is an array", () => {
  82. ValidationStrategy.array([]);
  83. });
  84. it("should throw an error when the value is null", () => {
  85. assert.throws(() => {
  86. ValidationStrategy.array(null);
  87. }, /Expected an array/);
  88. });
  89. it("should throw an error when the value is a string", () => {
  90. assert.throws(() => {
  91. ValidationStrategy.array("");
  92. }, /Expected an array/);
  93. });
  94. it("should throw an error when the value is an object", () => {
  95. assert.throws(() => {
  96. ValidationStrategy.array({});
  97. }, /Expected an array/);
  98. });
  99. });
  100. describe("object?", () => {
  101. it("should not throw an error when the value is an object", () => {
  102. ValidationStrategy["object?"]({});
  103. });
  104. it("should not throw an error when the value is null", () => {
  105. ValidationStrategy["object?"](null);
  106. });
  107. it("should throw an error when the value is a string", () => {
  108. assert.throws(() => {
  109. ValidationStrategy["object?"]("");
  110. }, /Expected an object/);
  111. });
  112. });
  113. describe("string", () => {
  114. it("should not throw an error when the value is a string", () => {
  115. ValidationStrategy.string("foo");
  116. });
  117. it("should not throw an error when the value is an empty string", () => {
  118. ValidationStrategy.string("");
  119. });
  120. it("should throw an error when the value is null", () => {
  121. assert.throws(() => {
  122. ValidationStrategy.string(null);
  123. }, /Expected a string/);
  124. });
  125. it("should throw an error when the value is an object", () => {
  126. assert.throws(() => {
  127. ValidationStrategy.string({});
  128. }, /Expected a string/);
  129. });
  130. });
  131. describe("string!", () => {
  132. it("should not throw an error when the value is an string", () => {
  133. ValidationStrategy["string!"]("foo");
  134. });
  135. it("should throw an error when the value is an empty string", () => {
  136. assert.throws(() => {
  137. ValidationStrategy["string!"]("");
  138. }, /Expected a non-empty string/);
  139. });
  140. it("should throw an error when the value is null", () => {
  141. assert.throws(() => {
  142. ValidationStrategy["string!"](null);
  143. }, /Expected a non-empty string/);
  144. });
  145. it("should throw an error when the value is an object", () => {
  146. assert.throws(() => {
  147. ValidationStrategy["string!"]({});
  148. }, /Expected a non-empty string/);
  149. });
  150. });
  151. });