SplitTestUtils.test.mjs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { expect } from 'vitest'
  2. import SplitTestUtils from '../../../../app/src/Features/SplitTests/SplitTestUtils.mjs'
  3. describe('SplitTestUtils', function () {
  4. describe('isExperimentFull', function () {
  5. describe('when userLimit is null or undefined', function () {
  6. it('should return false when userLimit is null', function () {
  7. const variant = {
  8. userLimit: null,
  9. userCount: 5,
  10. }
  11. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  12. })
  13. it('should return false when userLimit is undefined', function () {
  14. const variant = {
  15. userCount: 5,
  16. }
  17. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  18. })
  19. })
  20. describe('when userLimit is not a number', function () {
  21. it.each([
  22. { label: 'NaN', userLimit: NaN },
  23. { label: 'an object', userLimit: {} },
  24. { label: 'a string', userLimit: 'string' },
  25. ])(
  26. 'should return false when userLimit is $label',
  27. function ({ userLimit }) {
  28. const variant = {
  29. userLimit,
  30. userCount: 50,
  31. }
  32. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  33. }
  34. )
  35. })
  36. it('should return true when userLimit is 0', function () {
  37. const variant = {
  38. userLimit: 0,
  39. userCount: 5,
  40. }
  41. expect(SplitTestUtils.isExperimentFull(variant)).toBe(true)
  42. })
  43. it('should treat undefined userCount as 0 and return false when under limit', function () {
  44. const variant = {
  45. userLimit: 100,
  46. }
  47. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  48. })
  49. it('should treat null userCount as 0 and return false when under limit', function () {
  50. const variant = {
  51. userLimit: 100,
  52. userCount: null,
  53. }
  54. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  55. })
  56. it('should treat undefined userCount as 0 and return true when limit is 0', function () {
  57. const variant = {
  58. userLimit: 0,
  59. }
  60. expect(SplitTestUtils.isExperimentFull(variant)).toBe(true)
  61. })
  62. describe('when userCount is below the limit', function () {
  63. it('should return false when userCount is less than userLimit', function () {
  64. const variant = {
  65. userLimit: 100,
  66. userCount: 50,
  67. }
  68. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  69. })
  70. it('should return false when userCount is 1 and userLimit is 100', function () {
  71. const variant = {
  72. userLimit: 100,
  73. userCount: 1,
  74. }
  75. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  76. })
  77. it('should return false when userCount is 0 and userLimit is 100', function () {
  78. const variant = {
  79. userLimit: 100,
  80. userCount: 0,
  81. }
  82. expect(SplitTestUtils.isExperimentFull(variant)).toBe(false)
  83. })
  84. })
  85. it('should return true when userCount equals userLimit', function () {
  86. const variant = {
  87. userLimit: 100,
  88. userCount: 100,
  89. }
  90. expect(SplitTestUtils.isExperimentFull(variant)).toBe(true)
  91. })
  92. it('should return true when userCount is greater than userLimit', function () {
  93. const variant = {
  94. userLimit: 100,
  95. userCount: 150,
  96. }
  97. expect(SplitTestUtils.isExperimentFull(variant)).toBe(true)
  98. })
  99. })
  100. })