backfill.spec.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {backfillMissingProvidersWithFallback} from 'sentry/views/settings/account/notifications/utils';
  2. describe('backfillMissingProvidersWithFallback', () => {
  3. describe('when scopeType is user', () => {
  4. it('should add missing provider with the fallback value', () => {
  5. expect(
  6. backfillMissingProvidersWithFallback({}, ['email'], 'sometimes', 'user')
  7. ).toEqual({email: 'sometimes', slack: 'never'});
  8. });
  9. it('should turn on both providers with the fallback value', () => {
  10. expect(
  11. backfillMissingProvidersWithFallback(
  12. {email: 'never', slack: 'never'},
  13. ['email', 'slack'],
  14. 'sometimes',
  15. 'user'
  16. )
  17. ).toEqual({email: 'sometimes', slack: 'sometimes'});
  18. });
  19. it('should move the existing setting when providers are swapped', () => {
  20. expect(
  21. backfillMissingProvidersWithFallback(
  22. {email: 'always', slack: 'never'},
  23. ['slack'],
  24. '',
  25. 'user'
  26. )
  27. ).toEqual({email: 'never', slack: 'always'});
  28. });
  29. it('should turn off both providers when providers is empty', () => {
  30. expect(
  31. backfillMissingProvidersWithFallback(
  32. {email: 'always', slack: 'always'},
  33. [],
  34. '',
  35. 'user'
  36. )
  37. ).toEqual({email: 'never', slack: 'never'});
  38. });
  39. });
  40. describe('when scopeType is organization', () => {
  41. it('should retain OFF organization scope preference when provider list changes', () => {
  42. expect(
  43. backfillMissingProvidersWithFallback(
  44. {email: 'never', slack: 'never'},
  45. ['slack'],
  46. 'sometimes',
  47. 'organization'
  48. )
  49. ).toEqual({email: 'never', slack: 'never'});
  50. });
  51. });
  52. });