Skip to content

Commit

Permalink
fix: error undefined stringInputs when google not send all input fiel…
Browse files Browse the repository at this point in the history
…ds, fixes #12
  • Loading branch information
dyaskur committed Aug 27, 2023
1 parent c96a49b commit 33b8174
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/helpers/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ export function getStateFromCard(event: chatV1.Schema$DeprecatedEvent) {

export function getConfigFromInput(formValues: PollFormInputs) {
const state: PollConfig = {topic: '', choices: []};

state.topic = formValues.topic.stringInputs!.value![0]!.trim();
state.anon = formValues.is_anonymous.stringInputs!.value![0] === '1';
state.optionable = formValues.allow_add_option.stringInputs!.value![0] === '1';
state.type = parseInt(formValues.type.stringInputs!.value![0]) as ClosableType;
state.topic = formValues.topic.stringInputs!.value![0]!.trim() ?? '';
state.anon = formValues.is_anonymous?.stringInputs!.value![0] === '1';
state.optionable = formValues.allow_add_option?.stringInputs!.value![0] === '1';
state.type = parseInt(formValues.type?.stringInputs!.value![0] ?? '1') as ClosableType;

for (let i = 0; i < MAX_NUM_OF_OPTIONS; ++i) {
const choice = formValues[`option${i}`]!.stringInputs!.value![0]!.trim();
const choice = formValues[`option${i}`]?.stringInputs!.value![0]!.trim();
if (choice) {
state.choices.push(choice);
}
Expand Down
14 changes: 0 additions & 14 deletions tests/action-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ describe('startPoll', () => {
invokedFunction: 'start_poll',
formInputs: {
topic: {stringInputs: {value: ['Topic']}},
is_anonymous: {stringInputs: {value: ['0']}},
allow_add_option: {stringInputs: {value: ['0']}},
type: {stringInputs: {value: ['0']}},
option0: {stringInputs: {value: ['Yay']}},
Expand All @@ -265,10 +264,6 @@ describe('startPoll', () => {
option3: {stringInputs: {value: ['']}},
option4: {stringInputs: {value: ['']}},
option5: {stringInputs: {value: ['No Way']}},
option6: {stringInputs: {value: ['']}},
option7: {stringInputs: {value: ['']}},
option8: {stringInputs: {value: ['']}},
option9: {stringInputs: {value: ['']}},
},
},
user: {displayName: 'User'},
Expand Down Expand Up @@ -316,15 +311,6 @@ describe('startPoll', () => {
allow_add_option: {stringInputs: {value: ['1']}},
type: {stringInputs: {value: ['1']}},
option0: {stringInputs: {value: ['Option 1']}},
option1: {stringInputs: {value: ['']}},
option2: {stringInputs: {value: ['']}},
option3: {stringInputs: {value: ['']}},
option4: {stringInputs: {value: ['']}},
option5: {stringInputs: {value: ['']}},
option6: {stringInputs: {value: ['']}},
option7: {stringInputs: {value: ['']}},
option8: {stringInputs: {value: ['']}},
option9: {stringInputs: {value: ['']}},
},
},
};
Expand Down

0 comments on commit 33b8174

Please sign in to comment.