Skip to content

Commit 4054893

Browse files
committed
feat(admin-ui): api test cases for admin module #1262
1 parent 03c9171 commit 4054893

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+676
-36
lines changed

admin-ui/app/redux/sagas/MauSaga.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ export function* getMau({ payload }) {
2626
const data = yield call(mauApi.getMau, payload.action.action_data)
2727
yield put(getMauResponse({ data: buildData(data) }))
2828
yield call(postUserAction, audit)
29+
return data
2930
} catch (e) {
3031
yield put(getMauResponse(null))
3132
if (isFourZeroOneError(e)) {
3233
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
3334
yield put(getAPIAccessToken(jwt))
3435
}
36+
return e
3537
}
3638
}
3739

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { combineReducers } from '@reduxjs/toolkit'
2+
import {
3+
authReducerInit,
4+
beforeAllAsync,
5+
} from 'Plugins/admin/__tests__/api/setup.test'
6+
import {
7+
getScriptsByType,
8+
addScript,
9+
deleteScript,
10+
editScript,
11+
} from 'Plugins/admin/redux/sagas/CustomScriptSaga'
12+
import {
13+
initialState as customScriptInitState,
14+
reducer as customScriptReducer,
15+
} from 'Plugins/admin/redux/features/customScriptSlice'
16+
import { expectSaga } from 'redux-saga-test-plan'
17+
import authReducer from 'Redux/features/authSlice'
18+
import { log } from 'console'
19+
20+
let initialState
21+
22+
const formInitState = (token, issuer) => {
23+
initialState = {
24+
authReducer: authReducerInit(token, issuer),
25+
customScriptReducer: customScriptInitState,
26+
}
27+
}
28+
29+
beforeAll(async () => {
30+
try {
31+
await beforeAllAsync(formInitState)
32+
} catch (error) {
33+
log(error.message)
34+
}
35+
})
36+
37+
const rootReducer = combineReducers({
38+
authReducer,
39+
customScriptReducer,
40+
})
41+
42+
const createPayload = {
43+
moduleProperties: [
44+
{
45+
value1: 'location_type',
46+
value2: 'db',
47+
description: '',
48+
},
49+
{
50+
value1: 'usage_type',
51+
value2: 'interactive',
52+
description: '',
53+
},
54+
],
55+
locationType: 'db',
56+
level: 2,
57+
name: 'test',
58+
description: 'test',
59+
scriptType: 'person_authentication',
60+
programmingLanguage: 'java',
61+
script: 'test script which should fail',
62+
configurationProperties: [
63+
{
64+
value1: 'test',
65+
value2: 'test2',
66+
hide: false,
67+
},
68+
],
69+
enabled: true,
70+
}
71+
72+
describe('fetch & update custom scripts', () => {
73+
let createdScript
74+
it('should GET custom scripts which are person_authentication type', async () => {
75+
const result = await expectSaga(getScriptsByType, {
76+
payload: { action: { type: 'person_authentication' } },
77+
})
78+
.withReducer(rootReducer, initialState)
79+
.run(false)
80+
81+
expect(result.returnValue instanceof Error).toBe(false)
82+
if (!(result.returnValue instanceof Error)) {
83+
expect(result.returnValue.entries).toEqual(
84+
result.storeState.customScriptReducer.items
85+
)
86+
}
87+
})
88+
89+
it('should add test script', async () => {
90+
const result = await expectSaga(addScript, {
91+
payload: { action: { action_data: { customScript: createPayload } } },
92+
})
93+
.withReducer(rootReducer, initialState)
94+
.run(false)
95+
96+
expect(result.returnValue instanceof Error).toBe(false)
97+
if (!(result.returnValue instanceof Error)) {
98+
createdScript = result.returnValue
99+
}
100+
})
101+
102+
it('should update newly created script', async () => {
103+
if (createdScript) {
104+
const result = await expectSaga(editScript, {
105+
payload: {
106+
action: {
107+
action_data: {
108+
customScript: { ...createdScript, name: 'update_tests' },
109+
},
110+
},
111+
},
112+
})
113+
.withReducer(rootReducer, initialState)
114+
.silentRun(false)
115+
116+
expect(result.returnValue instanceof Error).toBe(false)
117+
} else {
118+
log('failed to created script, ABORTING update test')
119+
}
120+
})
121+
122+
it('should delete newly created script', async () => {
123+
if (createdScript) {
124+
const result = await expectSaga(deleteScript, {
125+
payload: { action: { action_data: createdScript.inum } },
126+
})
127+
.withReducer(rootReducer, initialState)
128+
.silentRun(false)
129+
expect(result.returnValue instanceof Error).toBe(false)
130+
} else {
131+
log('failed to created script, ABORTING delete test')
132+
}
133+
})
134+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import { combineReducers } from '@reduxjs/toolkit'
2+
import {
3+
authReducerInit,
4+
beforeAllAsync,
5+
} from 'Plugins/admin/__tests__/api/setup.test'
6+
import {
7+
fetchMapping,
8+
addMapping,
9+
deleteMapping,
10+
updateMapping,
11+
} from 'Plugins/admin/redux/sagas/MappingSaga'
12+
import {
13+
deletePermission,
14+
addPermission,
15+
} from 'Plugins/admin/redux/sagas/ApiPermissionSaga'
16+
import { addRole, deleteRole } from 'Plugins/admin/redux/sagas/ApiRoleSaga'
17+
import {
18+
initialState as mappingInitState,
19+
reducer as mappingReducer,
20+
} from 'Plugins/admin/redux/features/mappingSlice'
21+
import { expectSaga } from 'redux-saga-test-plan'
22+
import authReducer from 'Redux/features/authSlice'
23+
import { reducer as apiRoleReducer } from 'Plugins/admin/redux/features/apiRoleSlice'
24+
import { log } from 'console'
25+
26+
let initialState
27+
28+
const formInitState = (token, issuer) => {
29+
initialState = {
30+
authReducer: authReducerInit(token, issuer),
31+
mappingReducer: mappingInitState,
32+
apiRoleReducer: { items: [] },
33+
}
34+
}
35+
36+
beforeAll(async () => {
37+
try {
38+
await beforeAllAsync(formInitState)
39+
} catch (error) {
40+
log(error.message)
41+
}
42+
})
43+
44+
const rootReducer = combineReducers({
45+
authReducer,
46+
mappingReducer,
47+
apiRoleReducer,
48+
})
49+
50+
const uiRolePayload = {
51+
role: 'test-role',
52+
description: 'test description',
53+
deletable: true,
54+
}
55+
56+
const read_permission = 'https://jans.io/oauth/config/test_jest.read'
57+
const write_permission = 'https://jans.io/oauth/config/test_jest.write'
58+
59+
const mappingPayload = {
60+
role: uiRolePayload.role,
61+
permissions: [read_permission, write_permission],
62+
}
63+
64+
describe('perform CRUD action for mapping module', () => {
65+
let uiRole
66+
it('should fetch mapping role permissions', async () => {
67+
const result = await expectSaga(fetchMapping, {
68+
payload: {
69+
action: {},
70+
},
71+
})
72+
.withReducer(rootReducer, initialState)
73+
.run(false)
74+
75+
expect(result.returnValue instanceof Error).toBe(false)
76+
})
77+
78+
it('should create new permission https://jans.io/oauth/config/test_jest.read', async () => {
79+
const result = await expectSaga(addPermission, {
80+
payload: {
81+
action: {
82+
action_data: { permission: read_permission, description: 'desc' },
83+
},
84+
},
85+
})
86+
.withReducer(rootReducer, initialState)
87+
.run(false)
88+
89+
expect(result.returnValue instanceof Error).toBe(false)
90+
})
91+
92+
it('should create new permission https://jans.io/oauth/config/test_jest.write', async () => {
93+
const result = await expectSaga(addPermission, {
94+
payload: {
95+
action: {
96+
action_data: { permission: write_permission, description: 'desc' },
97+
},
98+
},
99+
})
100+
.withReducer(rootReducer, initialState)
101+
.run(false)
102+
103+
expect(result.returnValue instanceof Error).toBe(false)
104+
})
105+
106+
it('should create new test role', async () => {
107+
const result = await expectSaga(addRole, {
108+
payload: { action: { action_data: uiRolePayload } },
109+
})
110+
.withReducer(rootReducer, initialState)
111+
.run(false)
112+
113+
expect(result.returnValue instanceof Error).toBe(false)
114+
if (!(result.returnValue instanceof Error)) {
115+
uiRole = result.returnValue
116+
}
117+
})
118+
119+
it('should add mapping', async () => {
120+
if (uiRole) {
121+
const result = await expectSaga(addMapping, {
122+
payload: {
123+
data: mappingPayload,
124+
},
125+
})
126+
.withReducer(rootReducer, initialState)
127+
.run(false)
128+
129+
expect(result.returnValue instanceof Error).toBe(false)
130+
} else {
131+
log('skipping test, no test permission found!')
132+
}
133+
})
134+
135+
it('should update mapping', async () => {
136+
if (uiRole) {
137+
const result = await expectSaga(updateMapping, {
138+
payload: {
139+
data: {
140+
role: mappingPayload.role,
141+
permissions: ['https://jans.io/oauth/config/test_jest.write'],
142+
},
143+
},
144+
})
145+
.withReducer(rootReducer, initialState)
146+
.run(false)
147+
148+
expect(result.returnValue instanceof Error).toBe(false)
149+
} else {
150+
log('skipping test, no test permission found!')
151+
}
152+
})
153+
154+
it('should delete newly created mapping item', async () => {
155+
if (uiRole) {
156+
const result = await expectSaga(deleteMapping, {
157+
payload: {
158+
data: {
159+
role: mappingPayload.role,
160+
permissions: ['https://jans.io/oauth/config/test_jest.write'],
161+
},
162+
},
163+
})
164+
.withReducer(rootReducer, initialState)
165+
.run(false)
166+
167+
expect(result.returnValue instanceof Error).toBe(false)
168+
} else {
169+
log('skipping test, no test permission found!')
170+
}
171+
})
172+
173+
it('should delete permission https://jans.io/oauth/config/test_jest.read', async () => {
174+
const result = await expectSaga(deletePermission, {
175+
payload: {
176+
action: {
177+
action_data: { permission: read_permission, description: 'desc' },
178+
},
179+
},
180+
})
181+
.withReducer(rootReducer, initialState)
182+
.run(false)
183+
184+
expect(result.returnValue instanceof Error).toBe(false)
185+
})
186+
187+
it('should delete permission https://jans.io/oauth/config/test_jest.write', async () => {
188+
const result = await expectSaga(deletePermission, {
189+
payload: {
190+
action: {
191+
action_data: { permission: write_permission, description: 'desc' },
192+
},
193+
},
194+
})
195+
.withReducer(rootReducer, initialState)
196+
.run(false)
197+
198+
expect(result.returnValue instanceof Error).toBe(false)
199+
})
200+
201+
it('should delete newly added role', async () => {
202+
if (uiRole) {
203+
const result = await expectSaga(deleteRole, {
204+
payload: {
205+
action: {
206+
action_data: { ...uiRolePayload },
207+
},
208+
},
209+
})
210+
.withReducer(rootReducer, initialState)
211+
.run(false)
212+
213+
expect(result.returnValue instanceof Error).toBe(false)
214+
} else {
215+
log('skipping delete test, no role found!!!')
216+
}
217+
})
218+
})

0 commit comments

Comments
 (0)