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

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

17 Jan 2024 05:42AM UTC coverage: 96.97%. Remained the same
7551583681

Pull #35

github

web-flow
chore(deps): bump ansi-regex from 3.0.0 to 5.0.1

Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 3.0.0 to 5.0.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](https://github.com/chalk/ansi-regex/compare/v3.0.0...v5.0.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #35: chore(deps): bump ansi-regex from 3.0.0 to 5.0.1

223 of 239 branches covered (0.0%)

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

97.56
/src/server/handlers/authorizationHandler.js
1
const { User } = require('../models/userModel');
4✔
2
const { Subscription } = require('../models/subscriptionModel');
4✔
3
const { GoogleClient } = require('../lib/GoogleClient');
4✔
4

5
async function onAuthorize(accessToken, refreshToken, expires) {
6
  const googleClient = new GoogleClient({ token: accessToken });
3✔
7
  const userInfoResponse = await googleClient.getUserInfo();
3✔
8
  const userId = userInfoResponse.sub;
3✔
9

10
  let user = await User.findByPk(userId);
3✔
11
  if (!user) {
3✔
12
    user = await User.create({
1✔
13
      id: userId,
14
      accessToken: accessToken,
15
      refreshToken: refreshToken,
16
      tokenExpiredAt: expires,
17
      name: userInfoResponse.name,
18
      subscriptions: [],
19
    });
20
  }
21
  else {
22
    user.accessToken = accessToken;
2✔
23
    if (refreshToken) {
2✔
24
      user.refreshToken = refreshToken;
1✔
25
    }
26
    user.tokenExpiredAt = expires;
2✔
27
    await user.save();
2✔
28
  }
29

30
  return userId;
3✔
31
}
32

33
function getUniqueSubscriptions(subscriptions) {
34
  const data = {};
6✔
35
  subscriptions.forEach((subscription) => {
6✔
36
    data[subscription.id] = subscription;
4✔
37
  });
38
  return Object.keys(data).map((key) => data[key]);
6✔
39
}
40

41
async function onUnauthorize(user) {
42
  const googleClient = new GoogleClient({ token: user.accessToken });
6✔
43
  const subscriptions = user.subscriptions;
6✔
44
  const uniqueSubscriptions = getUniqueSubscriptions(subscriptions);
6✔
45
  await Promise.all(uniqueSubscriptions.map(async (subscription) => {
6✔
46
    try {
3✔
47
      await googleClient.deleteWatch(subscription.formId, subscription.id);
3✔
48
      await Subscription.destroy({ where: { id: subscription.id } });
2✔
49
    } catch (e) {
50
      console.error('Failed to delete watch: ', subscription.id);
1✔
51
      console.error(e);
1✔
52
    }
53
  }));
54
  await googleClient.revokeToken(user.refreshToken || user.accessToken);
6!
55
  user.accessToken = '';
5✔
56
  user.refreshToken = '';
5✔
57
  user.subscriptions = [];
5✔
58
  await user.save();
5✔
59
}
60

61
exports.onAuthorize = onAuthorize;
4✔
62
exports.onUnauthorize = onUnauthorize;
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