Skip to content

Commit

Permalink
Fix unrelated test with the changes in this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Sep 24, 2024
1 parent 69a1ce5 commit b41280e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('evaluation results aggregations', () => {
expect(result.mostCommon).toBe('apple')
// Funcky test because of floating point math issues
// in Mac OS and CI Linux
expect(result.percentage).toBeGreaterThan(65)
expect(result.percentage).toBeGreaterThan(64)
expect(result.percentage).toBeLessThan(67)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,43 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ProgressTracker } from '../../utils/progressTracker'
import { runDocumentJob } from './runDocumentJob'

const mocks = vi.hoisted(() => ({
queues: {
defaultQueue: {
jobs: {
enqueueRunEvaluationJob: vi.fn(),
const mocks = vi.hoisted(() => {
const mockEmit = vi.fn()
return {
mockEmit,
getSocketMock: vi.fn().mockResolvedValue({ emit: mockEmit }),
queues: {
defaultQueue: {
jobs: {
enqueueRunEvaluationJob: vi.fn(),
},
},
},
eventsQueue: {
jobs: {
enqueueCreateEventJob: vi.fn(),
enqueuePublishEventJob: vi.fn(),
eventsQueue: {
jobs: {
enqueueCreateEventJob: vi.fn(),
enqueuePublishEventJob: vi.fn(),
},
},
},
}
})

vi.mock('@latitude-data/core/websockets/workers', () => ({
WebsocketClient: {
getSocket: mocks.getSocketMock,
},
}))

// Mock dependencies
vi.mock('../../', () => ({
setupJobs: vi.fn().mockImplementation(() => mocks.queues),
}))

vi.mock('@latitude-data/core/redis')
vi.mock('@latitude-data/core/queues', () => {
return {
queues: vi.fn().mockResolvedValue({}),
}
})
vi.mock('@latitude-data/core/services/commits/runDocumentAtCommit')
vi.mock('@latitude-data/env')
vi.mock('../../utils/progressTracker')
Expand Down Expand Up @@ -117,6 +132,15 @@ describe('runDocumentJob', () => {

await runDocumentJob(mockJob)

expect(mocks.mockEmit).toHaveBeenCalledWith('evaluationStatus', {
workspaceId: workspace.id,
data: {
batchId: 'batch1',
evaluationId: evaluation.id,
documentUuid: document.documentUuid,
},
})

expect(runDocumentAtCommit).toHaveBeenCalled()
expect(
mocks.queues.defaultQueue.jobs.enqueueRunEvaluationJob,
Expand All @@ -136,5 +160,13 @@ describe('runDocumentJob', () => {

expect(consoleSpy).toHaveBeenCalledWith(testError)
expect(ProgressTracker.prototype.incrementErrors).toHaveBeenCalled()
expect(mocks.mockEmit).toHaveBeenCalledWith('evaluationStatus', {
workspaceId: workspace.id,
data: {
batchId: 'batch1',
evaluationId: evaluation.id,
documentUuid: document.documentUuid,
},
})
})
})

0 comments on commit b41280e

Please sign in to comment.