-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path05-form-publishing.http
More file actions
294 lines (229 loc) · 9.53 KB
/
Copy path05-form-publishing.http
File metadata and controls
294 lines (229 loc) · 9.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# ============================================
# Phase 5: Form Publishing
# ============================================
# This file tests the form publishing lifecycle:
# - Verify form status before publishing (should be DRAFT)
# - Publish the form (status changes from DRAFT to PUBLISHED)
# - Verify form is published and accessible
# - Test that published form appears in listing
# Import setup from Phase 4
# @import ./04-question-management.http
###
# ============================================
# Get Form Status Before Publishing
# ============================================
# @name getFormBeforePublish
# @ref verifyQuestionDeletion
GET {{BASE_URL}}/forms/{{formId}}
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Form is in DRAFT status before publishing', () => {
const data = JSON.parse(response.body);
equal(data.id, formId, 'Form ID should match');
equal(data.status, 'DRAFT', 'Status should be DRAFT before publishing');
equal(data.title, 'Form Lifecycle Test Form (Updated)', 'Title should match');
console.log('Form ID:', data.id);
console.log('Status:', data.status);
console.log('Title:', data.title);
console.log('Visibility:', data.visibility);
});
}}
###
# ============================================
# Verify Workflow is Valid Before Publishing
# ============================================
# @name verifyWorkflowBeforePublish
# @ref getFormBeforePublish
GET {{BASE_URL}}/forms/{{formId}}/workflow
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Workflow is valid before publishing', () => {
const data = JSON.parse(response.body);
equal(Array.isArray(data.workflow), true, 'Workflow should be an array');
equal(data.workflow.length, 3, 'Workflow should have 3 nodes (START, Section, END)');
equal(Array.isArray(data.info), true, 'Info should be an array');
equal(data.info.length, 0, 'There should be no validation errors');
console.log('Workflow is valid and ready for publishing');
});
}}
###
# ============================================
# Verify Questions Exist Before Publishing
# ============================================
# @name verifyQuestionsBeforePublish
# @ref verifyWorkflowBeforePublish
GET {{BASE_URL}}/forms/{{formId}}/sections
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Form has questions before publishing', () => {
const data = JSON.parse(response.body);
equal(Array.isArray(data), true, 'Response should be an array');
// Find our section
const ourSection = data.find(s => s.section.id === defaultSectionId);
equal(ourSection !== undefined, true, 'Our section should exist');
equal(Array.isArray(ourSection.questions), true, 'Questions should be an array');
equal(ourSection.questions.length >= 1, true, 'Should have at least 1 question');
console.log('Form has', ourSection.questions.length, 'questions ready for publishing');
});
}}
###
# ============================================
# Publish Form
# ============================================
# @name publishForm
# @ref verifyQuestionsBeforePublish
POST {{BASE_URL}}/forms/{{formId}}/publish
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Form published successfully', () => {
const data = JSON.parse(response.body);
equal(data.visibility !== undefined, true, 'Response should contain visibility');
equal(typeof data.visibility, 'string', 'Visibility should be a string');
console.log('Form visibility:', data.visibility);
});
const data = JSON.parse(response.body);
exports.formVisibility = data.visibility;
}}
###
# ============================================
# Get Form After Publishing
# ============================================
# @name getFormAfterPublish
# @ref publishForm
GET {{BASE_URL}}/forms/{{formId}}
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Form status changed to PUBLISHED', () => {
const data = JSON.parse(response.body);
equal(data.id, formId, 'Form ID should match');
equal(data.status, 'PUBLISHED', 'Status should be PUBLISHED after publishing');
equal(data.visibility, formVisibility, 'Visibility should match');
console.log('Form ID:', data.id);
console.log('Status:', data.status);
console.log('Title:', data.title);
console.log('Form visibility:', data.visibility);
console.log('Publish Time:', data.publishTime);
console.log('Deadline:', data.deadline);
});
}}
###
# ============================================
# Verify Published Form Appears in User Form List (GET /forms/me)
# ============================================
# @name verifyFormInUserListing
# @ref getFormAfterPublish
GET {{BASE_URL}}/forms/me
?? status == 200
{{
test.hasResponseBody();
const { equal } = require('assert');
const data = JSON.parse(response.body);
test('Published form with a future deadline appears in GET /forms/me', () => {
equal(Array.isArray(data), true, 'Response must be a bare array');
const row = data.find((r) => r.id === formId);
equal(row !== undefined, true, 'Published form should appear in user form list');
equal(row.deadline !== undefined && row.deadline !== null, true, 'Lifecycle form should have a deadline');
equal(Array.isArray(row.responseIds), true, 'responseIds must always be an array');
});
}}
###
# ============================================
# Verify Published Form Appears in Listing
# ============================================
# @name verifyFormInListing
# @ref verifyFormInUserListing
GET {{BASE_URL}}/forms
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Published form appears in forms listing', () => {
const data = JSON.parse(response.body);
equal(Array.isArray(data), true, 'Response should be an array');
// Find our published form
const publishedForm = data.find(f => f.id === formId);
equal(publishedForm !== undefined, true, 'Published form should appear in listing');
equal(publishedForm.status, 'PUBLISHED', 'Form status should be PUBLISHED in listing');
console.log('Published form found in listing with status:', publishedForm.status);
});
}}
###
# ============================================
# Verify Published Form in Default View of Organization Listing
# ============================================
# @name verifyFormInOrgListing
# @ref verifyFormInListing
GET {{BASE_URL}}/orgs/{{orgSlug}}/forms
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Published form appears in organization forms listing', () => {
const data = JSON.parse(response.body);
equal(Array.isArray(data), true, 'Response should be an array');
// Find our published form
const publishedForm = data.find(f => f.id === formId);
equal(publishedForm !== undefined, true, 'Published form should appear in org listing');
equal(publishedForm.status, 'PUBLISHED', 'Form status should be PUBLISHED in org listing');
console.log('Published form found in organization listing');
});
}}
###
# ============================================
# Try Publishing Again (Should Be Idempotent or Return Error)
# ============================================
# @name publishFormAgain
# @ref verifyFormInOrgListing
POST {{BASE_URL}}/forms/{{formId}}/publish
{{
// Publishing an already published form should either:
// 1. Return 200 with same visibility (idempotent)
// 2. Return 4xx error indicating form is already published
const statusCode = response.statusCode;
const isSuccess = statusCode === 200;
const isClientError = statusCode >= 400 && statusCode < 500;
const { equal } = require('assert');
test('Publishing again returns expected response', () => {
const data = JSON.parse(response.body);
equal(data.title, 'Validation Problem', 'Response should indicate validation problem');
});
}}
###
# ============================================
# Get Form Final State
# ============================================
# @name getFormFinalState
# @ref publishFormAgain
GET {{BASE_URL}}/forms/{{formId}}
{{
test.status(200);
test.hasResponseBody();
const { equal } = require('assert');
test('Form remains in PUBLISHED state', () => {
const data = JSON.parse(response.body);
equal(data.id, formId, 'Form ID should match');
equal(data.status, 'PUBLISHED', 'Status should remain PUBLISHED');
console.log('Form ID:', data.id);
console.log('Status:', data.status);
console.log('Title:', data.title);
console.log('Description (ProseMirror doc):', data.description?.type);
console.log('Description HTML:', data.descriptionHtml);
console.log('Form visibility:', data.visibility);
console.log('Publish Time:', data.publishTime);
console.log('Deadline:', data.deadline);
console.log('Cover Image:', data.coverImage || '(none)');
console.log('Google Sheet URL:', data.googleSheetUrl || '(none)');
console.log('Created At:', data.createdAt);
console.log('Updated At:', data.updatedAt);
});
}}