Skip to content

Commit 637e14b

Browse files
committed
fix: error-states-should-clear
1 parent 6e2bce8 commit 637e14b

File tree

6 files changed

+102
-7
lines changed

6 files changed

+102
-7
lines changed

.changeset/cute-snails-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@forgerock/davinci-client': patch
3+
---
4+
5+
error states should be cleared from state when a successful next or success node was processed

packages/davinci-client/src/lib/collector.utils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,15 @@ describe('Object value collectors', () => {
427427
title: 'Device 1',
428428
id: '123123',
429429
default: true,
430-
value: 'device1-value',
430+
description: 'device1-value',
431431
},
432432
{
433433
type: 'device2',
434434
iconSrc: 'icon2.png',
435435
title: 'Device 2',
436436
id: '345345',
437437
default: false,
438-
value: 'device2-value',
438+
description: 'device2-value',
439439
},
440440
],
441441
required: true,
@@ -444,7 +444,7 @@ describe('Object value collectors', () => {
444444
const transformedDevices = mockField.options.map((device) => ({
445445
label: device.title,
446446
value: device.id,
447-
content: device.value,
447+
content: device.description,
448448
type: device.type,
449449
key: device.id,
450450
default: device.default,

packages/davinci-client/src/lib/collector.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,15 @@ export function returnObjectCollector<
374374
const unmappedDefault = field.options.find((device) => device.default);
375375
defaultValue = {
376376
type: unmappedDefault ? unmappedDefault.type : '',
377-
value: unmappedDefault ? unmappedDefault.value : '',
377+
value: unmappedDefault ? unmappedDefault.description : '',
378378
id: unmappedDefault ? unmappedDefault.id : '',
379379
};
380380

381381
// Map DaVinci spec to normalized SDK API
382382
options = field.options.map((device) => ({
383383
type: device.type,
384384
label: device.title,
385-
content: device.value,
385+
content: device.description,
386386
value: device.id,
387387
key: device.id,
388388
default: device.default,

packages/davinci-client/src/lib/davinci.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export type DeviceAuthenticationField = {
126126
title: string;
127127
id: string;
128128
default: boolean;
129-
value: string;
129+
description: string;
130130
}[];
131131
required: boolean;
132132
};

packages/davinci-client/src/lib/node.slice.test.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,49 @@ describe('The node slice reducers', () => {
4141
expect(nodeSlice.reducer(undefined, action)).toEqual(nodeNext0);
4242
});
4343

44+
it('should clear error when we successfully process a node with a next', () => {
45+
const actionError = {
46+
type: 'node/error',
47+
payload: {
48+
data: error0a,
49+
requestId: '1234',
50+
httpStatus: 400,
51+
},
52+
};
53+
const errorState = {
54+
cache: {
55+
key: '1234',
56+
},
57+
client: {
58+
status: 'error' as const,
59+
},
60+
error: {
61+
code: ' Invalid username and/or password',
62+
collectors: [],
63+
message: ' Invalid username and/or password',
64+
internalHttpStatus: 400,
65+
status: 'error',
66+
type: 'davinci_error',
67+
},
68+
httpStatus: 400,
69+
server: {
70+
status: 'error',
71+
},
72+
status: 'error',
73+
};
74+
const errorStateReducer = nodeSlice.reducer(undefined, actionError);
75+
expect(errorStateReducer).toEqual(errorState);
76+
77+
const action = {
78+
type: 'node/next',
79+
payload: {
80+
data: next0,
81+
requestId: '1234',
82+
httpStatus: 200,
83+
},
84+
};
85+
expect(nodeSlice.reducer(errorStateReducer, action)).toEqual(nodeNext0);
86+
});
4487
it('should handle success node after DaVinci flow', () => {
4588
const action = {
4689
type: 'node/success',
@@ -67,6 +110,50 @@ describe('The node slice reducers', () => {
67110
expect(nodeSlice.reducer(undefined, action)).toEqual(nodeSuccess1);
68111
});
69112

113+
it('should clear error when we successfully process a node', () => {
114+
const action = {
115+
type: 'node/error',
116+
payload: {
117+
data: error0a,
118+
requestId: '1234',
119+
httpStatus: 400,
120+
},
121+
};
122+
const errorState = {
123+
cache: {
124+
key: '1234',
125+
},
126+
client: {
127+
status: 'error' as const,
128+
},
129+
error: {
130+
code: ' Invalid username and/or password',
131+
collectors: [],
132+
message: ' Invalid username and/or password',
133+
internalHttpStatus: 400,
134+
status: 'error',
135+
type: 'davinci_error',
136+
},
137+
httpStatus: 400,
138+
server: {
139+
status: 'error',
140+
},
141+
status: 'error',
142+
};
143+
const errorStateReducer = nodeSlice.reducer(undefined, action);
144+
expect(errorStateReducer).toEqual(errorState);
145+
146+
const actionSuccess = {
147+
type: 'node/success',
148+
payload: {
149+
data: success1,
150+
requestId: '1234',
151+
httpStatus: 200,
152+
},
153+
};
154+
expect(nodeSlice.reducer(errorStateReducer, actionSuccess)).toEqual(nodeSuccess1);
155+
});
156+
70157
it('should handle error node', () => {
71158
const action = {
72159
type: 'node/error',

packages/davinci-client/src/lib/node.slice.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const initialNodeState = {
5151
status: START_STATUS,
5252
},
5353
status: START_STATUS,
54-
};
54+
} satisfies StartNode;
5555

5656
type NodeStates = ErrorNode | FailureNode | ContinueNode | SuccessNode | StartNode;
5757

@@ -204,6 +204,8 @@ export const nodeSlice = createSlice({
204204
status: CONTINUE_STATUS,
205205
};
206206

207+
newState.error = null;
208+
207209
newState.httpStatus = action.payload.httpStatus;
208210

209211
newState.server = {
@@ -257,6 +259,7 @@ export const nodeSlice = createSlice({
257259
status: SUCCESS_STATUS,
258260
};
259261

262+
newState.error = null;
260263
newState.status = SUCCESS_STATUS;
261264

262265
return newState;

0 commit comments

Comments
 (0)