Skip to content

Commit 1512521

Browse files
committed
test(types): call the mothership events route with its context, type the acceptance transaction mock, and shrink the test-types baseline
1 parent 0cdca5a commit 1512521

3 files changed

Lines changed: 14 additions & 23 deletions

File tree

‎apps/sim/app/api/mothership/events/route.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ vi.mock('@/lib/mothership/chat/organization-chats', () => mothershipOrganization
2727
vi.mock('@/lib/mothership/chat-status', () => mothershipChatStatusMock)
2828
vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock)
2929

30-
import { GET } from '@/app/api/mothership/events/route'
30+
import { GET as routeGET } from '@/app/api/mothership/events/route'
3131

32+
const GET = (req: NextRequest) => routeGET(req, { params: Promise.resolve({}) })
3233
const authorize = mothershipOrganizationChatsMockFns.mockAuthorizeOrganizationChatEvents
3334
const subscribe = mothershipChatStatusMockFns.mockOnStatusChanged
3435

‎apps/sim/lib/billing/organization.test.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '@sim/testing/mocks/organization-membership.mock'
2525
import { schemaMock } from '@sim/testing/mocks/schema.mock'
2626
import { beforeEach, describe, expect, it, vi } from 'vitest'
27+
import type { DbTransaction } from '@/lib/db/types'
2728

2829
const {
2930
mockCreateOrganizationWithOwner,
@@ -77,6 +78,8 @@ const { mockAcquireOrganizationMutationLock } = organizationMembershipMockFns
7778
const { mockAcquireUserBillingIdentityLock } = billingIdentityLockMockFns
7879
const BILLING_WEBHOOK = { type: 'system', name: 'Billing System' } as const
7980
const ACCEPTOR = { type: 'user', userId: 'acceptor-1' } as const
81+
/** The chain mock standing in for the acceptance transaction the Tx variant runs on. */
82+
const ACCEPTANCE_TX = dbChainMock.db as unknown as DbTransaction
8083
billingPlanHelpersMockFns.mockIsPaid.mockImplementation((plan) => plan !== 'free')
8184

8285
function queueWhereResponses(responses: unknown[][]) {
@@ -175,7 +178,7 @@ describe('ensureOrganizationForTeamSubscription', () => {
175178
mockAttachOwnedWorkspacesToOrganizationTx.mockResolvedValueOnce({ usageLimitUserIds: [] })
176179

177180
await ensureOrganizationForTeamSubscriptionTx(
178-
dbChainMock.db,
181+
ACCEPTANCE_TX,
179182
{
180183
id: 'sub-1',
181184
plan: 'team',
@@ -204,7 +207,7 @@ describe('ensureOrganizationForTeamSubscription', () => {
204207

205208
await expect(
206209
ensureOrganizationForTeamSubscriptionTx(
207-
dbChainMock.db,
210+
ACCEPTANCE_TX,
208211
{
209212
id: 'sub-1',
210213
plan: 'team',
@@ -267,16 +270,13 @@ describe('syncSubscriptionUsageLimits', () => {
267270
mockGetOrganizationIdForSubscriptionReference.mockResolvedValue('org-1')
268271
mockGetPlanPricing.mockReturnValue({ basePrice: 25 })
269272

270-
await syncSubscriptionUsageLimits(
271-
{
272-
id: 'sub-1',
273-
plan: 'team_6000',
274-
referenceId: 'org-1',
275-
status: 'active',
276-
seats: 2,
277-
},
278-
BILLING_WEBHOOK
279-
)
273+
await syncSubscriptionUsageLimits({
274+
id: 'sub-1',
275+
plan: 'team_6000',
276+
referenceId: 'org-1',
277+
status: 'active',
278+
seats: 2,
279+
})
280280

281281
const update = dbChainMockFns.set.mock.calls[0]?.[0]
282282
const expression = JSON.stringify(update?.orgUsageLimit)

‎scripts/check-test-types.baseline.json‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,10 @@
231231
"apps/sim/app/api/mothership/chats/read/route.test.ts": {
232232
"TS2554": 3
233233
},
234-
"apps/sim/app/api/mothership/events/route.test.ts": {
235-
"TS2554": 10
236-
},
237234
"apps/sim/app/api/organizations/[id]/permission-groups/[groupId]/route.test.ts": {
238235
"TS2550": 2
239236
},
240237
"apps/sim/app/api/organizations/route.test.ts": {
241-
"TS2554": 3,
242238
"TS2769": 1
243239
},
244240
"apps/sim/app/api/pinned-items/route.test.ts": {
@@ -458,9 +454,6 @@
458454
"TS2322": 1,
459455
"TS2554": 1
460456
},
461-
"apps/sim/app/api/workspaces/route.test.ts": {
462-
"TS2554": 2
463-
},
464457
"apps/sim/background/async-execution-correlation.test.ts": {
465458
"TS2345": 2
466459
},
@@ -966,9 +959,6 @@
966959
"TS2345": 2,
967960
"TS2739": 16
968961
},
969-
"apps/sim/lib/billing/organization.test.ts": {
970-
"TS2345": 1
971-
},
972962
"apps/sim/lib/billing/organizations/lock-order.test.ts": {
973963
"TS2345": 2,
974964
"TS2352": 1,

0 commit comments

Comments
 (0)