actions.spec.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import {
  2. clusterSchemasPayload,
  3. schemaVersionsPayload,
  4. } from 'redux/reducers/schemas/__test__/fixtures';
  5. import * as actions from 'redux/actions';
  6. import {
  7. MessageSchemaSourceEnum,
  8. TopicColumnsToSort,
  9. TopicMessageSchema,
  10. } from 'generated-sources';
  11. import { FailurePayload } from 'redux/interfaces';
  12. import {
  13. topicMessagePayload,
  14. topicMessagesMetaPayload,
  15. } from 'redux/reducers/topicMessages/__test__/fixtures';
  16. import { fetchKsqlDbTablesPayload } from 'redux/reducers/ksqlDb/__test__/fixtures';
  17. import { mockTopicsState } from './fixtures';
  18. describe('Actions', () => {
  19. describe('fetchClusterStatsAction', () => {
  20. it('creates a REQUEST action', () => {
  21. expect(actions.fetchClusterStatsAction.request()).toEqual({
  22. type: 'GET_CLUSTER_STATUS__REQUEST',
  23. });
  24. });
  25. it('creates a SUCCESS action', () => {
  26. expect(
  27. actions.fetchClusterStatsAction.success({ brokerCount: 1 })
  28. ).toEqual({
  29. type: 'GET_CLUSTER_STATUS__SUCCESS',
  30. payload: {
  31. brokerCount: 1,
  32. },
  33. });
  34. });
  35. it('creates a FAILURE action', () => {
  36. expect(actions.fetchClusterStatsAction.failure()).toEqual({
  37. type: 'GET_CLUSTER_STATUS__FAILURE',
  38. });
  39. });
  40. });
  41. describe('fetchSchemasByClusterNameAction', () => {
  42. it('creates a REQUEST action', () => {
  43. expect(actions.fetchSchemasByClusterNameAction.request()).toEqual({
  44. type: 'GET_CLUSTER_SCHEMAS__REQUEST',
  45. });
  46. });
  47. it('creates a SUCCESS action', () => {
  48. expect(
  49. actions.fetchSchemasByClusterNameAction.success(clusterSchemasPayload)
  50. ).toEqual({
  51. type: 'GET_CLUSTER_SCHEMAS__SUCCESS',
  52. payload: clusterSchemasPayload,
  53. });
  54. });
  55. it('creates a FAILURE action', () => {
  56. expect(actions.fetchSchemasByClusterNameAction.failure()).toEqual({
  57. type: 'GET_CLUSTER_SCHEMAS__FAILURE',
  58. });
  59. });
  60. });
  61. describe('fetchSchemaVersionsAction', () => {
  62. it('creates a REQUEST action', () => {
  63. expect(actions.fetchSchemaVersionsAction.request()).toEqual({
  64. type: 'GET_SCHEMA_VERSIONS__REQUEST',
  65. });
  66. });
  67. it('creates a SUCCESS action', () => {
  68. expect(
  69. actions.fetchSchemaVersionsAction.success(schemaVersionsPayload)
  70. ).toEqual({
  71. type: 'GET_SCHEMA_VERSIONS__SUCCESS',
  72. payload: schemaVersionsPayload,
  73. });
  74. });
  75. it('creates a FAILURE action', () => {
  76. expect(actions.fetchSchemaVersionsAction.failure()).toEqual({
  77. type: 'GET_SCHEMA_VERSIONS__FAILURE',
  78. });
  79. });
  80. });
  81. describe('createSchemaAction', () => {
  82. it('creates a REQUEST action', () => {
  83. expect(actions.createSchemaAction.request()).toEqual({
  84. type: 'POST_SCHEMA__REQUEST',
  85. });
  86. });
  87. it('creates a SUCCESS action', () => {
  88. expect(
  89. actions.createSchemaAction.success(schemaVersionsPayload[0])
  90. ).toEqual({
  91. type: 'POST_SCHEMA__SUCCESS',
  92. payload: schemaVersionsPayload[0],
  93. });
  94. });
  95. it('creates a FAILURE action', () => {
  96. expect(actions.createSchemaAction.failure({})).toEqual({
  97. type: 'POST_SCHEMA__FAILURE',
  98. payload: {},
  99. });
  100. });
  101. });
  102. describe('dismissAlert', () => {
  103. it('creates a REQUEST action', () => {
  104. const id = 'alert-id1';
  105. expect(actions.dismissAlert(id)).toEqual({
  106. type: 'DISMISS_ALERT',
  107. payload: id,
  108. });
  109. });
  110. });
  111. describe('clearMessagesTopicAction', () => {
  112. it('creates a REQUEST action', () => {
  113. expect(actions.clearMessagesTopicAction.request()).toEqual({
  114. type: 'CLEAR_TOPIC_MESSAGES__REQUEST',
  115. });
  116. });
  117. it('creates a SUCCESS action', () => {
  118. expect(actions.clearMessagesTopicAction.success()).toEqual({
  119. type: 'CLEAR_TOPIC_MESSAGES__SUCCESS',
  120. });
  121. });
  122. it('creates a FAILURE action', () => {
  123. expect(actions.clearMessagesTopicAction.failure({})).toEqual({
  124. type: 'CLEAR_TOPIC_MESSAGES__FAILURE',
  125. payload: {},
  126. });
  127. });
  128. });
  129. describe('fetchTopicConsumerGroups', () => {
  130. it('creates a REQUEST action', () => {
  131. expect(actions.fetchTopicConsumerGroupsAction.request()).toEqual({
  132. type: 'GET_TOPIC_CONSUMER_GROUPS__REQUEST',
  133. });
  134. });
  135. it('creates a SUCCESS action', () => {
  136. expect(
  137. actions.fetchTopicConsumerGroupsAction.success(mockTopicsState)
  138. ).toEqual({
  139. type: 'GET_TOPIC_CONSUMER_GROUPS__SUCCESS',
  140. payload: mockTopicsState,
  141. });
  142. });
  143. it('creates a FAILURE action', () => {
  144. expect(actions.fetchTopicConsumerGroupsAction.failure()).toEqual({
  145. type: 'GET_TOPIC_CONSUMER_GROUPS__FAILURE',
  146. });
  147. });
  148. });
  149. describe('setTopicsSearchAction', () => {
  150. it('creartes SET_TOPICS_SEARCH', () => {
  151. expect(actions.setTopicsSearchAction('test')).toEqual({
  152. type: 'SET_TOPICS_SEARCH',
  153. payload: 'test',
  154. });
  155. });
  156. });
  157. describe('setTopicsOrderByAction', () => {
  158. it('creartes SET_TOPICS_ORDER_BY', () => {
  159. expect(actions.setTopicsOrderByAction(TopicColumnsToSort.NAME)).toEqual({
  160. type: 'SET_TOPICS_ORDER_BY',
  161. payload: TopicColumnsToSort.NAME,
  162. });
  163. });
  164. });
  165. describe('deleting consumer group', () => {
  166. it('creates DELETE_CONSUMER_GROUP__REQUEST', () => {
  167. expect(actions.deleteConsumerGroupAction.request()).toEqual({
  168. type: 'DELETE_CONSUMER_GROUP__REQUEST',
  169. });
  170. });
  171. it('creates DELETE_CONSUMER_GROUP__SUCCESS', () => {
  172. expect(actions.deleteConsumerGroupAction.success('test')).toEqual({
  173. type: 'DELETE_CONSUMER_GROUP__SUCCESS',
  174. payload: 'test',
  175. });
  176. });
  177. it('creates DELETE_CONSUMER_GROUP__FAILURE', () => {
  178. const alert: FailurePayload = {
  179. subject: ['consumer-group', 'test'].join('-'),
  180. title: `Consumer Gropup Test`,
  181. };
  182. expect(actions.deleteConsumerGroupAction.failure({ alert })).toEqual({
  183. type: 'DELETE_CONSUMER_GROUP__FAILURE',
  184. payload: { alert },
  185. });
  186. });
  187. });
  188. describe('topic messages', () => {
  189. it('creates ADD_TOPIC_MESSAGE', () => {
  190. expect(actions.addTopicMessage(topicMessagePayload)).toEqual({
  191. type: 'ADD_TOPIC_MESSAGE',
  192. payload: topicMessagePayload,
  193. });
  194. });
  195. it('creates RESET_TOPIC_MESSAGES', () => {
  196. expect(actions.resetTopicMessages()).toEqual({
  197. type: 'RESET_TOPIC_MESSAGES',
  198. });
  199. });
  200. it('creates UPDATE_TOPIC_MESSAGES_PHASE', () => {
  201. expect(actions.updateTopicMessagesPhase('Polling')).toEqual({
  202. type: 'UPDATE_TOPIC_MESSAGES_PHASE',
  203. payload: 'Polling',
  204. });
  205. });
  206. it('creates UPDATE_TOPIC_MESSAGES_META', () => {
  207. expect(actions.updateTopicMessagesMeta(topicMessagesMetaPayload)).toEqual(
  208. {
  209. type: 'UPDATE_TOPIC_MESSAGES_META',
  210. payload: topicMessagesMetaPayload,
  211. }
  212. );
  213. });
  214. });
  215. describe('sending messages', () => {
  216. describe('fetchTopicMessageSchemaAction', () => {
  217. it('creates GET_TOPIC_SCHEMA__REQUEST', () => {
  218. expect(actions.fetchTopicMessageSchemaAction.request()).toEqual({
  219. type: 'GET_TOPIC_SCHEMA__REQUEST',
  220. });
  221. });
  222. it('creates GET_TOPIC_SCHEMA__SUCCESS', () => {
  223. const messageSchema: TopicMessageSchema = {
  224. key: {
  225. name: 'key',
  226. source: MessageSchemaSourceEnum.SCHEMA_REGISTRY,
  227. schema: `{
  228. "$schema": "http://json-schema.org/draft-07/schema#",
  229. "$id": "http://example.com/myURI.schema.json",
  230. "title": "TestRecord",
  231. "type": "object",
  232. "additionalProperties": false,
  233. "properties": {
  234. "f1": {
  235. "type": "integer"
  236. },
  237. "f2": {
  238. "type": "string"
  239. },
  240. "schema": {
  241. "type": "string"
  242. }
  243. }
  244. }
  245. `,
  246. },
  247. value: {
  248. name: 'value',
  249. source: MessageSchemaSourceEnum.SCHEMA_REGISTRY,
  250. schema: `{
  251. "$schema": "http://json-schema.org/draft-07/schema#",
  252. "$id": "http://example.com/myURI1.schema.json",
  253. "title": "TestRecord",
  254. "type": "object",
  255. "additionalProperties": false,
  256. "properties": {
  257. "f1": {
  258. "type": "integer"
  259. },
  260. "f2": {
  261. "type": "string"
  262. },
  263. "schema": {
  264. "type": "string"
  265. }
  266. }
  267. }
  268. `,
  269. },
  270. };
  271. expect(
  272. actions.fetchTopicMessageSchemaAction.success({
  273. topicName: 'test',
  274. schema: messageSchema,
  275. })
  276. ).toEqual({
  277. type: 'GET_TOPIC_SCHEMA__SUCCESS',
  278. payload: {
  279. topicName: 'test',
  280. schema: messageSchema,
  281. },
  282. });
  283. });
  284. it('creates GET_TOPIC_SCHEMA__FAILURE', () => {
  285. const alert: FailurePayload = {
  286. subject: ['message-chema', 'test'].join('-'),
  287. title: `Message Schema Test`,
  288. };
  289. expect(
  290. actions.fetchTopicMessageSchemaAction.failure({ alert })
  291. ).toEqual({
  292. type: 'GET_TOPIC_SCHEMA__FAILURE',
  293. payload: { alert },
  294. });
  295. });
  296. });
  297. });
  298. });
  299. describe('ksqlDb', () => {
  300. it('creates GET_KSQL_DB_TABLES_AND_STREAMS__REQUEST', () => {
  301. expect(actions.fetchKsqlDbTablesAction.request()).toEqual({
  302. type: 'GET_KSQL_DB_TABLES_AND_STREAMS__REQUEST',
  303. });
  304. });
  305. it('creates GET_KSQL_DB_TABLES_AND_STREAMS__SUCCESS', () => {
  306. expect(
  307. actions.fetchKsqlDbTablesAction.success(fetchKsqlDbTablesPayload)
  308. ).toEqual({
  309. type: 'GET_KSQL_DB_TABLES_AND_STREAMS__SUCCESS',
  310. payload: fetchKsqlDbTablesPayload,
  311. });
  312. });
  313. it('creates GET_KSQL_DB_TABLES_AND_STREAMS__FAILURE', () => {
  314. expect(actions.fetchKsqlDbTablesAction.failure({})).toEqual({
  315. type: 'GET_KSQL_DB_TABLES_AND_STREAMS__FAILURE',
  316. payload: {},
  317. });
  318. });
  319. });