notificationChannel.test.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { NotificationChannelDTO } from '../../../types';
  2. import { transformSubmitData } from './notificationChannels';
  3. const basicFormData: NotificationChannelDTO = {
  4. id: 1,
  5. uid: 'pX7fbbHGk',
  6. name: 'Pete discord',
  7. type: {
  8. value: 'discord',
  9. label: 'Discord',
  10. type: 'discord',
  11. name: 'Discord',
  12. heading: 'Discord settings',
  13. description: 'Sends notifications to Discord',
  14. info: '',
  15. options: [
  16. {
  17. element: 'input',
  18. inputType: 'text',
  19. label: 'Message Content',
  20. description: 'Mention a group using @ or a user using <@ID> when notifying in a channel',
  21. placeholder: '',
  22. propertyName: 'content',
  23. selectOptions: null,
  24. showWhen: { field: '', is: '' },
  25. required: false,
  26. validationRule: '',
  27. secure: false,
  28. },
  29. {
  30. element: 'input',
  31. inputType: 'text',
  32. label: 'Webhook URL',
  33. description: '',
  34. placeholder: 'Discord webhook URL',
  35. propertyName: 'url',
  36. selectOptions: null,
  37. showWhen: { field: '', is: '' },
  38. required: true,
  39. validationRule: '',
  40. secure: false,
  41. },
  42. ],
  43. typeName: 'discord',
  44. },
  45. isDefault: false,
  46. sendReminder: false,
  47. disableResolveMessage: false,
  48. frequency: '',
  49. created: '2020-08-24T10:46:43+02:00',
  50. updated: '2020-09-02T14:08:27+02:00',
  51. settings: {
  52. url: 'https://discordapp.com/api/webhooks/',
  53. uploadImage: true,
  54. content: '',
  55. autoResolve: true,
  56. httpMethod: 'POST',
  57. severity: 'critical',
  58. },
  59. secureFields: {},
  60. secureSettings: {},
  61. };
  62. const selectFormData: NotificationChannelDTO = {
  63. id: 23,
  64. uid: 'BxEN9rNGk',
  65. name: 'Webhook',
  66. type: {
  67. value: 'webhook',
  68. label: 'webhook',
  69. type: 'webhook',
  70. name: 'webhook',
  71. heading: 'Webhook settings',
  72. description: 'Sends HTTP POST request to a URL',
  73. info: '',
  74. options: [
  75. {
  76. element: 'input',
  77. inputType: 'text',
  78. label: 'Url',
  79. description: '',
  80. placeholder: '',
  81. propertyName: 'url',
  82. selectOptions: null,
  83. showWhen: { field: '', is: '' },
  84. required: true,
  85. validationRule: '',
  86. secure: false,
  87. },
  88. {
  89. element: 'select',
  90. inputType: '',
  91. label: 'Http Method',
  92. description: '',
  93. placeholder: '',
  94. propertyName: 'httpMethod',
  95. selectOptions: [
  96. { value: 'POST', label: 'POST' },
  97. { value: 'PUT', label: 'PUT' },
  98. ],
  99. showWhen: { field: '', is: '' },
  100. required: false,
  101. validationRule: '',
  102. secure: false,
  103. },
  104. {
  105. element: 'input',
  106. inputType: 'text',
  107. label: 'Username',
  108. description: '',
  109. placeholder: '',
  110. propertyName: 'username',
  111. selectOptions: null,
  112. showWhen: { field: '', is: '' },
  113. required: false,
  114. validationRule: '',
  115. secure: false,
  116. },
  117. {
  118. element: 'input',
  119. inputType: 'password',
  120. label: 'Password',
  121. description: '',
  122. placeholder: '',
  123. propertyName: 'password',
  124. selectOptions: null,
  125. showWhen: { field: '', is: '' },
  126. required: false,
  127. validationRule: '',
  128. secure: true,
  129. },
  130. ],
  131. typeName: 'webhook',
  132. },
  133. isDefault: false,
  134. sendReminder: false,
  135. disableResolveMessage: false,
  136. frequency: '',
  137. created: '2020-08-28T10:47:37+02:00',
  138. updated: '2020-09-03T09:37:21+02:00',
  139. settings: {
  140. autoResolve: true,
  141. httpMethod: 'POST',
  142. password: '',
  143. severity: 'critical',
  144. uploadImage: true,
  145. url: 'http://asdf',
  146. username: 'asdf',
  147. },
  148. secureFields: { password: true },
  149. secureSettings: {},
  150. };
  151. describe('Transform submit data', () => {
  152. it('basic transform', () => {
  153. const expected = {
  154. id: 1,
  155. name: 'Pete discord',
  156. type: 'discord',
  157. sendReminder: false,
  158. disableResolveMessage: false,
  159. frequency: '15m',
  160. settings: {
  161. uploadImage: true,
  162. autoResolve: true,
  163. httpMethod: 'POST',
  164. severity: 'critical',
  165. url: 'https://discordapp.com/api/webhooks/',
  166. content: '',
  167. },
  168. secureSettings: {},
  169. secureFields: {},
  170. isDefault: false,
  171. uid: 'pX7fbbHGk',
  172. created: '2020-08-24T10:46:43+02:00',
  173. updated: '2020-09-02T14:08:27+02:00',
  174. };
  175. expect(transformSubmitData(basicFormData)).toEqual(expected);
  176. });
  177. it('should transform form data with selects', () => {
  178. const expected = {
  179. created: '2020-08-28T10:47:37+02:00',
  180. disableResolveMessage: false,
  181. frequency: '15m',
  182. id: 23,
  183. isDefault: false,
  184. name: 'Webhook',
  185. secureFields: { password: true },
  186. secureSettings: {},
  187. sendReminder: false,
  188. settings: {
  189. autoResolve: true,
  190. httpMethod: 'POST',
  191. password: '',
  192. severity: 'critical',
  193. uploadImage: true,
  194. url: 'http://asdf',
  195. username: 'asdf',
  196. },
  197. type: 'webhook',
  198. uid: 'BxEN9rNGk',
  199. updated: '2020-09-03T09:37:21+02:00',
  200. };
  201. expect(transformSubmitData(selectFormData)).toEqual(expected);
  202. });
  203. });