Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasey committed Dec 20, 2024
1 parent 155a19b commit 32955af
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 57 deletions.
56 changes: 0 additions & 56 deletions lib/proposals/forms/__tests__/upsertProposalFormAnswers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,62 +236,6 @@ describe('upsertFormAnswers', () => {
);
});

it('should throw an error if not all required fields were provided', async () => {
const fieldsInput: FormFieldInput[] = [
{
id: v4(),
type: 'short_text',
name: 'name',
description: 'description',
index: 0,
options: [],
private: false,
required: true,
fieldConfig: {},
dependsOnStepIndex: null
},
{
id: v4(),
type: 'long_text',
name: 'long name',
description: 'another description',
index: 1,
options: [],
private: true,
required: true,
fieldConfig: {},
dependsOnStepIndex: null
}
];

const formId = await createForm(fieldsInput);

await prisma.proposal.update({
where: { id: proposal.id },
data: { formId }
});

await expect(
upsertProposalFormAnswers({
proposalId: proposal.id,
answers: [{ fieldId: fieldsInput[0].id, value: '' }]
})
).rejects.toBeInstanceOf(InvalidInputError);

// allow draft override
await prisma.proposal.update({
where: { id: proposal.id },
data: { status: 'draft' }
});

await expect(
upsertProposalFormAnswers({
proposalId: proposal.id,
answers: [{ fieldId: fieldsInput[0].id, value: '123' }]
})
).resolves.toBeTruthy();
});

it('should throw an error if invalid fieldId was provided', async () => {
const fieldsInput: FormFieldInput[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion pages/api/proposals/[id]/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function publishProposalStatusController(req: NextApiRequest, res: NextApi
throw new ActionNotPermittedError(`You cannot publish an archived proposal`);
}
// dont expect values for any form fields that depend on an evaluation step
const formFields = (proposalPage.proposal.form?.formFields as unknown as FormFieldInput[]).filter(
const formFields = (proposalPage.proposal.form?.formFields as unknown as FormFieldInput[])?.filter(
(field) => typeof field.dependsOnStepIndex !== 'number'
);
const errors = getProposalErrors({
Expand Down

0 comments on commit 32955af

Please sign in to comment.