ksqlDb.spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import fetchMock from 'fetch-mock-jest';
  2. import mockStoreCreator from 'redux/store/configureStore/mockStoreCreator';
  3. import * as thunks from 'redux/actions/thunks';
  4. import * as actions from 'redux/actions';
  5. import { ksqlCommandResponse } from 'redux/reducers/ksqlDb/__test__/fixtures';
  6. import { transformKsqlResponse } from 'redux/actions/thunks';
  7. const store = mockStoreCreator;
  8. const clusterName = 'local';
  9. describe('Thunks', () => {
  10. afterEach(() => {
  11. fetchMock.restore();
  12. store.clearActions();
  13. });
  14. describe('fetchKsqlDbTables', () => {
  15. it('creates GET_KSQL_DB_TABLES_AND_STREAMS__SUCCESS when fetching streams', async () => {
  16. fetchMock.post(`/api/clusters/${clusterName}/ksql`, ksqlCommandResponse);
  17. await store.dispatch(thunks.fetchKsqlDbTables(clusterName));
  18. expect(store.getActions()).toEqual([
  19. actions.fetchKsqlDbTablesAction.request(),
  20. actions.fetchKsqlDbTablesAction.success({
  21. streams: transformKsqlResponse(ksqlCommandResponse.data),
  22. tables: transformKsqlResponse(ksqlCommandResponse.data),
  23. }),
  24. ]);
  25. });
  26. it('creates GET_KSQL_DB_TABLES_AND_STREAMS__FAILURE', async () => {
  27. fetchMock.post(`/api/clusters/${clusterName}/ksql`, 422);
  28. await store.dispatch(thunks.fetchKsqlDbTables(clusterName));
  29. expect(store.getActions()).toEqual([
  30. actions.fetchKsqlDbTablesAction.request(),
  31. actions.fetchKsqlDbTablesAction.failure({
  32. alert: {
  33. subject: 'ksqlDb',
  34. title: 'Failed to fetch tables and streams',
  35. response: {
  36. status: 422,
  37. statusText: 'Unprocessable Entity',
  38. url: `/api/clusters/${clusterName}/ksql`,
  39. },
  40. },
  41. }),
  42. ]);
  43. });
  44. });
  45. });