actions.spec.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import * as actions from 'redux/actions';
  2. import {
  3. MessageSchemaSourceEnum,
  4. TopicColumnsToSort,
  5. TopicMessageSchema,
  6. } from 'generated-sources';
  7. import { FailurePayload } from 'redux/interfaces';
  8. import {
  9. topicMessagePayload,
  10. topicMessagesMetaPayload,
  11. } from 'redux/reducers/topicMessages/__test__/fixtures';
  12. import { mockTopicsState } from './fixtures';
  13. describe('Actions', () => {
  14. describe('dismissAlert', () => {
  15. it('creates a REQUEST action', () => {
  16. const id = 'alert-id1';
  17. expect(actions.dismissAlert(id)).toEqual({
  18. type: 'DISMISS_ALERT',
  19. payload: id,
  20. });
  21. });
  22. });
  23. describe('clearMessagesTopicAction', () => {
  24. it('creates a REQUEST action', () => {
  25. expect(actions.clearMessagesTopicAction.request()).toEqual({
  26. type: 'CLEAR_TOPIC_MESSAGES__REQUEST',
  27. });
  28. });
  29. it('creates a SUCCESS action', () => {
  30. expect(actions.clearMessagesTopicAction.success()).toEqual({
  31. type: 'CLEAR_TOPIC_MESSAGES__SUCCESS',
  32. });
  33. });
  34. it('creates a FAILURE action', () => {
  35. expect(actions.clearMessagesTopicAction.failure({})).toEqual({
  36. type: 'CLEAR_TOPIC_MESSAGES__FAILURE',
  37. payload: {},
  38. });
  39. });
  40. });
  41. describe('fetchTopicConsumerGroups', () => {
  42. it('creates a REQUEST action', () => {
  43. expect(actions.fetchTopicConsumerGroupsAction.request()).toEqual({
  44. type: 'GET_TOPIC_CONSUMER_GROUPS__REQUEST',
  45. });
  46. });
  47. it('creates a SUCCESS action', () => {
  48. expect(
  49. actions.fetchTopicConsumerGroupsAction.success(mockTopicsState)
  50. ).toEqual({
  51. type: 'GET_TOPIC_CONSUMER_GROUPS__SUCCESS',
  52. payload: mockTopicsState,
  53. });
  54. });
  55. it('creates a FAILURE action', () => {
  56. expect(actions.fetchTopicConsumerGroupsAction.failure()).toEqual({
  57. type: 'GET_TOPIC_CONSUMER_GROUPS__FAILURE',
  58. });
  59. });
  60. });
  61. describe('setTopicsSearchAction', () => {
  62. it('creartes SET_TOPICS_SEARCH', () => {
  63. expect(actions.setTopicsSearchAction('test')).toEqual({
  64. type: 'SET_TOPICS_SEARCH',
  65. payload: 'test',
  66. });
  67. });
  68. });
  69. describe('setTopicsOrderByAction', () => {
  70. it('creartes SET_TOPICS_ORDER_BY', () => {
  71. expect(actions.setTopicsOrderByAction(TopicColumnsToSort.NAME)).toEqual({
  72. type: 'SET_TOPICS_ORDER_BY',
  73. payload: TopicColumnsToSort.NAME,
  74. });
  75. });
  76. });
  77. describe('topic messages', () => {
  78. it('creates ADD_TOPIC_MESSAGE', () => {
  79. expect(actions.addTopicMessage(topicMessagePayload)).toEqual({
  80. type: 'ADD_TOPIC_MESSAGE',
  81. payload: topicMessagePayload,
  82. });
  83. });
  84. it('creates RESET_TOPIC_MESSAGES', () => {
  85. expect(actions.resetTopicMessages()).toEqual({
  86. type: 'RESET_TOPIC_MESSAGES',
  87. });
  88. });
  89. it('creates UPDATE_TOPIC_MESSAGES_PHASE', () => {
  90. expect(actions.updateTopicMessagesPhase('Polling')).toEqual({
  91. type: 'UPDATE_TOPIC_MESSAGES_PHASE',
  92. payload: 'Polling',
  93. });
  94. });
  95. it('creates UPDATE_TOPIC_MESSAGES_META', () => {
  96. expect(actions.updateTopicMessagesMeta(topicMessagesMetaPayload)).toEqual(
  97. {
  98. type: 'UPDATE_TOPIC_MESSAGES_META',
  99. payload: topicMessagesMetaPayload,
  100. }
  101. );
  102. });
  103. });
  104. describe('sending messages', () => {
  105. describe('fetchTopicMessageSchemaAction', () => {
  106. it('creates GET_TOPIC_SCHEMA__REQUEST', () => {
  107. expect(actions.fetchTopicMessageSchemaAction.request()).toEqual({
  108. type: 'GET_TOPIC_SCHEMA__REQUEST',
  109. });
  110. });
  111. it('creates GET_TOPIC_SCHEMA__SUCCESS', () => {
  112. const messageSchema: TopicMessageSchema = {
  113. key: {
  114. name: 'key',
  115. source: MessageSchemaSourceEnum.SCHEMA_REGISTRY,
  116. schema: `{
  117. "$schema": "http://json-schema.org/draft-07/schema#",
  118. "$id": "http://example.com/myURI.schema.json",
  119. "title": "TestRecord",
  120. "type": "object",
  121. "additionalProperties": false,
  122. "properties": {
  123. "f1": {
  124. "type": "integer"
  125. },
  126. "f2": {
  127. "type": "string"
  128. },
  129. "schema": {
  130. "type": "string"
  131. }
  132. }
  133. }
  134. `,
  135. },
  136. value: {
  137. name: 'value',
  138. source: MessageSchemaSourceEnum.SCHEMA_REGISTRY,
  139. schema: `{
  140. "$schema": "http://json-schema.org/draft-07/schema#",
  141. "$id": "http://example.com/myURI1.schema.json",
  142. "title": "TestRecord",
  143. "type": "object",
  144. "additionalProperties": false,
  145. "properties": {
  146. "f1": {
  147. "type": "integer"
  148. },
  149. "f2": {
  150. "type": "string"
  151. },
  152. "schema": {
  153. "type": "string"
  154. }
  155. }
  156. }
  157. `,
  158. },
  159. };
  160. expect(
  161. actions.fetchTopicMessageSchemaAction.success({
  162. topicName: 'test',
  163. schema: messageSchema,
  164. })
  165. ).toEqual({
  166. type: 'GET_TOPIC_SCHEMA__SUCCESS',
  167. payload: {
  168. topicName: 'test',
  169. schema: messageSchema,
  170. },
  171. });
  172. });
  173. it('creates GET_TOPIC_SCHEMA__FAILURE', () => {
  174. const alert: FailurePayload = {
  175. subject: ['message-chema', 'test'].join('-'),
  176. title: `Message Schema Test`,
  177. };
  178. expect(
  179. actions.fetchTopicMessageSchemaAction.failure({ alert })
  180. ).toEqual({
  181. type: 'GET_TOPIC_SCHEMA__FAILURE',
  182. payload: { alert },
  183. });
  184. });
  185. });
  186. });
  187. });