Skip to content

Commit 1152a26

Browse files
authored
fix(subscriptions): fixed organization creation failure introduced by subscription updates (#361)
* fix(subscriptions): fixed organization creation failure introduced by subscription updates * cleaned up tests * run format
1 parent 274ebdf commit 1152a26

File tree

44 files changed

+1679
-992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1679
-992
lines changed

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ coverage
3434
**/public/sw.js
3535
**/public/workbox-*.js
3636
**/public/worker-*.js
37-
**/public/fallback-*.js
37+
**/public/fallback-*.js
38+
39+
# Documentation
40+
apps/docs/**/*.mdx

apps/docs/content/docs/tools/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
"x",
4646
"youtube"
4747
]
48-
}
48+
}

apps/sim/app/(auth)/verify/use-verification.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@ export function useVerification({
5757
if (storedEmail) {
5858
setEmail(storedEmail)
5959
}
60-
60+
6161
// Check for redirect information
6262
const storedRedirectUrl = sessionStorage.getItem('inviteRedirectUrl')
6363
if (storedRedirectUrl) {
6464
setRedirectUrl(storedRedirectUrl)
6565
}
66-
66+
6767
// Check if this is an invite flow
6868
const storedIsInviteFlow = sessionStorage.getItem('isInviteFlow')
6969
if (storedIsInviteFlow === 'true') {
7070
setIsInviteFlow(true)
7171
}
7272
}
73-
73+
7474
// Also check URL parameters for redirect information
7575
const redirectParam = searchParams.get('redirectAfter')
7676
if (redirectParam) {
7777
setRedirectUrl(redirectParam)
7878
}
79-
79+
8080
// Check for invite_flow parameter
8181
const inviteFlowParam = searchParams.get('invite_flow')
8282
if (inviteFlowParam === 'true') {
@@ -130,7 +130,7 @@ export function useVerification({
130130
// Clear email from sessionStorage after successful verification
131131
if (typeof window !== 'undefined') {
132132
sessionStorage.removeItem('verificationEmail')
133-
133+
134134
// Also clear invite-related items
135135
if (isInviteFlow) {
136136
sessionStorage.removeItem('inviteRedirectUrl')

apps/sim/app/api/__test-utils__/utils.ts

Lines changed: 88 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { vi } from 'vitest'
22
import { NextRequest } from 'next/server'
33

4-
/**
5-
* Mock sample workflow state for testing
6-
*/
74
export const sampleWorkflowState = {
85
blocks: {
96
'starter-id': {
@@ -65,51 +62,108 @@ export const sampleWorkflowState = {
6562
isDeployed: false,
6663
}
6764

68-
/**
69-
* Mock database with test data
70-
*/
71-
export function mockDb() {
72-
return {
73-
select: vi.fn().mockImplementation(() => ({
74-
from: vi.fn().mockImplementation(() => ({
75-
where: vi.fn().mockImplementation(() => ({
76-
limit: vi.fn().mockImplementation(() => [
77-
{
78-
id: 'workflow-id',
79-
userId: 'user-id',
80-
state: sampleWorkflowState,
81-
},
82-
]),
83-
})),
65+
export const mockDb = {
66+
select: vi.fn().mockImplementation(() => ({
67+
from: vi.fn().mockImplementation(() => ({
68+
where: vi.fn().mockImplementation(() => ({
69+
limit: vi.fn().mockImplementation(() => [
70+
{
71+
id: 'workflow-id',
72+
userId: 'user-id',
73+
state: sampleWorkflowState,
74+
},
75+
]),
8476
})),
8577
})),
86-
update: vi.fn().mockImplementation(() => ({
87-
set: vi.fn().mockImplementation(() => ({
88-
where: vi.fn().mockResolvedValue([]),
89-
})),
78+
})),
79+
update: vi.fn().mockImplementation(() => ({
80+
set: vi.fn().mockImplementation(() => ({
81+
where: vi.fn().mockResolvedValue([]),
9082
})),
91-
}
83+
})),
84+
eq: vi.fn().mockImplementation((field, value) => ({ field, value, type: 'eq' })),
85+
and: vi.fn().mockImplementation((...conditions) => ({
86+
conditions,
87+
type: 'and',
88+
})),
89+
}
90+
91+
export const mockLogger = {
92+
info: vi.fn(),
93+
warn: vi.fn(),
94+
error: vi.fn(),
95+
debug: vi.fn(),
96+
}
97+
98+
export const mockUser = {
99+
id: 'user-123',
100+
email: 'test@example.com',
101+
}
102+
103+
export const mockSubscription = {
104+
id: 'sub-123',
105+
plan: 'enterprise',
106+
status: 'active',
107+
seats: 5,
108+
referenceId: 'user-123',
109+
metadata: {
110+
perSeatAllowance: 100,
111+
totalAllowance: 500,
112+
updatedAt: '2023-01-01T00:00:00.000Z',
113+
},
114+
}
115+
116+
export const mockOrganization = {
117+
id: 'org-456',
118+
name: 'Test Organization',
119+
slug: 'test-org',
120+
}
121+
122+
export const mockAdminMember = {
123+
id: 'member-123',
124+
userId: 'user-123',
125+
organizationId: 'org-456',
126+
role: 'admin',
127+
}
128+
129+
export const mockRegularMember = {
130+
id: 'member-456',
131+
userId: 'user-123',
132+
organizationId: 'org-456',
133+
role: 'member',
134+
}
135+
136+
export const mockTeamSubscription = {
137+
id: 'sub-456',
138+
plan: 'team',
139+
status: 'active',
140+
seats: 5,
141+
referenceId: 'org-123',
142+
}
143+
144+
export const mockPersonalSubscription = {
145+
id: 'sub-789',
146+
plan: 'enterprise',
147+
status: 'active',
148+
seats: 5,
149+
referenceId: 'user-123',
150+
metadata: {
151+
perSeatAllowance: 100,
152+
totalAllowance: 500,
153+
updatedAt: '2023-01-01T00:00:00.000Z',
154+
},
92155
}
93156

94-
/**
95-
* Mock environment variables for testing
96-
*/
97157
export const mockEnvironmentVars = {
98158
OPENAI_API_KEY: 'encrypted:openai-api-key',
99159
SERPER_API_KEY: 'encrypted:serper-api-key',
100160
}
101161

102-
/**
103-
* Mock decrypted environment variables for testing
104-
*/
105162
export const mockDecryptedEnvVars = {
106163
OPENAI_API_KEY: 'sk-test123',
107164
SERPER_API_KEY: 'serper-test123',
108165
}
109166

110-
/**
111-
* Create mock Next.js request for testing
112-
*/
113167
export function createMockRequest(
114168
method: string = 'GET',
115169
body?: any,
@@ -125,11 +179,7 @@ export function createMockRequest(
125179
})
126180
}
127181

128-
/**
129-
* Mock the executeWorkflow function dependencies
130-
*/
131182
export function mockExecutionDependencies() {
132-
// Mock decryptSecret function
133183
vi.mock('@/lib/utils', async () => {
134184
const actual = await vi.importActual('@/lib/utils')
135185
return {
@@ -150,26 +200,22 @@ export function mockExecutionDependencies() {
150200
}
151201
})
152202

153-
// Mock execution logger functions
154203
vi.mock('@/lib/logs/execution-logger', () => ({
155204
persistExecutionLogs: vi.fn().mockResolvedValue(undefined),
156205
persistExecutionError: vi.fn().mockResolvedValue(undefined),
157206
}))
158207

159-
// Mock trace spans builder
160208
vi.mock('@/lib/logs/trace-spans', () => ({
161209
buildTraceSpans: vi.fn().mockReturnValue({
162210
traceSpans: [],
163211
totalDuration: 100,
164212
}),
165213
}))
166214

167-
// Mock workflow utils
168215
vi.mock('@/lib/workflows/utils', () => ({
169216
updateWorkflowRunCounts: vi.fn().mockResolvedValue(undefined),
170217
}))
171218

172-
// Mock serializer
173219
vi.mock('@/serializer', () => ({
174220
Serializer: vi.fn().mockImplementation(() => ({
175221
serializeWorkflow: vi.fn().mockReturnValue({
@@ -205,7 +251,6 @@ export function mockExecutionDependencies() {
205251
})),
206252
}))
207253

208-
// Mock executor
209254
vi.mock('@/executor', () => ({
210255
Executor: vi.fn().mockImplementation(() => ({
211256
execute: vi.fn().mockResolvedValue({
@@ -226,15 +271,11 @@ export function mockExecutionDependencies() {
226271
})),
227272
}))
228273

229-
// Mock database
230274
vi.mock('@/db', () => ({
231-
db: mockDb(),
275+
db: mockDb,
232276
}))
233277
}
234278

235-
/**
236-
* Mock the workflow access validation middleware
237-
*/
238279
export function mockWorkflowAccessValidation(shouldSucceed = true) {
239280
if (shouldSucceed) {
240281
vi.mock('@/app/api/workflows/middleware', () => ({
@@ -258,11 +299,7 @@ export function mockWorkflowAccessValidation(shouldSucceed = true) {
258299
}
259300
}
260301

261-
/**
262-
* Get mocked dependencies for validation
263-
*/
264302
export async function getMockedDependencies() {
265-
// Using dynamic imports to avoid module resolution issues
266303
const utilsModule = await import('@/lib/utils')
267304
const logsModule = await import('@/lib/logs/execution-logger')
268305
const traceSpansModule = await import('@/lib/logs/trace-spans')

0 commit comments

Comments
 (0)