|
| 1 | +# ============================================ |
| 2 | +# Phase 2: Form Creation - Form CRUD & Metadata |
| 3 | +# ============================================ |
| 4 | +# This file covers form creation and basic CRUD operations: |
| 5 | +# - Create form |
| 6 | +# - Get form by ID |
| 7 | +# - Update form metadata |
| 8 | +# - List forms |
| 9 | +# - Get available fonts |
| 10 | +# - Upload cover image (optional) |
| 11 | + |
| 12 | +# Import setup from Phase 1 |
| 13 | +# @import ./01-setup.http |
| 14 | + |
| 15 | +### |
| 16 | + |
| 17 | +# ============================================ |
| 18 | +# Get Available Fonts |
| 19 | +# ============================================ |
| 20 | +# @name getFonts |
| 21 | +GET {{BASE_URL}}/forms/fonts |
| 22 | + |
| 23 | +{{ |
| 24 | + test.status(200); |
| 25 | + test.hasResponseBody(); |
| 26 | + |
| 27 | + const { equal } = require('assert'); |
| 28 | + |
| 29 | + test('Fonts array is returned', () => { |
| 30 | + const data = JSON.parse(response.body); |
| 31 | + equal(Array.isArray(data), true, 'Response should be an array'); |
| 32 | + equal(data.length > 0, true, 'Fonts array should not be empty'); |
| 33 | + }); |
| 34 | + |
| 35 | + const data = JSON.parse(response.body); |
| 36 | + exports.firstFontId = data[0].id; |
| 37 | +}} |
| 38 | + |
| 39 | +### |
| 40 | + |
| 41 | +# ============================================ |
| 42 | +# Create Form |
| 43 | +# ============================================ |
| 44 | +# @name createForm |
| 45 | +# @ref addUserToOrg |
| 46 | +POST {{BASE_URL}}/orgs/{{orgSlug}}/forms |
| 47 | +Content-Type: application/json |
| 48 | + |
| 49 | +{ |
| 50 | + "title": "Form Lifecycle Test Form", |
| 51 | + "description": "This is a comprehensive test form covering all question types and form lifecycle operations. It demonstrates form creation, question management, workflow setup, and response handling.", |
| 52 | + "previewMessage": "Complete test form", |
| 53 | + "messageAfterSubmission": "Thank you for completing this test form! Your response has been recorded.", |
| 54 | + "visibility": "PUBLIC" |
| 55 | +} |
| 56 | + |
| 57 | +?? status <= 201 |
| 58 | +{{ |
| 59 | + test.hasResponseBody(); |
| 60 | + |
| 61 | + const { equal } = require('assert'); |
| 62 | + |
| 63 | + test('Form created with correct properties', () => { |
| 64 | + const data = JSON.parse(response.body); |
| 65 | + equal(data.id !== undefined, true, 'Form ID should exist'); |
| 66 | + equal(data.title, 'Form Lifecycle Test Form', 'Form title should match'); |
| 67 | + equal(data.description, 'This is a comprehensive test form covering all question types and form lifecycle operations. It demonstrates form creation, question management, workflow setup, and response handling.', 'Form description should match'); |
| 68 | + equal(data.previewMessage, 'Complete test form', 'Preview message should match'); |
| 69 | + equal(data.messageAfterSubmission, 'Thank you for completing this test form! Your response has been recorded.', 'Message after submission should match'); |
| 70 | + equal(data.visibility, 'PUBLIC', 'Form visibility should be PUBLIC'); |
| 71 | + equal(data.status, 'DRAFT', 'Form status should be DRAFT'); |
| 72 | + equal(data.lastEditor.id, userId, 'Last editor should be the current user'); |
| 73 | + equal(data.unitId, orgId, 'Organization ID should match'); |
| 74 | + }); |
| 75 | + |
| 76 | + const data = JSON.parse(response.body); |
| 77 | + exports.formId = data.id; |
| 78 | +}} |
| 79 | + |
| 80 | +### |
| 81 | + |
| 82 | +# ============================================ |
| 83 | +# Get Form by ID |
| 84 | +# ============================================ |
| 85 | +# @name getForm |
| 86 | +# @ref createForm |
| 87 | +GET {{BASE_URL}}/forms/{{formId}} |
| 88 | + |
| 89 | +{{ |
| 90 | + test.status(200); |
| 91 | + test.hasResponseBody(); |
| 92 | + |
| 93 | + const { equal } = require('assert'); |
| 94 | + |
| 95 | + test('Form retrieved successfully', () => { |
| 96 | + const data = JSON.parse(response.body); |
| 97 | + equal(data.id, formId, 'Form ID should match'); |
| 98 | + equal(data.title, 'Form Lifecycle Test Form', 'Form title should match'); |
| 99 | + equal(data.status, 'DRAFT', 'Form status should be DRAFT'); |
| 100 | + }); |
| 101 | +}} |
| 102 | + |
| 103 | +### |
| 104 | + |
| 105 | +# ============================================ |
| 106 | +# List Forms |
| 107 | +# ============================================ |
| 108 | +# @name listForms |
| 109 | +# @ref getForm |
| 110 | +GET {{BASE_URL}}/forms |
| 111 | + |
| 112 | +{{ |
| 113 | + test.status(200); |
| 114 | + test.hasResponseBody(); |
| 115 | + |
| 116 | + const { equal } = require('assert'); |
| 117 | + |
| 118 | + test('Forms list contains created form', () => { |
| 119 | + const data = JSON.parse(response.body); |
| 120 | + equal(Array.isArray(data), true, 'Response should be an array'); |
| 121 | + equal(data.some(f => f.id === formId), true, 'Created form should be in the list'); |
| 122 | + }); |
| 123 | +}} |
| 124 | + |
| 125 | +### |
| 126 | + |
| 127 | +# ============================================ |
| 128 | +# Update Form - Add Dressing & Metadata |
| 129 | +# ============================================ |
| 130 | +# @name updateForm |
| 131 | +# @ref listForms |
| 132 | +PUT {{BASE_URL}}/forms/{{formId}} |
| 133 | +Content-Type: application/json |
| 134 | + |
| 135 | +{ |
| 136 | + "title": "Form Lifecycle Test Form (Updated)", |
| 137 | + "description": "This is an updated comprehensive test form covering all question types and form lifecycle operations. Updated to test form editing capabilities.", |
| 138 | + "previewMessage": "Updated test form - complete all sections", |
| 139 | + "messageAfterSubmission": "Thank you for your submission! We will review your response shortly.", |
| 140 | + "visibility": "PUBLIC", |
| 141 | + "dressing": { |
| 142 | + "color": "#0066cc", |
| 143 | + "headerFont": "BoutiqueBitmap7x7CircleDot", |
| 144 | + "questionFont": "BoutiqueBitmap7x7SquareDot", |
| 145 | + "textFont": "ChillBitmap16px" |
| 146 | + }, |
| 147 | + "deadline": "2026-12-31T23:59:59Z", |
| 148 | + "publishTime": "2026-02-01T00:00:00Z" |
| 149 | +} |
| 150 | + |
| 151 | +{{ |
| 152 | + test.status(200); |
| 153 | + test.hasResponseBody(); |
| 154 | + |
| 155 | + const { equal } = require('assert'); |
| 156 | + |
| 157 | + test('Form updated with correct properties', () => { |
| 158 | + const data = JSON.parse(response.body); |
| 159 | + equal(data.title, 'Form Lifecycle Test Form (Updated)', 'Form title should be updated'); |
| 160 | + equal(data.dressing !== undefined, true, 'Dressing should exist'); |
| 161 | + equal(data.dressing.color, '#0066cc', 'Dressing color should match'); |
| 162 | + equal(data.dressing.headerFont, 'BoutiqueBitmap7x7CircleDot', 'Dressing header font should match'); |
| 163 | + equal(data.dressing.questionFont, 'BoutiqueBitmap7x7SquareDot', 'Dressing question font should match'); |
| 164 | + equal(data.dressing.textFont, 'ChillBitmap16px', 'Dressing text font should match'); |
| 165 | + equal(data.deadline !== null, true, 'Deadline should be set'); |
| 166 | + equal(data.publishTime !== null, true, 'Publish time should be set'); |
| 167 | + }); |
| 168 | +}} |
| 169 | + |
| 170 | +### |
| 171 | + |
| 172 | +# ============================================ |
| 173 | +# Get Updated Form |
| 174 | +# ============================================ |
| 175 | +# @name getUpdatedForm |
| 176 | +# @ref updateForm |
| 177 | +GET {{BASE_URL}}/forms/{{formId}} |
| 178 | + |
| 179 | +{{ |
| 180 | + test.status(200); |
| 181 | + test.hasResponseBody(); |
| 182 | + |
| 183 | + const { equal } = require('assert'); |
| 184 | + |
| 185 | + test('Form update persisted', () => { |
| 186 | + const data = JSON.parse(response.body); |
| 187 | + equal(data.title, 'Form Lifecycle Test Form (Updated)', 'Updated title should persist'); |
| 188 | + equal(data.dressing.color, '#0066cc', 'Dressing color should persist'); |
| 189 | + equal(data.dressing.headerFont, 'BoutiqueBitmap7x7CircleDot', 'Dressing header font should persist'); |
| 190 | + equal(data.dressing.questionFont, 'BoutiqueBitmap7x7SquareDot', 'Dressing question font should persist'); |
| 191 | + equal(data.dressing.textFont, 'ChillBitmap16px', 'Dressing text font should persist'); |
| 192 | + }); |
| 193 | +}} |
| 194 | + |
| 195 | +### |
| 196 | + |
| 197 | +# ============================================ |
| 198 | +# List Forms by Organization |
| 199 | +# ============================================ |
| 200 | +# @name listFormsByOrg |
| 201 | +# @ref getUpdatedForm |
| 202 | +GET {{BASE_URL}}/orgs/{{orgSlug}}/forms |
| 203 | + |
| 204 | +{{ |
| 205 | + test.status(200); |
| 206 | + test.hasResponseBody(); |
| 207 | + |
| 208 | + const { equal } = require('assert'); |
| 209 | + |
| 210 | + test('Organization forms list contains created form', () => { |
| 211 | + const data = JSON.parse(response.body); |
| 212 | + equal(Array.isArray(data), true, 'Response should be an array'); |
| 213 | + equal(data.some(f => f.id === formId), true, 'Created form should be in organization forms list'); |
| 214 | + }); |
| 215 | +}} |
0 commit comments