2022-04-22 08:33:13 -05:00
|
|
|
|
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
|
|
|
|
import { ApiKeysState } from '../../../types';
|
|
|
|
|
import { getMultipleMockKeys } from '../__mocks__/apiKeysMock';
|
|
|
|
|
|
|
|
|
|
import {
|
2021-12-16 05:46:09 -06:00
|
|
|
|
apiKeysLoaded,
|
|
|
|
|
apiKeysReducer,
|
|
|
|
|
includeExpiredToggled,
|
|
|
|
|
initialApiKeysState,
|
|
|
|
|
isFetching,
|
|
|
|
|
setSearchQuery,
|
|
|
|
|
} from './reducers';
|
2018-09-27 02:31:05 -05:00
|
|
|
|
|
|
|
|
|
describe('API Keys reducer', () => {
|
|
|
|
|
it('should set keys', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
|
reducerTester<ApiKeysState>()
|
|
|
|
|
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
|
2021-12-16 05:46:09 -06:00
|
|
|
|
.whenActionIsDispatched(
|
|
|
|
|
apiKeysLoaded({ keys: getMultipleMockKeys(4), keysIncludingExpired: getMultipleMockKeys(6) })
|
|
|
|
|
)
|
2020-01-13 01:03:22 -06:00
|
|
|
|
.thenStateShouldEqual({
|
|
|
|
|
...initialApiKeysState,
|
|
|
|
|
keys: getMultipleMockKeys(4),
|
2021-12-16 05:46:09 -06:00
|
|
|
|
keysIncludingExpired: getMultipleMockKeys(6),
|
2020-01-13 01:03:22 -06:00
|
|
|
|
hasFetched: true,
|
|
|
|
|
});
|
2018-09-27 02:31:05 -05:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should set search query', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
|
reducerTester<ApiKeysState>()
|
|
|
|
|
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
|
|
|
|
|
.whenActionIsDispatched(setSearchQuery('test query'))
|
|
|
|
|
.thenStateShouldEqual({
|
|
|
|
|
...initialApiKeysState,
|
|
|
|
|
searchQuery: 'test query',
|
|
|
|
|
});
|
2018-09-27 02:31:05 -05:00
|
|
|
|
});
|
2021-12-16 05:46:09 -06:00
|
|
|
|
|
|
|
|
|
it('should toggle the includeExpired state', () => {
|
|
|
|
|
reducerTester<ApiKeysState>()
|
|
|
|
|
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
|
|
|
|
|
.whenActionIsDispatched(includeExpiredToggled())
|
|
|
|
|
.thenStateShouldEqual({
|
|
|
|
|
...initialApiKeysState,
|
|
|
|
|
includeExpired: true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should set state when fetching', () => {
|
|
|
|
|
reducerTester<ApiKeysState>()
|
|
|
|
|
.givenReducer(apiKeysReducer, { ...initialApiKeysState })
|
|
|
|
|
.whenActionIsDispatched(isFetching())
|
|
|
|
|
.thenStateShouldEqual({
|
|
|
|
|
...initialApiKeysState,
|
|
|
|
|
hasFetched: false,
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-09-27 02:31:05 -05:00
|
|
|
|
});
|