FeatureFlagTests.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const { expect } = require('chai')
  2. const SandboxedModule = require('sandboxed-module')
  3. const modulePath = require('path').join(
  4. __dirname,
  5. '../../../../app/src/Features/Helpers/FeatureFlag'
  6. )
  7. describe('FeatureFlag', function () {
  8. beforeEach(function () {
  9. this.FeatureFlag = SandboxedModule.require(modulePath, {})
  10. })
  11. describe('shouldDisplayFeature', function () {
  12. describe('no req.query', function () {
  13. const req = {}
  14. it('should return false when variantFlag=false', function () {
  15. expect(this.FeatureFlag.shouldDisplayFeature(req, '', false)).to.be
  16. .false
  17. })
  18. it('should return true when variantFlag=true', function () {
  19. expect(this.FeatureFlag.shouldDisplayFeature(req, '', true)).to.be.true
  20. })
  21. })
  22. describe('req.query but no query param', function () {
  23. const req = { query: {} }
  24. it('should return false when variantFlag=false', function () {
  25. expect(this.FeatureFlag.shouldDisplayFeature(req, '', false)).to.be
  26. .false
  27. })
  28. it('should return true when variantFlag=true', function () {
  29. expect(this.FeatureFlag.shouldDisplayFeature(req, '', true)).to.be.true
  30. })
  31. })
  32. describe('req.query[name] exists', function () {
  33. const paramName = 'test'
  34. const req = { query: {} }
  35. it('should return false when value is not "true"', function () {
  36. req.query[paramName] = 'nope'
  37. expect(this.FeatureFlag.shouldDisplayFeature(req, paramName, false)).to
  38. .be.false
  39. })
  40. it('should return true when value is "true"', function () {
  41. req.query[paramName] = 'true'
  42. expect(this.FeatureFlag.shouldDisplayFeature(req, paramName, false)).to
  43. .be.true
  44. })
  45. })
  46. })
  47. })