123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- import fetchMock from 'fetch-mock-jest';
- import { ConnectorAction } from 'generated-sources';
- import * as actions from 'redux/actions/actions';
- import * as thunks from 'redux/actions/thunks';
- import {
- connects,
- connectorsServerPayload,
- connectors,
- connectorServerPayload,
- connector,
- tasksServerPayload,
- tasks,
- } from 'redux/reducers/connect/__test__/fixtures';
- import mockStoreCreator from 'redux/store/configureStore/mockStoreCreator';
- const store = mockStoreCreator;
- const clusterName = 'local';
- const connectName = 'first';
- const connectorName = 'hdfs-source-connector';
- const taskId = 10;
- describe('Thunks', () => {
- afterEach(() => {
- fetchMock.restore();
- store.clearActions();
- });
- describe('fetchConnects', () => {
- it('creates GET_CONNECTS__SUCCESS when fetching connects', async () => {
- fetchMock.getOnce(`/api/clusters/${clusterName}/connects`, connects);
- await store.dispatch(thunks.fetchConnects(clusterName));
- expect(store.getActions()).toEqual([
- actions.fetchConnectsAction.request(),
- actions.fetchConnectsAction.success({ connects }),
- ]);
- });
- it('creates GET_CONNECTS__FAILURE', async () => {
- fetchMock.getOnce(`/api/clusters/${clusterName}/connects`, 404);
- await store.dispatch(thunks.fetchConnects(clusterName));
- expect(store.getActions()).toEqual([
- actions.fetchConnectsAction.request(),
- actions.fetchConnectsAction.failure({
- alert: {
- subject: 'connects',
- title: 'Kafka Connect',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('fetchConnectors', () => {
- it('creates GET_CONNECTORS__SUCCESS when fetching connectors', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connectors`,
- connectorsServerPayload
- );
- await store.dispatch(thunks.fetchConnectors(clusterName));
- expect(store.getActions()).toEqual([
- actions.fetchConnectorsAction.request(),
- actions.fetchConnectorsAction.success({ connectors }),
- ]);
- });
- it('creates GET_CONNECTORS__SUCCESS when fetching connectors in silent mode', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connectors`,
- connectorsServerPayload
- );
- await store.dispatch(thunks.fetchConnectors(clusterName, true));
- expect(store.getActions()).toEqual([
- actions.fetchConnectorsAction.success({
- ...store.getState().connect,
- connectors,
- }),
- ]);
- });
- it('creates GET_CONNECTORS__FAILURE', async () => {
- fetchMock.getOnce(`/api/clusters/${clusterName}/connectors`, 404);
- await store.dispatch(thunks.fetchConnectors(clusterName));
- expect(store.getActions()).toEqual([
- actions.fetchConnectorsAction.request(),
- actions.fetchConnectorsAction.failure({
- alert: {
- subject: 'local-connectors',
- title: 'Kafka Connect Connectors',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('fetchConnector', () => {
- it('creates GET_CONNECTOR__SUCCESS when fetching connects', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
- connectorServerPayload
- );
- await store.dispatch(
- thunks.fetchConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.fetchConnectorAction.request(),
- actions.fetchConnectorAction.success({ connector }),
- ]);
- });
- it('creates GET_CONNECTOR__FAILURE', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
- 404
- );
- await store.dispatch(
- thunks.fetchConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.fetchConnectorAction.request(),
- actions.fetchConnectorAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('createConnector', () => {
- it('creates POST_CONNECTOR__SUCCESS when fetching connects', async () => {
- fetchMock.postOnce(
- {
- url: `/api/clusters/${clusterName}/connects/${connectName}/connectors`,
- body: {
- name: connectorName,
- config: connector.config,
- },
- },
- connectorServerPayload
- );
- await store.dispatch(
- thunks.createConnector(clusterName, connectName, {
- name: connectorName,
- config: connector.config,
- })
- );
- expect(store.getActions()).toEqual([
- actions.createConnectorAction.request(),
- actions.createConnectorAction.success({ connector }),
- ]);
- });
- it('creates POST_CONNECTOR__FAILURE', async () => {
- fetchMock.postOnce(
- {
- url: `/api/clusters/${clusterName}/connects/${connectName}/connectors`,
- body: {
- name: connectorName,
- config: connector.config,
- },
- },
- 404
- );
- await store.dispatch(
- thunks.createConnector(clusterName, connectName, {
- name: connectorName,
- config: connector.config,
- })
- );
- expect(store.getActions()).toEqual([
- actions.createConnectorAction.request(),
- actions.createConnectorAction.failure({
- alert: {
- subject: 'local-first',
- title: 'Kafka Connect Connector Create',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('deleteConnector', () => {
- it('creates DELETE_CONNECTOR__SUCCESS', async () => {
- fetchMock.deleteOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
- {}
- );
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connectors`,
- connectorsServerPayload
- );
- await store.dispatch(
- thunks.deleteConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.deleteConnectorAction.request(),
- actions.deleteConnectorAction.success({ connectorName }),
- ]);
- });
- it('creates DELETE_CONNECTOR__FAILURE', async () => {
- fetchMock.deleteOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}`,
- 404
- );
- try {
- await store.dispatch(
- thunks.deleteConnector(clusterName, connectName, connectorName)
- );
- } catch {
- expect(store.getActions()).toEqual([
- actions.deleteConnectorAction.request(),
- actions.deleteConnectorAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Delete',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- }
- });
- });
- describe('fetchConnectorTasks', () => {
- it('creates GET_CONNECTOR_TASKS__SUCCESS when fetching connects', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
- tasksServerPayload
- );
- await store.dispatch(
- thunks.fetchConnectorTasks(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.fetchConnectorTasksAction.request(),
- actions.fetchConnectorTasksAction.success({ tasks }),
- ]);
- });
- it('creates GET_CONNECTOR_TASKS__FAILURE', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
- 404
- );
- await store.dispatch(
- thunks.fetchConnectorTasks(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.fetchConnectorTasksAction.request(),
- actions.fetchConnectorTasksAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Tasks',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('restartConnector', () => {
- it('creates RESTART_CONNECTOR__SUCCESS when fetching connects', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESTART}`,
- { message: 'success' }
- );
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
- tasksServerPayload
- );
- await store.dispatch(
- thunks.restartConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.restartConnectorAction.request(),
- actions.restartConnectorAction.success(),
- ]);
- });
- it('creates RESTART_CONNECTOR__FAILURE', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESTART}`,
- 404
- );
- await store.dispatch(
- thunks.restartConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.restartConnectorAction.request(),
- actions.restartConnectorAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Tasks Restart',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('pauseConnector', () => {
- it('creates PAUSE_CONNECTOR__SUCCESS when fetching connects', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.PAUSE}`,
- { message: 'success' }
- );
- await store.dispatch(
- thunks.pauseConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.pauseConnectorAction.request(),
- actions.pauseConnectorAction.success({ connectorName }),
- ]);
- });
- it('creates PAUSE_CONNECTOR__FAILURE', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.PAUSE}`,
- 404
- );
- await store.dispatch(
- thunks.pauseConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.pauseConnectorAction.request(),
- actions.pauseConnectorAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Pause',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('resumeConnector', () => {
- it('creates RESUME_CONNECTOR__SUCCESS when fetching connects', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESUME}`,
- { message: 'success' }
- );
- await store.dispatch(
- thunks.resumeConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.resumeConnectorAction.request(),
- actions.resumeConnectorAction.success({ connectorName }),
- ]);
- });
- it('creates RESUME_CONNECTOR__FAILURE', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/action/${ConnectorAction.RESUME}`,
- 404
- );
- await store.dispatch(
- thunks.resumeConnector(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.resumeConnectorAction.request(),
- actions.resumeConnectorAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Resume',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('restartConnectorTask', () => {
- it('creates RESTART_CONNECTOR_TASK__SUCCESS when fetching connects', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks/${taskId}/action/restart`,
- { message: 'success' }
- );
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks`,
- tasksServerPayload
- );
- await store.dispatch(
- thunks.restartConnectorTask(
- clusterName,
- connectName,
- connectorName,
- taskId
- )
- );
- expect(store.getActions()).toEqual([
- actions.restartConnectorTaskAction.request(),
- actions.restartConnectorTaskAction.success(),
- ]);
- });
- it('creates RESTART_CONNECTOR_TASK__FAILURE', async () => {
- fetchMock.postOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/tasks/${taskId}/action/restart`,
- 404
- );
- await store.dispatch(
- thunks.restartConnectorTask(
- clusterName,
- connectName,
- connectorName,
- taskId
- )
- );
- expect(store.getActions()).toEqual([
- actions.restartConnectorTaskAction.request(),
- actions.restartConnectorTaskAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector-10',
- title: 'Kafka Connect Connector Task Restart',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('fetchConnectorConfig', () => {
- it('creates GET_CONNECTOR_CONFIG__SUCCESS when fetching connects', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
- connector.config
- );
- await store.dispatch(
- thunks.fetchConnectorConfig(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.fetchConnectorConfigAction.request(),
- actions.fetchConnectorConfigAction.success({
- config: connector.config,
- }),
- ]);
- });
- it('creates GET_CONNECTOR_CONFIG__FAILURE', async () => {
- fetchMock.getOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
- 404
- );
- await store.dispatch(
- thunks.fetchConnectorConfig(clusterName, connectName, connectorName)
- );
- expect(store.getActions()).toEqual([
- actions.fetchConnectorConfigAction.request(),
- actions.fetchConnectorConfigAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Config',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- describe('updateConnectorConfig', () => {
- it('creates PATCH_CONNECTOR_CONFIG__SUCCESS when fetching connects', async () => {
- fetchMock.putOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
- connectorServerPayload
- );
- await store.dispatch(
- thunks.updateConnectorConfig(
- clusterName,
- connectName,
- connectorName,
- connector.config
- )
- );
- expect(store.getActions()).toEqual([
- actions.updateConnectorConfigAction.request(),
- actions.updateConnectorConfigAction.success({ connector }),
- ]);
- });
- it('creates PATCH_CONNECTOR_CONFIG__FAILURE', async () => {
- fetchMock.putOnce(
- `/api/clusters/${clusterName}/connects/${connectName}/connectors/${connectorName}/config`,
- 404
- );
- await store.dispatch(
- thunks.updateConnectorConfig(
- clusterName,
- connectName,
- connectorName,
- connector.config
- )
- );
- expect(store.getActions()).toEqual([
- actions.updateConnectorConfigAction.request(),
- actions.updateConnectorConfigAction.failure({
- alert: {
- subject: 'local-first-hdfs-source-connector',
- title: 'Kafka Connect Connector Config Update',
- response: {
- status: 404,
- statusText: 'Not Found',
- body: undefined,
- },
- },
- }),
- ]);
- });
- });
- });
|