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

hicommonwealth / commonwealth / 16150748756

08 Jul 2025 05:57PM UTC coverage: 40.016%. Remained the same
16150748756

push

github

web-flow
Merge pull request #12586 from hicommonwealth/rotorsoft/refactor-libs-models-exports

Rotorsoft/refactor libs models exports

1857 of 5027 branches covered (36.94%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

104 existing lines in 10 files now uncovered.

3293 of 7843 relevant lines covered (41.99%)

36.82 hits per line

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

6.52
/libs/model/src/aggregates/contest/UpdateContestManagerFrameHashes.command.ts
1
import { Command, logger } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { NeynarAPIClient } from '@neynar/nodejs-sdk';
4
import { Mutex } from 'async-mutex';
5
import _ from 'lodash';
6
import { Op } from 'sequelize';
7
import { config } from '../../config';
8
import { models } from '../../database';
9
import { mustExist } from '../../middleware/guards';
10

11
const log = logger(import.meta);
31✔
12

13
const Errors = {
31✔
14
  ContestEnded: 'Contest has ended',
15
};
16

17
const neynarMutex = new Mutex();
31✔
18

19
export function UpdateContestManagerFrameHashes(): Command<
20
  typeof schemas.UpdateContestManagerFrameHashes
21
> {
UNCOV
22
  return {
×
23
    ...schemas.UpdateContestManagerFrameHashes,
24
    auth: [],
25
    body: async ({ payload }) => {
UNCOV
26
      await neynarMutex.runExclusive(async () => {
×
27
        const contestManager = await models.ContestManager.findOne({
×
28
          where: {
29
            contest_address: payload.contest_address,
30
            cancelled: {
31
              [Op.not]: true,
32
            },
33
            ended: {
34
              [Op.not]: true,
35
            },
36
          },
37
          include: [
38
            {
39
              model: models.Contest,
40
              as: 'contests',
41
              required: true,
42
            },
43
          ],
44
        });
UNCOV
45
        mustExist('Contest Manager', contestManager);
×
46
        if (new Date() > contestManager.contests![0]!.end_time) {
×
47
          log.warn(`${Errors.ContestEnded}: ${contestManager.contest_address}`);
×
48
          return {};
×
49
        }
50

51
        // find webhook by ID
UNCOV
52
        const client = new NeynarAPIClient(config.CONTESTS.NEYNAR_API_KEY!);
×
53
        const { webhook: existingCastWebhook } = await client.lookupWebhook(
×
54
          config.CONTESTS.NEYNAR_CAST_WEBHOOK_ID!,
55
        );
UNCOV
56
        mustExist('Neynar Webhook', existingCastWebhook);
×
57

58
        // remove and add hashes to subscription
UNCOV
59
        const allParentHashes = _.uniq([
×
60
          ...(existingCastWebhook?.subscription?.filters['cast.created']
×
61
            ?.parent_hashes || []),
62
          ...(existingCastWebhook?.subscription?.filters['cast.deleted']
×
63
            ?.parent_hashes || []),
64
        ])
65
          .filter((hash) => {
UNCOV
66
            return !(payload.frames_to_remove || []).includes(hash);
×
67
          })
68
          .concat(payload.frames_to_add || []);
×
69

UNCOV
70
        const subscription = {
×
71
          ...(existingCastWebhook.subscription?.filters || {}),
×
72
          // reply cast created on parent
73
          'cast.created': {
74
            ...(existingCastWebhook.subscription?.filters['cast.created'] ||
×
75
              {}),
76
            parent_hashes: allParentHashes,
77
          },
78
          // reply cast deleted on parent
79
          'cast.deleted': {
80
            ...(existingCastWebhook.subscription?.filters['cast.deleted'] ||
×
81
              {}),
82
            parent_hashes: allParentHashes,
83
          },
84
        };
85

UNCOV
86
        await client.updateWebhook(
×
87
          existingCastWebhook.webhook_id,
88
          existingCastWebhook.title,
89
          existingCastWebhook.target_url,
90
          {
91
            subscription,
92
          },
93
        );
94

UNCOV
95
        if (!payload.webhooks_only) {
×
96
          // update contest manager frame hashes
UNCOV
97
          contestManager.farcaster_frame_hashes = (
×
98
            contestManager.farcaster_frame_hashes || []
×
99
          )
100
            .filter((hash) => {
UNCOV
101
              return !(payload.frames_to_remove || []).includes(hash);
×
102
            })
103
            .concat(payload.frames_to_add || []);
×
UNCOV
104
          await contestManager.save();
×
105
        }
106
      });
107

UNCOV
108
      return {};
×
109
    },
110
  };
111
}
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

© 2026 Coveralls, Inc