|
| 1 | +import { |
| 2 | + getLogging, |
| 3 | + editLogging, |
| 4 | +} from 'Plugins/auth-server/redux/sagas/LoggingSaga' |
| 5 | +import { authReducerInit, beforeAllAsync } from './setup.test' |
| 6 | +import { combineReducers } from '@reduxjs/toolkit' |
| 7 | +import authReducer from 'Redux/features/authSlice' |
| 8 | +import { reducer as loggingReducer } from 'Plugins/auth-server/redux/features/loggingSlice' |
| 9 | +import { expectSaga } from 'redux-saga-test-plan' |
| 10 | +import { log } from 'console' |
| 11 | + |
| 12 | +let initialState |
| 13 | + |
| 14 | +const formInitState = (token, issuer) => { |
| 15 | + initialState = { |
| 16 | + authReducer: authReducerInit(token, issuer), |
| 17 | + loggingReducer: { |
| 18 | + logging: {}, |
| 19 | + }, |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +beforeAll(async () => { |
| 24 | + try { |
| 25 | + await beforeAllAsync(formInitState) |
| 26 | + } catch (error) { |
| 27 | + log(error.message) |
| 28 | + } |
| 29 | +}) |
| 30 | + |
| 31 | +const rootReducer = combineReducers({ |
| 32 | + authReducer, |
| 33 | + loggingReducer, |
| 34 | +}) |
| 35 | + |
| 36 | +describe('test GET & update action for logging page', () => { |
| 37 | + let configs |
| 38 | + |
| 39 | + it('GET current logging config', async () => { |
| 40 | + const result = await expectSaga(getLogging) |
| 41 | + .withReducer(rootReducer, initialState) |
| 42 | + .silentRun(false) |
| 43 | + |
| 44 | + configs = result.returnValue |
| 45 | + expect(result.returnValue instanceof Error).toBe(false) |
| 46 | + expect(result.returnValue).toEqual(result.storeState.loggingReducer.logging) |
| 47 | + }) |
| 48 | + |
| 49 | + it('update httpLoggingEnabled from current logging config', async () => { |
| 50 | + if (!(configs instanceof Error)) { |
| 51 | + const result = await expectSaga(editLogging, { |
| 52 | + payload: { |
| 53 | + data: { |
| 54 | + logging: { |
| 55 | + ...configs, |
| 56 | + httpLoggingEnabled: !configs.httpLoggingEnabled, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }) |
| 61 | + .withReducer(rootReducer, initialState) |
| 62 | + .silentRun(false) |
| 63 | + |
| 64 | + expect(result.returnValue instanceof Error).toBe(false) |
| 65 | + } else { |
| 66 | + log('Error occured while fetching') |
| 67 | + } |
| 68 | + }) |
| 69 | + |
| 70 | + it('should toggle back value of httpLoggingEnabled', async () => { |
| 71 | + if (!(configs instanceof Error)) { |
| 72 | + const result = await expectSaga(editLogging, { |
| 73 | + payload: { |
| 74 | + data: { |
| 75 | + logging: { |
| 76 | + ...configs, |
| 77 | + httpLoggingEnabled: configs.httpLoggingEnabled, |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }) |
| 82 | + .withReducer(rootReducer, initialState) |
| 83 | + .silentRun(false) |
| 84 | + |
| 85 | + expect(result.returnValue instanceof Error).toBe(false) |
| 86 | + } else { |
| 87 | + log('Error occured while fetching') |
| 88 | + } |
| 89 | + }) |
| 90 | +}) |
0 commit comments