Skip to content

Commit 905441a

Browse files
Merge pull request #31 from Nandgopal-R/docs/comments
docs: add schema diagram in readme
2 parents c7594ab + f39b8bc commit 905441a

7 files changed

Lines changed: 326 additions & 0 deletions

File tree

‎Form-Engine-Testing-Strategy.md‎

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
# Form Engine – Testing Strategy Document
2+
3+
## Testing Overview
4+
5+
Testing is conducted to ensure that the Form Engine platform functions correctly, reliably, and securely before deployment. The Form Engine allows users to create, manage, publish, and respond to dynamic forms using drag-and-drop fields. Since the system includes both frontend and backend components along with a database layer, testing verifies that each component works individually and together.
6+
7+
Testing helps:
8+
- Detect bugs early
9+
- Validate functional requirements
10+
- Ensure correct form creation and response handling
11+
- Maintain data integrity
12+
- Improve overall software quality
13+
- Reduce production risks
14+
- Ensure accessibility compliance
15+
- Validate data security and privacy
16+
17+
Overall, testing increases confidence in system stability, performance, and usability.
18+
19+
## Technologies and Languages Used
20+
21+
### Backend
22+
- **TypeScript** – Core backend development with strict typing
23+
- **Bun** – Runtime and test execution environment
24+
- **Elysia.js** – Backend framework for REST APIs
25+
- **Prisma ORM** – Database interaction and schema management
26+
- **PostgreSQL** – Primary database with transaction support
27+
28+
### Frontend
29+
- **React** – UI development with hooks and state management
30+
- **TypeScript** – Frontend type safety and interfaces
31+
- **TanStack Router** – Client-side routing
32+
- **React Query** – API state management and caching
33+
34+
### Testing Tools and Frameworks
35+
36+
#### Backend Testing Stack
37+
- **Bun Test Runner** – Built-in test execution with Jest-like API
38+
- **Mocking (bun:test mock.module)** – Database and dependency mocking
39+
- **Prisma Test Client** – Database testing with isolated transactions
40+
- **Supertest** – HTTP endpoint testing (when needed)
41+
42+
#### Frontend Testing Stack
43+
- **Vitest** – Component and utility testing with React Testing Library
44+
- **React Testing Library** – Component behavior testing from user perspective
45+
- **MSW (Mock Service Worker)** – API mocking for integration tests
46+
- **@testing-library/user-event** – User interaction simulation
47+
- **jsdom** – Browser environment simulation for tests
48+
49+
#### Development and Debugging Tools
50+
- **Prisma Studio** – Database inspection and verification
51+
- **Browser DevTools** – Network requests and UI debugging
52+
- **Bruno** – API endpoint testing and validation
53+
54+
## Comprehensive Testing Tools & Frameworks Summary
55+
56+
### Backend Testing Tools
57+
58+
| Tool/Framework | Purpose | Usage |
59+
|----------------|---------|-------|
60+
| **Bun Test Runner** | Unit and integration testing | Primary test execution for backend TypeScript code |
61+
| **bun:test mock.module** | Mocking dependencies | Mock database, external services, and modules |
62+
| **Prisma Test Client** | Database testing | Isolated transactions, schema validation |
63+
| **Supertest** | HTTP endpoint testing | API integration tests when needed |
64+
| **c8** | Code coverage | Coverage reporting for Bun tests |
65+
66+
### Frontend Testing Tools
67+
68+
| Tool/Framework | Purpose | Usage |
69+
|----------------|---------|-------|
70+
| **Vitest** | Test runner | Fast unit and integration testing for React |
71+
| **React Testing Library** | Component testing | User-centric component behavior testing |
72+
| **@testing-library/user-event** | User interaction | Simulate clicks, typing, form submission |
73+
| **@testing-library/jest-dom** | Assertions | Custom matchers for DOM testing |
74+
| **jsdom** | Browser simulation | DOM environment for Node-based tests |
75+
| **MSW (Mock Service Worker)** | API mocking | Intercept and mock HTTP requests |
76+
| **Vitest UI** | Test visualization | Interactive test result exploration |
77+
| **@vitest/coverage-v8** | Code coverage | Frontend coverage reporting |
78+
79+
### Code Quality & Static Analysis
80+
81+
| Tool | Purpose | Usage |
82+
|------|---------|-------|
83+
| **Biome** | Linting & formatting | Fast TypeScript/JavaScript linting |
84+
| **TypeScript Compiler (tsc)** | Type checking | Static type validation |
85+
| **ESLint** (if used) | Code linting | Additional linting rules |
86+
| **Prettier** (if used) | Code formatting | Consistent code style |
87+
88+
### CI/CD & Automation Tools
89+
90+
| Tool | Purpose | Usage |
91+
|------|---------|-------|
92+
| **GitHub Actions** | CI/CD pipeline | Automated testing on commits/PRs |
93+
| **Husky** | Git hooks | Pre-commit/pre-push test execution |
94+
| **lint-staged** | Staged file processing | Run tests only on changed files |
95+
| **Codecov** | Coverage reporting | Coverage visualization and tracking |
96+
| **Docker** | Containerization | Isolated test environment setup |
97+
| **Docker Compose** | Multi-container setup | Database + app testing environment |
98+
99+
100+
### Monitoring & Debugging Tools
101+
102+
| Tool | Purpose | Usage |
103+
|------|---------|-------|
104+
| **Chrome DevTools** | Frontend debugging | Network, performance, console debugging |
105+
| **Bruno** | API client | API collection management and testing |
106+
| **React Query DevTools** | State debugging | API cache and query state inspection |
107+
108+
109+
## Testing Levels and Scope
110+
111+
### 1. Unit Testing
112+
113+
#### Backend Unit Tests
114+
**Coverage Target: 85%+ code coverage, 95%+ controller coverage**
115+
116+
**Forms Controller (`src/api/forms/controller.ts`)**
117+
- **Functions Tested:**
118+
- `getAllForms` – Form listing with pagination
119+
- `createForm` – Form creation with validation
120+
- `getFormById` – Individual form retrieval
121+
- `updateFormById` – Form modification
122+
- `deleteForm` – Form deletion with cascade
123+
- `publishForm` – Form publishing workflow
124+
- `unPublishForm` – Form unpublishing
125+
- `getPublicFormById` – Public form access
126+
127+
- **Test Scenarios:**
128+
- Success cases with valid data
129+
- Empty data handling
130+
- Not found error scenarios (404)
131+
- Unauthorized access (403)
132+
- Database transaction failures
133+
- Input validation and sanitization
134+
- SQL injection prevention
135+
- Ownership validation
136+
137+
**Form Fields Controller (`src/api/form-fields/controller.ts`)**
138+
- **Functions Tested:**
139+
- `getAllFields` – Field retrieval with ordering
140+
- `createField` – Field creation with linked-list positioning
141+
- `updateField` – Field modification and options handling
142+
- `deleteField` – Field deletion with linked-list maintenance
143+
- `swapFields` – Field position swapping
144+
145+
- **Test Scenarios:**
146+
- Linked-list ordering logic
147+
- Field options storage (radio, dropdown, checkbox)
148+
- Field type validation
149+
- Ownership and authorization
150+
- Invalid field references
151+
- Swap safety checks and same-form validation
152+
- Transaction reliability and rollback
153+
- CGPA field special handling
154+
155+
**Form Response Controller (`src/api/form-response/controller.ts`)**
156+
- **Functions Tested:**
157+
- `draftResponse` – Auto-save draft functionality
158+
- `getDraftResponse` – Draft retrieval
159+
- `submitResponse` – Final response submission
160+
- `getFormResponsesForFormOwner` – Response analytics
161+
- `getSubmittedResponse` – Individual response access
162+
163+
- **Test Scenarios:**
164+
- Published vs unpublished form access
165+
- Draft persistence and retrieval
166+
- Response validation and sanitization
167+
- Answer mapping and data integrity
168+
- Ownership restrictions
169+
- Concurrent draft handling
170+
- Response encryption (if implemented)
171+
172+
**Validation Engine (`src/lib/validation-engine.ts`)**
173+
- **Functions Tested:**
174+
- Field validation for all types (text, number, email, phone, CGPA)
175+
- Form validation with multiple fields
176+
- Validation configuration building
177+
- Pattern matching and custom rules
178+
- Error message generation
179+
180+
- **Test Scenarios:**
181+
- All 17 field types validation
182+
- Edge cases and boundary values
183+
- Custom validation rules
184+
- Email/phone format validation
185+
- CGPA range validation (0.00-10.00)
186+
- Required field validation
187+
- Cross-field dependencies (if implemented)
188+
189+
## Test Properties Matrix
190+
191+
This matrix defines what properties each component type will be tested for:
192+
193+
| Component Type | Properties Tested | Test Methods |
194+
|----------------|-------------------|--------------|
195+
| **Backend Controllers** | Correctness, Error Handling, Authorization, Data Integrity, Transaction Safety | Unit tests, Integration tests, Mock database |
196+
| **API Endpoints** | Response Format, Status Codes, Performance, Security, Input Validation | HTTP tests, Load tests, Security scans |
197+
| **Database Models** | Integrity Constraints, Relationships, Migrations, Transaction Atomicity | Prisma tests, Migration tests, Rollback tests |
198+
| **UI Components** | Rendering Accuracy, Accessibility, User Interaction, Responsive Design, Error States | Component tests, Visual regression, a11y audits |
199+
| **Validation Engine** | Accuracy, Edge Cases, Error Messages, Pattern Matching, Custom Rules | Unit tests, Boundary tests, Regex validation |
200+
| **Forms** | Field Ordering, Required Fields, Options Storage, Validation Rules | Integration tests, E2E tests |
201+
| **Authentication** | Session Management, Token Security, OAuth Flow, Password Hashing | Security tests, Integration tests |
202+
| **API Clients** | Error Handling, Retry Logic, Response Parsing, Request Formation | Unit tests, Mock API responses |
203+
| **State Management** | Data Consistency, Cache Invalidation, Optimistic Updates | Integration tests, State inspection |
204+
| **Routing** | Navigation, Protected Routes, Parameter Handling, Redirects | E2E tests, Router tests |
205+
206+
207+
208+
#### Frontend Unit Tests
209+
**Coverage Target: 80%+ component coverage, 90%+ utility coverage**
210+
211+
**Component Testing (`src/components/`)**
212+
- **Field Components (`components/fields/`)**:
213+
- `FieldItems` – Field type selection
214+
- `FieldPreview` – Editor field rendering (all 17 types)
215+
- `FieldProperties` – Field configuration dialog
216+
- `FormFieldRenderer` – Form filler field rendering
217+
218+
- **UI Components (`components/ui/`)**:
219+
- `Input`, `Button`, `Checkbox`, `Switch`, `Slider`
220+
- `Field`, `Label`, `Toast`, `Dialog`
221+
- Custom form controls and primitives
222+
223+
- **Layout Components**:
224+
- `Header` – Navigation and auth
225+
- `AppSidebar` – Form navigation
226+
- `EditorCanvas` – Drag-and-drop interface
227+
228+
**Test Properties for Components:**
229+
- **Rendering**: Correct display in various states
230+
- **User Interaction**: Click, change, submit events
231+
- **Accessibility**: ARIA attributes, keyboard navigation
232+
- **Responsiveness**: Mobile and desktop layouts
233+
- **Error Handling**: Validation states, network errors
234+
- **Performance**: Render optimization, memoization
235+
236+
**Utility Testing (`src/lib/`)**
237+
- `validation-engine.test.ts` – Validation logic
238+
- `utils.test.ts` – Helper functions
239+
- `auth-client.test.ts` – Authentication utilities
240+
241+
### 2. Integration Testing
242+
243+
#### Backend Integration Tests
244+
- **Database Integration**:
245+
- Prisma model relationships
246+
- Transaction consistency
247+
- Migration testing
248+
- Data integrity constraints
249+
250+
- **API Integration**:
251+
- Controller-Service-Database flow
252+
- Error propagation
253+
- Request/response transformation
254+
- Authentication middleware
255+
256+
#### Frontend Integration Tests
257+
- **Component Integration**:
258+
- Parent-child component communication
259+
- State management across components
260+
- API integration with React Query
261+
- Router integration
262+
263+
- **API Integration**:
264+
- Mock API responses with MSW
265+
- Error state handling
266+
- Loading states
267+
- Retry logic
268+
269+
### 3. System Testing (End-to-End)
270+
271+
**Workflow Validation**:
272+
1. **Form Creation Workflow**:
273+
- User registration → Login → Create form → Add fields → Configure properties → Save → Publish
274+
275+
2. **Form Response Workflow**:
276+
- Access public form → Fill all field types → Validate input → Save draft → Submit response
277+
278+
3. **Form Management Workflow**:
279+
- View forms → Edit fields → Update options → Re-publish → View responses
280+
281+
4. **Edge Case Workflows**:
282+
- Concurrent form editing
283+
- Large forms with many fields
284+
- Network interruption during form filling
285+
- Browser refresh with unsaved changes
286+
287+
**Data Flow Testing**:
288+
- Frontend ↔ Backend API communication
289+
- Backend ↔ Database operations
290+
- Real-time updates (if implemented)
291+
- Form field options persistence
292+
293+
### 4. Compatibility Testing
294+
295+
**Browser Testing Matrix**:
296+
| Browser | Versions | Priority |
297+
|---------|----------|----------|
298+
| Chrome | Latest, Latest-1 | High |
299+
| Firefox | Latest, Latest-1 | High |
300+
| Safari | Latest, Latest-1 | High |
301+
| Edge | Latest | Medium |
302+
| Mobile Safari (iOS) | Latest, Latest-1 | High |
303+
| Chrome Mobile (Android) | Latest | High |
304+
305+
**Device Testing**:
306+
- **Desktop**: 1920x1080, 1366x768, 2560x1440
307+
- **Tablet**: iPad (1024x768), iPad Pro (1366x1024)
308+
- **Mobile**: iPhone (375x667), Android (360x640), Large phones (414x896)
309+
310+
311+
**Operating Systems**:
312+
- Windows 10/11
313+
- macOS (Monterey, Ventura, Sonoma)
314+
- iOS 15+
315+
- Android 11+

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ The platform helps colleges efficiently collect data for use cases such as event
2323
### Architecture Diagram
2424
![Architecture Diagram](./images/ArchitectureDiagram.png)
2525

