Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ coverage
**/public/sw.js
**/public/workbox-*.js
**/public/worker-*.js
**/public/fallback-*.js
**/public/fallback-*.js

# Documentation
apps/docs/**/*.mdx
2 changes: 1 addition & 1 deletion apps/docs/content/docs/tools/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
"x",
"youtube"
]
}
}
10 changes: 5 additions & 5 deletions apps/sim/app/(auth)/verify/use-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,26 @@ export function useVerification({
if (storedEmail) {
setEmail(storedEmail)
}

// Check for redirect information
const storedRedirectUrl = sessionStorage.getItem('inviteRedirectUrl')
if (storedRedirectUrl) {
setRedirectUrl(storedRedirectUrl)
}

// Check if this is an invite flow
const storedIsInviteFlow = sessionStorage.getItem('isInviteFlow')
if (storedIsInviteFlow === 'true') {
setIsInviteFlow(true)
}
}

// Also check URL parameters for redirect information
const redirectParam = searchParams.get('redirectAfter')
if (redirectParam) {
setRedirectUrl(redirectParam)
}

// Check for invite_flow parameter
const inviteFlowParam = searchParams.get('invite_flow')
if (inviteFlowParam === 'true') {
Expand Down Expand Up @@ -130,7 +130,7 @@ export function useVerification({
// Clear email from sessionStorage after successful verification
if (typeof window !== 'undefined') {
sessionStorage.removeItem('verificationEmail')

// Also clear invite-related items
if (isInviteFlow) {
sessionStorage.removeItem('inviteRedirectUrl')
Expand Down
139 changes: 88 additions & 51 deletions apps/sim/app/api/__test-utils__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { vi } from 'vitest'
import { NextRequest } from 'next/server'

/**
* Mock sample workflow state for testing
*/
export const sampleWorkflowState = {
blocks: {
'starter-id': {
Expand Down Expand Up @@ -65,51 +62,108 @@ export const sampleWorkflowState = {
isDeployed: false,
}

/**
* Mock database with test data
*/
export function mockDb() {
return {
select: vi.fn().mockImplementation(() => ({
from: vi.fn().mockImplementation(() => ({
where: vi.fn().mockImplementation(() => ({
limit: vi.fn().mockImplementation(() => [
{
id: 'workflow-id',
userId: 'user-id',
state: sampleWorkflowState,
},
]),
})),
export const mockDb = {
select: vi.fn().mockImplementation(() => ({
from: vi.fn().mockImplementation(() => ({
where: vi.fn().mockImplementation(() => ({
limit: vi.fn().mockImplementation(() => [
{
id: 'workflow-id',
userId: 'user-id',
state: sampleWorkflowState,
},
]),
})),
})),
update: vi.fn().mockImplementation(() => ({
set: vi.fn().mockImplementation(() => ({
where: vi.fn().mockResolvedValue([]),
})),
})),
update: vi.fn().mockImplementation(() => ({
set: vi.fn().mockImplementation(() => ({
where: vi.fn().mockResolvedValue([]),
})),
}
})),
eq: vi.fn().mockImplementation((field, value) => ({ field, value, type: 'eq' })),
and: vi.fn().mockImplementation((...conditions) => ({
conditions,
type: 'and',
})),
}

export const mockLogger = {
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
}

export const mockUser = {
id: 'user-123',
email: 'test@example.com',
}

export const mockSubscription = {
id: 'sub-123',
plan: 'enterprise',
status: 'active',
seats: 5,
referenceId: 'user-123',
metadata: {
perSeatAllowance: 100,
totalAllowance: 500,
updatedAt: '2023-01-01T00:00:00.000Z',
},
}

export const mockOrganization = {
id: 'org-456',
name: 'Test Organization',
slug: 'test-org',
}

export const mockAdminMember = {
id: 'member-123',
userId: 'user-123',
organizationId: 'org-456',
role: 'admin',
}

export const mockRegularMember = {
id: 'member-456',
userId: 'user-123',
organizationId: 'org-456',
role: 'member',
}

export const mockTeamSubscription = {
id: 'sub-456',
plan: 'team',
status: 'active',
seats: 5,
referenceId: 'org-123',
}

export const mockPersonalSubscription = {
id: 'sub-789',
plan: 'enterprise',
status: 'active',
seats: 5,
referenceId: 'user-123',
metadata: {
perSeatAllowance: 100,
totalAllowance: 500,
updatedAt: '2023-01-01T00:00:00.000Z',
},
}

/**
* Mock environment variables for testing
*/
export const mockEnvironmentVars = {
OPENAI_API_KEY: 'encrypted:openai-api-key',
SERPER_API_KEY: 'encrypted:serper-api-key',
}

/**
* Mock decrypted environment variables for testing
*/
export const mockDecryptedEnvVars = {
OPENAI_API_KEY: 'sk-test123',
SERPER_API_KEY: 'serper-test123',
}

/**
* Create mock Next.js request for testing
*/
export function createMockRequest(
method: string = 'GET',
body?: any,
Expand All @@ -125,11 +179,7 @@ export function createMockRequest(
})
}

/**
* Mock the executeWorkflow function dependencies
*/
export function mockExecutionDependencies() {
// Mock decryptSecret function
vi.mock('@/lib/utils', async () => {
const actual = await vi.importActual('@/lib/utils')
return {
Expand All @@ -150,26 +200,22 @@ export function mockExecutionDependencies() {
}
})

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

// Mock trace spans builder
vi.mock('@/lib/logs/trace-spans', () => ({
buildTraceSpans: vi.fn().mockReturnValue({
traceSpans: [],
totalDuration: 100,
}),
}))

// Mock workflow utils
vi.mock('@/lib/workflows/utils', () => ({
updateWorkflowRunCounts: vi.fn().mockResolvedValue(undefined),
}))

// Mock serializer
vi.mock('@/serializer', () => ({
Serializer: vi.fn().mockImplementation(() => ({
serializeWorkflow: vi.fn().mockReturnValue({
Expand Down Expand Up @@ -205,7 +251,6 @@ export function mockExecutionDependencies() {
})),
}))

// Mock executor
vi.mock('@/executor', () => ({
Executor: vi.fn().mockImplementation(() => ({
execute: vi.fn().mockResolvedValue({
Expand All @@ -226,15 +271,11 @@ export function mockExecutionDependencies() {
})),
}))

// Mock database
vi.mock('@/db', () => ({
db: mockDb(),
db: mockDb,
}))
}

/**
* Mock the workflow access validation middleware
*/
export function mockWorkflowAccessValidation(shouldSucceed = true) {
if (shouldSucceed) {
vi.mock('@/app/api/workflows/middleware', () => ({
Expand All @@ -258,11 +299,7 @@ export function mockWorkflowAccessValidation(shouldSucceed = true) {
}
}

/**
* Get mocked dependencies for validation
*/
export async function getMockedDependencies() {
// Using dynamic imports to avoid module resolution issues
const utilsModule = await import('@/lib/utils')
const logsModule = await import('@/lib/logs/execution-logger')
const traceSpansModule = await import('@/lib/logs/trace-spans')
Expand Down
Loading