connectors.spec.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. import fetchMock from 'fetch-mock-jest';
  2. import { ConnectorAction } from 'generated-sources';
  3. import * as actions from 'redux/actions/actions';
  4. import * as thunks from 'redux/actions/thunks';
  5. import {
  6. connects,
  7. connectorsServerPayload,
  8. connectors,
  9. connectorServerPayload,
  10. connector,
  11. tasksServerPayload,
  12. tasks,
  13. } from 'redux/reducers/connect/__test__/fixtures';
  14. import mockStoreCreator from 'redux/store/configureStore/mockStoreCreator';
  15. const store = mockStoreCreator;
  16. const clusterName = 'local';
  17. const connectName = 'first';
  18. const connectorName = 'hdfs-source-connector';
  19. const taskId = 10;
  20. describe('Thunks', () => {
  21. afterEach(() => {
  22. fetchMock.restore();
  23. store.clearActions();
  24. });
  25. describe('fetchConnects', () => {
  26. it('creates GET_CONNECTS__SUCCESS when fetching connects', async () => {
  27. fetchMock.getOnce(`/api/clusters/${clusterName}/connects`, connects);
  28. await store.dispatch(thunks.fetchConnects(clusterName));
  29. expect(store.getActions()).toEqual([
  30. actions.fetchConnectsAction.request(),
  31. actions.fetchConnectsAction.success({ connects }),
  32. ]);
  33. });
  34. it('creates GET_CONNECTS__FAILURE', async () => {
  35. fetchMock.getOnce(`/api/clusters/${clusterName}/connects`, 404);
  36. await store.dispatch(thunks.fetchConnects(clusterName));
  37. expect(store.getActions()).toEqual([
  38. actions.fetchConnectsAction.request(),
  39. actions.fetchConnectsAction.failure({
  40. alert: {
  41. subject: 'connects',
  42. title: 'Kafka Connect',
  43. response: {
  44. status: 404,
  45. statusText: 'Not Found',
  46. body: undefined,
  47. },
  48. },
  49. }),
  50. ]);
  51. });
  52. });
  53. describe('fetchConnectors', () => {
  54. it('creates GET_CONNECTORS__SUCCESS when fetching connectors', async () => {
  55. fetchMock.getOnce(
  56. `/api/clusters/${clusterName}/connectors`,
  57. connectorsServerPayload
  58. );
  59. await store.dispatch(thunks.fetchConnectors(clusterName));
  60. expect(store.getActions()).toEqual([
  61. actions.fetchConnectorsAction.request(),
  62. actions.fetchConnectorsAction.success({ connectors }),
  63. ]);
  64. });
  65. it('creates GET_CONNECTORS__SUCCESS when fetching connectors in silent mode', async () => {
  66. fetchMock.getOnce(
  67. `/api/clusters/${clusterName}/connectors`,
  68. connectorsServerPayload
  69. );
  70. await store.dispatch(thunks.fetchConnectors(clusterName, true));
  71. expect(store.getActions()).toEqual([
  72. actions.fetchConnectorsAction.success({
  73. ...store.getState().connect,
  74. connectors,
  75. }),
  76. ]);
  77. });
  78. it('creates GET_CONNECTORS__FAILURE', async () => {
  79. fetchMock.getOnce(`/api/clusters/${clusterName}/connectors`, 404);
  80. await store.dispatch(thunks.fetchConnectors(clusterName));
  81. expect(store.getActions()).toEqual([
  82. actions.fetchConnectorsAction.request(),
  83. actions.fetchConnectorsAction.failure({
  84. alert: {
  85. subject: 'local-connectors',
  86. title: 'Kafka Connect Connectors',
  87. response: {
  88. status: 404,
  89. statusText: 'Not Found',
  90. body: undefined,
  91. },
  92. },
  93. }),
  94. ]);
  95. });
  96. });
  97. describe('fetchConnector', () => {
  98. it('creates GET_CONNECTOR__SUCCESS when fetching connects', async () => {
  99. fetchMock.getOnce(
  100. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
  101. connectorServerPayload
  102. );
  103. await store.dispatch(
  104. thunks.fetchConnector(clusterName, connectName, connectorName)
  105. );
  106. expect(store.getActions()).toEqual([
  107. actions.fetchConnectorAction.request(),
  108. actions.fetchConnectorAction.success({ connector }),
  109. ]);
  110. });
  111. it('creates GET_CONNECTOR__FAILURE', async () => {
  112. fetchMock.getOnce(
  113. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
  114. 404
  115. );
  116. await store.dispatch(
  117. thunks.fetchConnector(clusterName, connectName, connectorName)
  118. );
  119. expect(store.getActions()).toEqual([
  120. actions.fetchConnectorAction.request(),
  121. actions.fetchConnectorAction.failure({
  122. alert: {
  123. subject: 'local-first-hdfs-source-connector',
  124. title: 'Kafka Connect Connector',
  125. response: {
  126. status: 404,
  127. statusText: 'Not Found',
  128. body: undefined,
  129. },
  130. },
  131. }),
  132. ]);
  133. });
  134. });
  135. describe('createConnector', () => {
  136. it('creates POST_CONNECTOR__SUCCESS when fetching connects', async () => {
  137. fetchMock.postOnce(
  138. {
  139. url: `/api/clusters/${clusterName}/connects/${connectName}/connectors`,
  140. body: {
  141. name: connectorName,
  142. config: connector.config,
  143. },
  144. },
  145. connectorServerPayload
  146. );
  147. await store.dispatch(
  148. thunks.createConnector(clusterName, connectName, {
  149. name: connectorName,
  150. config: connector.config,
  151. })
  152. );
  153. expect(store.getActions()).toEqual([
  154. actions.createConnectorAction.request(),
  155. actions.createConnectorAction.success({ connector }),
  156. ]);
  157. });
  158. it('creates POST_CONNECTOR__FAILURE', async () => {
  159. fetchMock.postOnce(
  160. {
  161. url: `/api/clusters/${clusterName}/connects/${connectName}/connectors`,
  162. body: {
  163. name: connectorName,
  164. config: connector.config,
  165. },
  166. },
  167. 404
  168. );
  169. await store.dispatch(
  170. thunks.createConnector(clusterName, connectName, {
  171. name: connectorName,
  172. config: connector.config,
  173. })
  174. );
  175. expect(store.getActions()).toEqual([
  176. actions.createConnectorAction.request(),
  177. actions.createConnectorAction.failure({
  178. alert: {
  179. subject: 'local-first',
  180. title: 'Kafka Connect Connector Create',
  181. response: {
  182. status: 404,
  183. statusText: 'Not Found',
  184. body: undefined,
  185. },
  186. },
  187. }),
  188. ]);
  189. });
  190. });
  191. describe('deleteConnector', () => {
  192. it('creates DELETE_CONNECTOR__SUCCESS', async () => {
  193. fetchMock.deleteOnce(
  194. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
  195. {}
  196. );
  197. fetchMock.getOnce(
  198. `/api/clusters/${clusterName}/connectors`,
  199. connectorsServerPayload
  200. );
  201. await store.dispatch(
  202. thunks.deleteConnector(clusterName, connectName, connectorName)
  203. );
  204. expect(store.getActions()).toEqual([
  205. actions.deleteConnectorAction.request(),
  206. actions.deleteConnectorAction.success({ connectorName }),
  207. ]);
  208. });
  209. it('creates DELETE_CONNECTOR__FAILURE', async () => {
  210. fetchMock.deleteOnce(
  211. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
  212. 404
  213. );
  214. try {
  215. await store.dispatch(
  216. thunks.deleteConnector(clusterName, connectName, connectorName)
  217. );
  218. } catch {
  219. expect(store.getActions()).toEqual([
  220. actions.deleteConnectorAction.request(),
  221. actions.deleteConnectorAction.failure({
  222. alert: {
  223. subject: 'local-first-hdfs-source-connector',
  224. title: 'Kafka Connect Connector Delete',
  225. response: {
  226. status: 404,
  227. statusText: 'Not Found',
  228. body: undefined,
  229. },
  230. },
  231. }),
  232. ]);
  233. }
  234. });
  235. });
  236. describe('fetchConnectorTasks', () => {
  237. it('creates GET_CONNECTOR_TASKS__SUCCESS when fetching connects', async () => {
  238. fetchMock.getOnce(
  239. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
  240. tasksServerPayload
  241. );
  242. await store.dispatch(
  243. thunks.fetchConnectorTasks(clusterName, connectName, connectorName)
  244. );
  245. expect(store.getActions()).toEqual([
  246. actions.fetchConnectorTasksAction.request(),
  247. actions.fetchConnectorTasksAction.success({ tasks }),
  248. ]);
  249. });
  250. it('creates GET_CONNECTOR_TASKS__FAILURE', async () => {
  251. fetchMock.getOnce(
  252. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
  253. 404
  254. );
  255. await store.dispatch(
  256. thunks.fetchConnectorTasks(clusterName, connectName, connectorName)
  257. );
  258. expect(store.getActions()).toEqual([
  259. actions.fetchConnectorTasksAction.request(),
  260. actions.fetchConnectorTasksAction.failure({
  261. alert: {
  262. subject: 'local-first-hdfs-source-connector',
  263. title: 'Kafka Connect Connector Tasks',
  264. response: {
  265. status: 404,
  266. statusText: 'Not Found',
  267. body: undefined,
  268. },
  269. },
  270. }),
  271. ]);
  272. });
  273. });
  274. describe('restartConnector', () => {
  275. it('creates RESTART_CONNECTOR__SUCCESS when fetching connects', async () => {
  276. fetchMock.postOnce(
  277. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESTART}`,
  278. { message: 'success' }
  279. );
  280. fetchMock.getOnce(
  281. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
  282. tasksServerPayload
  283. );
  284. await store.dispatch(
  285. thunks.restartConnector(clusterName, connectName, connectorName)
  286. );
  287. expect(store.getActions()).toEqual([
  288. actions.restartConnectorAction.request(),
  289. actions.restartConnectorAction.success(),
  290. ]);
  291. });
  292. it('creates RESTART_CONNECTOR__FAILURE', async () => {
  293. fetchMock.postOnce(
  294. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESTART}`,
  295. 404
  296. );
  297. await store.dispatch(
  298. thunks.restartConnector(clusterName, connectName, connectorName)
  299. );
  300. expect(store.getActions()).toEqual([
  301. actions.restartConnectorAction.request(),
  302. actions.restartConnectorAction.failure({
  303. alert: {
  304. subject: 'local-first-hdfs-source-connector',
  305. title: 'Kafka Connect Connector Tasks Restart',
  306. response: {
  307. status: 404,
  308. statusText: 'Not Found',
  309. body: undefined,
  310. },
  311. },
  312. }),
  313. ]);
  314. });
  315. });
  316. describe('pauseConnector', () => {
  317. it('creates PAUSE_CONNECTOR__SUCCESS when fetching connects', async () => {
  318. fetchMock.postOnce(
  319. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.PAUSE}`,
  320. { message: 'success' }
  321. );
  322. await store.dispatch(
  323. thunks.pauseConnector(clusterName, connectName, connectorName)
  324. );
  325. expect(store.getActions()).toEqual([
  326. actions.pauseConnectorAction.request(),
  327. actions.pauseConnectorAction.success({ connectorName }),
  328. ]);
  329. });
  330. it('creates PAUSE_CONNECTOR__FAILURE', async () => {
  331. fetchMock.postOnce(
  332. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.PAUSE}`,
  333. 404
  334. );
  335. await store.dispatch(
  336. thunks.pauseConnector(clusterName, connectName, connectorName)
  337. );
  338. expect(store.getActions()).toEqual([
  339. actions.pauseConnectorAction.request(),
  340. actions.pauseConnectorAction.failure({
  341. alert: {
  342. subject: 'local-first-hdfs-source-connector',
  343. title: 'Kafka Connect Connector Pause',
  344. response: {
  345. status: 404,
  346. statusText: 'Not Found',
  347. body: undefined,
  348. },
  349. },
  350. }),
  351. ]);
  352. });
  353. });
  354. describe('resumeConnector', () => {
  355. it('creates RESUME_CONNECTOR__SUCCESS when fetching connects', async () => {
  356. fetchMock.postOnce(
  357. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESUME}`,
  358. { message: 'success' }
  359. );
  360. await store.dispatch(
  361. thunks.resumeConnector(clusterName, connectName, connectorName)
  362. );
  363. expect(store.getActions()).toEqual([
  364. actions.resumeConnectorAction.request(),
  365. actions.resumeConnectorAction.success({ connectorName }),
  366. ]);
  367. });
  368. it('creates RESUME_CONNECTOR__FAILURE', async () => {
  369. fetchMock.postOnce(
  370. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESUME}`,
  371. 404
  372. );
  373. await store.dispatch(
  374. thunks.resumeConnector(clusterName, connectName, connectorName)
  375. );
  376. expect(store.getActions()).toEqual([
  377. actions.resumeConnectorAction.request(),
  378. actions.resumeConnectorAction.failure({
  379. alert: {
  380. subject: 'local-first-hdfs-source-connector',
  381. title: 'Kafka Connect Connector Resume',
  382. response: {
  383. status: 404,
  384. statusText: 'Not Found',
  385. body: undefined,
  386. },
  387. },
  388. }),
  389. ]);
  390. });
  391. });
  392. describe('restartConnectorTask', () => {
  393. it('creates RESTART_CONNECTOR_TASK__SUCCESS when fetching connects', async () => {
  394. fetchMock.postOnce(
  395. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks/${taskId}/action/restart`,
  396. { message: 'success' }
  397. );
  398. fetchMock.getOnce(
  399. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
  400. tasksServerPayload
  401. );
  402. await store.dispatch(
  403. thunks.restartConnectorTask(
  404. clusterName,
  405. connectName,
  406. connectorName,
  407. taskId
  408. )
  409. );
  410. expect(store.getActions()).toEqual([
  411. actions.restartConnectorTaskAction.request(),
  412. actions.restartConnectorTaskAction.success(),
  413. ]);
  414. });
  415. it('creates RESTART_CONNECTOR_TASK__FAILURE', async () => {
  416. fetchMock.postOnce(
  417. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks/${taskId}/action/restart`,
  418. 404
  419. );
  420. await store.dispatch(
  421. thunks.restartConnectorTask(
  422. clusterName,
  423. connectName,
  424. connectorName,
  425. taskId
  426. )
  427. );
  428. expect(store.getActions()).toEqual([
  429. actions.restartConnectorTaskAction.request(),
  430. actions.restartConnectorTaskAction.failure({
  431. alert: {
  432. subject: 'local-first-hdfs-source-connector-10',
  433. title: 'Kafka Connect Connector Task Restart',
  434. response: {
  435. status: 404,
  436. statusText: 'Not Found',
  437. body: undefined,
  438. },
  439. },
  440. }),
  441. ]);
  442. });
  443. });
  444. describe('fetchConnectorConfig', () => {
  445. it('creates GET_CONNECTOR_CONFIG__SUCCESS when fetching connects', async () => {
  446. fetchMock.getOnce(
  447. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
  448. connector.config
  449. );
  450. await store.dispatch(
  451. thunks.fetchConnectorConfig(clusterName, connectName, connectorName)
  452. );
  453. expect(store.getActions()).toEqual([
  454. actions.fetchConnectorConfigAction.request(),
  455. actions.fetchConnectorConfigAction.success({
  456. config: connector.config,
  457. }),
  458. ]);
  459. });
  460. it('creates GET_CONNECTOR_CONFIG__FAILURE', async () => {
  461. fetchMock.getOnce(
  462. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
  463. 404
  464. );
  465. await store.dispatch(
  466. thunks.fetchConnectorConfig(clusterName, connectName, connectorName)
  467. );
  468. expect(store.getActions()).toEqual([
  469. actions.fetchConnectorConfigAction.request(),
  470. actions.fetchConnectorConfigAction.failure({
  471. alert: {
  472. subject: 'local-first-hdfs-source-connector',
  473. title: 'Kafka Connect Connector Config',
  474. response: {
  475. status: 404,
  476. statusText: 'Not Found',
  477. body: undefined,
  478. },
  479. },
  480. }),
  481. ]);
  482. });
  483. });
  484. describe('updateConnectorConfig', () => {
  485. it('creates PATCH_CONNECTOR_CONFIG__SUCCESS when fetching connects', async () => {
  486. fetchMock.putOnce(
  487. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
  488. connectorServerPayload
  489. );
  490. await store.dispatch(
  491. thunks.updateConnectorConfig(
  492. clusterName,
  493. connectName,
  494. connectorName,
  495. connector.config
  496. )
  497. );
  498. expect(store.getActions()).toEqual([
  499. actions.updateConnectorConfigAction.request(),
  500. actions.updateConnectorConfigAction.success({ connector }),
  501. ]);
  502. });
  503. it('creates PATCH_CONNECTOR_CONFIG__FAILURE', async () => {
  504. fetchMock.putOnce(
  505. `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
  506. 404
  507. );
  508. await store.dispatch(
  509. thunks.updateConnectorConfig(
  510. clusterName,
  511. connectName,
  512. connectorName,
  513. connector.config
  514. )
  515. );
  516. expect(store.getActions()).toEqual([
  517. actions.updateConnectorConfigAction.request(),
  518. actions.updateConnectorConfigAction.failure({
  519. alert: {
  520. subject: 'local-first-hdfs-source-connector',
  521. title: 'Kafka Connect Connector Config Update',
  522. response: {
  523. status: 404,
  524. statusText: 'Not Found',
  525. body: undefined,
  526. },
  527. },
  528. }),
  529. ]);
  530. });
  531. });
  532. });