26+
### Schema Diagram
27+
![Schema Diagram](./images/schemaDiagram.png)
28+
2629
### Activity Diagram
2730
![Activity Diagram](./images/ActivityDiagram.jpg)
2831

‎images/schemaDiagram.png‎

81.8 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "form_fields" ADD COLUMN "options" JSONB;

‎prisma/schema.prisma‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ model FormFields {
8787
fieldValueType String
8888
fieldType String
8989
validation Json?
90+
options Json?
9091
createdAt DateTime @default(now())
9192
updatedAt DateTime @updatedAt
9293
formId String

‎src/api/form-fields/controller.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export async function createField({
9090
fieldValueType: body.fieldValueType,
9191
fieldType: body.fieldType,
9292
validation: body.validation ?? undefined,
93+
options: body.options ?? undefined,
9394
formId: params.formId,
9495
prevFieldId: null,
9596
},
@@ -138,6 +139,7 @@ export async function createField({
138139
fieldValueType: body.fieldValueType,
139140
fieldType: body.fieldType,
140141
validation: body.validation ?? undefined,
142+
options: body.options ?? undefined,
141143
formId: params.formId,
142144
prevFieldId: prevField.id,
143145
},
@@ -191,6 +193,7 @@ export async function updateField({
191193
fieldValueType: body.fieldValueType,
192194
fieldType: body.fieldType,
193195
validation: body.validation ?? undefined,
196+
options: body.options ?? undefined,
194197
},
195198
});
196199

‎src/types/form-fields.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const createFieldDTO = {
2929
fieldValueType: t.String(),
3030
fieldType: t.String(),
3131
validation: t.Optional(t.Any()),
32+
options: t.Optional(t.Any()),
3233
prevFieldId: t.Optional(
3334
t.String({
3435
format: "uuid",
@@ -54,6 +55,7 @@ export const updateFieldDTO = {
5455
fieldValueType: t.Optional(t.String()),
5556
fieldType: t.Optional(t.String()),
5657
validation: t.Optional(t.Any()),
58+
options: t.Optional(t.Any()),
5759
}),
5860
};
5961

0 commit comments

Comments
 (0)