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

hicommonwealth / commonwealth / 15936026264

27 Jun 2025 09:10PM UTC coverage: 39.947% (-0.1%) from 40.058%
15936026264

Pull #12505

github

web-flow
Merge 625dbe137 into f644f13e6
Pull Request #12505: Contests/Voting e2e test

1844 of 5005 branches covered (36.84%)

Branch coverage included in aggregate %.

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

168 existing lines in 10 files now uncovered.

3280 of 7822 relevant lines covered (41.93%)

37.06 hits per line

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

0.0
/libs/model/src/aggregates/thread/GetThreadById.query.ts
1
import { InvalidState, Query } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { QueryTypes } from 'sequelize';
4
import { z } from 'zod';
5
import { models, sequelize } from '../../database';
6
import { authOptionalForThread, UnauthorizedView } from '../../middleware';
7
import { filterGates, joinGates, withGates } from '../../utils/gating';
8

9
export function GetThreadById(): Query<typeof schemas.GetThreadById> {
10
  return {
×
11
    ...schemas.GetThreadById,
12
    auth: [authOptionalForThread],
13
    secure: true,
14
    body: async ({ actor, payload, context }) => {
15
      const { thread_id } = payload;
×
16

17
      // find open gates in thread's community
UNCOV
18
      const [open_thread] = await sequelize.query<{
×
19
        id: number;
20
      }>(
21
        `
22
        ${withGates(actor)}
23
        SELECT T.id
24
        FROM
25
          "Threads" T
26
          ${joinGates(actor)}
27
        WHERE
28
          T.id = :thread_id
29
          ${filterGates(actor)}
30
        `,
31
        {
32
          type: QueryTypes.SELECT,
33
          replacements: {
34
            address_id: actor.address_id,
35
            community_id: context?.community_id,
36
            thread_id,
37
          },
38
        },
39
      );
UNCOV
40
      if (!open_thread) throw new UnauthorizedView(actor);
×
41

42
      // TODO: refactor using plain sql and add gating filters
UNCOV
43
      const thread = await models.Thread.findOne({
×
44
        where: { id: thread_id },
45
        include: [
46
          {
47
            model: models.Address,
48
            as: 'Address',
49
            include: [
50
              {
51
                model: models.User,
52
                as: 'User',
53
                required: true,
54
                attributes: ['id', 'profile', 'tier'],
55
              },
56
            ],
57
          },
58
          {
59
            model: models.Address,
60
            as: 'collaborators',
61
            include: [
62
              {
63
                model: models.User,
64
                as: 'User',
65
                required: true,
66
                attributes: ['id', 'profile', 'tier'],
67
              },
68
            ],
69
          },
70
          {
71
            model: models.Topic,
72
            as: 'topic',
73
            required: true,
74
          },
75
          {
76
            model: models.Reaction,
77
            as: 'reactions',
78
            include: [
79
              {
80
                model: models.Address,
81
                as: 'Address',
82
                required: true,
83
                include: [
84
                  {
85
                    model: models.User,
86
                    as: 'User',
87
                    required: true,
88
                    attributes: ['id', 'profile', 'tier'],
89
                  },
90
                ],
91
              },
92
            ],
93
          },
94
          {
95
            model: models.ContestAction,
96
            where: { action: 'upvoted' },
97
            required: false,
98
            attributes: ['content_id', 'thread_id'],
99
            include: [
100
              {
101
                model: models.Contest,
102
                on: {
103
                  contest_id: sequelize.where(
104
                    sequelize.col('"ContestActions".contest_id'),
105
                    '=',
106
                    sequelize.col('"ContestActions->Contest".contest_id'),
107
                  ),
108
                  contest_address: sequelize.where(
109
                    sequelize.col('"ContestActions".contest_address'),
110
                    '=',
111
                    sequelize.col('"ContestActions->Contest".contest_address'),
112
                  ),
113
                },
114
                attributes: [
115
                  'contest_id',
116
                  'contest_address',
117
                  'score',
118
                  'start_time',
119
                  'end_time',
120
                ],
121
                include: [
122
                  {
123
                    model: models.ContestManager,
124
                    attributes: ['name', 'cancelled', 'interval'],
125
                  },
126
                ],
127
              },
128
            ],
129
          },
130
          { model: models.ThreadVersionHistory },
131
        ],
132
      });
133

UNCOV
134
      if (!thread) {
×
135
        throw new InvalidState('Thread not found');
×
136
      }
137

UNCOV
138
      return thread!.toJSON() as z.infer<typeof schemas.ThreadView>;
×
139
    },
140
  };
141
}
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