• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ringcentral / google-forms-notification-add-in / 3653923233

pending completion
3653923233

Pull #35

github

GitHub
Merge 2acefbbc1 into c672dffc8
Pull Request #35: chore(deps): bump ansi-regex from 3.0.0 to 5.0.1

223 of 239 branches covered (93.31%)

Branch coverage included in aggregate %.

641 of 652 relevant lines covered (98.31%)

14.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/server/lib/formatGoogleFormResponse.js
1
const { Template } = require('adaptivecards-templating');
4✔
2
const responseTemplate = require('../adaptiveCardPayloads/response.json');
4✔
3
const { findItemInAdaptiveCard } = require('./findItemInAdaptiveCard');
4✔
4

5
function getAnswerFromResponse(response, questionId) {
6
  return response.answers[questionId] &&
85✔
7
    response.answers[questionId].textAnswers &&
8
    response.answers[questionId].textAnswers.answers.map(value => value.value).join(', ');
60✔
9
}
10

11
function getAnswers(form, response) {
12
  const answers = [];
8✔
13
  form.items.forEach((item) => {
8✔
14
    if (item.questionItem) {
80✔
15
      const question = item.questionItem.question;
71✔
16
      const answer = getAnswerFromResponse(response, question.questionId);
71✔
17
      if (answer) {
71✔
18
        let answerDescription = '';
46✔
19
        if (question.scaleQuestion) {
46✔
20
          answerDescription = `"${question.scaleQuestion.low} = ${question.scaleQuestion.lowLabel}  ${question.scaleQuestion.high} = ${question.scaleQuestion.highLabel}": `;
3✔
21
        }
22
        answers.push({
46✔
23
          type: 'Container',
24
          items: [
25
            {
26
              type: 'TextBlock',
27
              text: item.title,
28
              wrap: true,
29
              weight: 'Bolder',
30
            },
31
            {
32
              type: 'TextBlock',
33
              wrap: true,
34
              text: `${answerDescription}${answer}`,
35
            },
36
          ]
37
        });
38
      }
39
    }
40
    if (item.questionGroupItem && item.questionGroupItem.questions) {
80✔
41
      const columns = [];
2✔
42
      item.questionGroupItem.questions.forEach((question) => {
2✔
43
        const answer = getAnswerFromResponse(response, question.questionId);
14✔
44
        if (answer) {
14!
45
          columns.push({
14✔
46
            type: 'ColumnSet',
47
            columns: [
48
              {
49
                type: 'Column',
50
                items: [
51
                  {
52
                    type: 'TextBlock',
53
                    text: `${question.rowQuestion.title}:`
54
                  }
55
                ],
56
                width: 'stretch',
57
              },
58
              {
59
                type: 'Column',
60
                items: [
61
                  {
62
                    type: 'TextBlock',
63
                    text: answer,
64
                    wrap: true,
65
                    weight: 'Bolder'
66
                  }
67
                ],
68
                width: 'stretch',
69
              },
70
            ],
71
          });
72
        }
73
      });
74
      if (columns.length > 0) {
2!
75
        const container = {
2✔
76
          type: 'Container',
77
          items: [
78
            {
79
              type: 'TextBlock',
80
              text: item.title,
81
              wrap: true,
82
              weight: 'Bolder',
83
            },
84
          ],
85
        };
86
        if (item.description) {
2✔
87
          container.items.push({
1✔
88
            type: 'TextBlock',
89
            text: item.description,
90
            wrap: true,
91
            size: 'Small',
92
            isSubtle: true,
93
          });
94
        }
95
        container.items = container.items.concat(columns);
2✔
96
        answers.push(container);
2✔
97
      }
98
    }
99
  });
100
  return answers;
8✔
101
}
102

103
function formatGoogleFormResponseIntoCard(form, response) {
104
  const formUrl = `https://docs.google.com/forms/d/${form.formId}/edit`;
8✔
105
  const allAnswers = getAnswers(form, response);
8✔
106
  const answers = allAnswers.slice(0, 5);
8✔
107
  const moreAnswers = allAnswers.length > 5 ? allAnswers.slice(5) : [];
8!
108
  const template = new Template(responseTemplate);
8✔
109
  const card = template.expand({
8✔
110
    $root: {
111
      formId: form.formId,
112
      formTitle: form.info.title || form.info.documentTitle,
9✔
113
      formUrl,
114
      responseId: response.id,
115
      responseUrl: `${formUrl}#response=${response.responseId}`,
116
    },
117
  });
118
  const answersItem = findItemInAdaptiveCard(card, 'answers');
8✔
119
  answersItem.items = answers;
8✔
120
  if (moreAnswers.length > 0) {
8!
121
    const moreAnswersItem = findItemInAdaptiveCard(card, 'moreAnswers');
8✔
122
    const moreAnswerButton = findItemInAdaptiveCard(card, 'shoreMoreButtons');
8✔
123
    moreAnswersItem.items = moreAnswers;
8✔
124
    delete moreAnswerButton.isVisible;
8✔
125
  }
126
  return card;
8✔
127
}
128

129
exports.formatGoogleFormResponseIntoCard = formatGoogleFormResponseIntoCard;
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc