-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store PDF documents in db table (#371)
* Add form_documents table and an initializeForm service, responsible for creating a form that's initialized with data from a PDF. initializeForm is not currently wired to the UI. * Improve pattern builder docs * Fix test and typing errors; implement localStorage version of addDocument * Wire initializeForm to UI * PDF attachment download working * Fix imports * Rebuild lock file * Revert "Rebuild lock file" This reverts commit 0b0f6c7. * Remove pdf bytes from blueprint object * Parse/validate Blueprint JSON * Delete associated documents when a form is deleted. * Document support in-browser * Add tests for parseForm * Inject a FormConfig into the forms db adapter * Remove console.log * Call parseStringForm() in getForm db function * Update BrowserFormRepository for interface changes * Fix typo
- Loading branch information
1 parent
47ec6d4
commit 47ea8ce
Showing
67 changed files
with
1,357 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/database/migrations/20241031103354_form_documents_table.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export async function up(knex) { | ||
await knex.schema.createTable('form_documents', table => { | ||
table.uuid('id').primary(); | ||
table.string('type').notNullable(); | ||
table.string('file_name').notNullable(); | ||
table.binary('data').notNullable(); | ||
table.string('extract').notNullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export async function down(knex) { | ||
await knex.schema.dropTableIfExists('form_documents'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { failure, success } from '@atj/common'; | ||
|
||
import { parseForm, parseFormString } from './parse-form'; | ||
import { defaultFormConfig, type InputPattern } from '../patterns'; | ||
import type { Blueprint } from '../types'; | ||
|
||
describe('parseForm', () => { | ||
it('should return success when form data is valid', () => { | ||
const formData: Blueprint = { | ||
summary: { | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}, | ||
root: 'rootValue', | ||
patterns: { | ||
validPattern: { | ||
type: 'input', | ||
id: 'validPattern', | ||
data: { | ||
label: 'label', | ||
required: true, | ||
maxLength: 100, | ||
}, | ||
} satisfies InputPattern, | ||
}, | ||
outputs: [ | ||
{ | ||
id: 'output1', | ||
path: 'path/to/output', | ||
fields: { | ||
field1: { | ||
type: 'TextField', | ||
name: 'name', | ||
label: 'label', | ||
value: 'value', | ||
required: true, | ||
}, | ||
}, | ||
formFields: { | ||
formField1: 'formValue1', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const result = parseForm(defaultFormConfig, formData); | ||
expect(result).toEqual(success(formData)); | ||
}); | ||
|
||
it('should return failure when form data is invalid', () => { | ||
const formData = { | ||
summary: { | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}, | ||
root: 'rootValue', | ||
patterns: { | ||
invalidPattern: { | ||
type: 'invalidPattern', | ||
data: {}, | ||
}, | ||
}, | ||
outputs: [ | ||
{ | ||
id: 'output1', | ||
path: 'path/to/output', | ||
fields: { | ||
field1: 'value1', | ||
}, | ||
formFields: { | ||
formField1: 'formValue1', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const result = parseForm(defaultFormConfig, formData); | ||
expect(result.success).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('parseFormString', () => { | ||
it('should return success when JSON string is valid', () => { | ||
const jsonString = JSON.stringify({ | ||
summary: { | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}, | ||
root: 'rootValue', | ||
patterns: { | ||
validPattern: { | ||
type: 'input', | ||
id: 'validPattern', | ||
data: { | ||
label: 'label', | ||
required: true, | ||
maxLength: 100, | ||
initial: '', | ||
}, | ||
} satisfies InputPattern, | ||
}, | ||
outputs: [], | ||
} satisfies Blueprint); | ||
|
||
const result = parseFormString(defaultFormConfig, jsonString); | ||
expect(result).toEqual(success(JSON.parse(jsonString))); | ||
}); | ||
|
||
it('should return failure when JSON string is invalid', () => { | ||
const jsonString = JSON.stringify({ | ||
summary: { | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}, | ||
root: 'rootValue', | ||
patterns: { | ||
invalidPattern: { | ||
type: 'invalidPattern', | ||
data: {}, | ||
}, | ||
}, | ||
outputs: [ | ||
{ | ||
id: 'output1', | ||
path: 'path/to/output', | ||
fields: { | ||
field1: 'value1', | ||
}, | ||
formFields: { | ||
formField1: 'formValue1', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
const result = parseFormString(defaultFormConfig, jsonString); | ||
expect(result).toEqual({ | ||
success: false, | ||
error: | ||
'[\n' + | ||
' {\n' + | ||
' "code": "custom",\n' + | ||
' "message": "Invalid pattern",\n' + | ||
' "path": [\n' + | ||
' "patterns",\n' + | ||
' "invalidPattern"\n' + | ||
' ]\n' + | ||
' }\n' + | ||
']', | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.