@mcpher/gas-fakes 1.2.21 → 1.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -69,7 +69,8 @@ export class FakeFormResponse {
|
|
|
69
69
|
}
|
|
70
70
|
// Add the raw answer object from the API response to the item's answer list.
|
|
71
71
|
// This correctly groups all row answers for a grid under the same parent item.
|
|
72
|
-
|
|
72
|
+
// We also attach the questionId to the answer object so we can identify the row later.
|
|
73
|
+
groupedAnswers.get(itemId).answers.push({ ...answer, questionId });
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -40,6 +40,37 @@ export class FakeItemResponse {
|
|
|
40
40
|
* @returns {string} the response
|
|
41
41
|
*/
|
|
42
42
|
getResponse() {
|
|
43
|
+
|
|
44
|
+
const itemType = this.__item.getType().toString();
|
|
45
|
+
if (itemType === 'GRID' || itemType === 'CHECKBOX_GRID') {
|
|
46
|
+
const rows = this.__item.getRows();
|
|
47
|
+
// Initialize with empty string for GRID, empty array for CHECKBOX_GRID
|
|
48
|
+
// This matches Apps Script behavior: String[] for Grid, String[][] for CheckboxGrid
|
|
49
|
+
const rowAnswers = new Array(rows.length).fill(itemType === 'CHECKBOX_GRID' ? [] : '');
|
|
50
|
+
|
|
51
|
+
const questionIdMap = new Map();
|
|
52
|
+
if (this.__item.__resource.questionGroupItem?.questions) {
|
|
53
|
+
this.__item.__resource.questionGroupItem.questions.forEach((q, index) => {
|
|
54
|
+
questionIdMap.set(q.questionId, index);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.__answers.forEach(answer => {
|
|
58
|
+
if (answer.questionId && questionIdMap.has(answer.questionId)) {
|
|
59
|
+
const rowIndex = questionIdMap.get(answer.questionId);
|
|
60
|
+
const values = answer.textAnswers?.answers?.map(a => a.value) || [];
|
|
61
|
+
|
|
62
|
+
if (itemType === 'CHECKBOX_GRID') {
|
|
63
|
+
rowAnswers[rowIndex] = values;
|
|
64
|
+
} else {
|
|
65
|
+
// For GRID, take the first value
|
|
66
|
+
rowAnswers[rowIndex] = values[0] || '';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return rowAnswers;
|
|
72
|
+
}
|
|
73
|
+
|
|
43
74
|
// Flatten the 'textAnswers.answers' arrays from all answer objects.
|
|
44
75
|
// This correctly combines all row answers for a grid item.
|
|
45
76
|
const allTextAnswers = this.__answers.flatMap(
|