Skip to content

Commit

Permalink
chore: fix enqueueing to wrong next step
Browse files Browse the repository at this point in the history
  • Loading branch information
ogp-weeloong committed May 8, 2024
1 parent 998be5b commit 752deaa
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 220 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/config/app-env-vars/m365.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const m365TenantInfo = Object.freeze({
process.env.M365_SG_GOVT_ALLOWED_SENSITIVITY_LABEL_GUIDS_CSV,
),
}),
...(appConfig.isDev
...(!appConfig.isProd
? {
'govtech-staging': makeTenantInfo({
label: 'GovTech Staging SharePoint',
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type AppConfig = {
webAppUrl: string
webhookUrl: string
appEnv: string
isProd: boolean
isDev: boolean
postgresDatabase: string
postgresPort: number
Expand Down Expand Up @@ -61,6 +62,7 @@ const appEnv = process.env.APP_ENV || 'development'
const appConfig: AppConfig = {
port,
appEnv: appEnv,
isProd: appEnv === 'prod',
isDev: appEnv === 'development',
version: process.env.npm_package_version,
postgresDatabase: process.env.POSTGRES_DATABASE || 'plumber_dev',
Expand Down
208 changes: 0 additions & 208 deletions packages/backend/src/helpers/__tests__/queues.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { afterEach, describe, expect, it, vi } from 'vitest'

import { makeActionQueue } from '../helpers/make-action-queue'

const mocks = vi.hoisted(() => {
const queueOn = vi.fn()

return {
// BullMQ queue mocks
queueConstructor: vi.fn(() => ({
on: queueOn,
})),
queueOn,

// Misc mocks
processOn: vi.fn(),
}
})

vi.mock('@taskforcesh/bullmq-pro', () => ({
QueuePro: mocks.queueConstructor,
}))

vi.mock('process', async () => {
const process = await vi.importActual<typeof import('process')>('process')
return {
default: {
...process,
on: mocks.processOn,
},
}
})

vi.mock('@/config/redis', () => ({
createRedisClient: vi.fn(() => 'mock redis client'),
}))

vi.mock('@/helpers/tracer', () => ({
default: {
wrap: vi.fn(() => ({})),
},
}))

vi.mock('@/apps', () => ({
default: {},
}))

vi.mock('@/helpers/generate-error-email', () => ({
isErrorEmailAlreadySent: vi.fn(),
sendErrorEmail: vi.fn(),
}))

describe('makeActionQueue', () => {
afterEach(() => {
vi.restoreAllMocks()
})

it('creates a queue with an configured queue name', () => {
makeActionQueue({ queueName: '{test-app-queue}' })
expect(mocks.queueConstructor).toHaveBeenCalledWith('{test-app-queue}', {
connection: 'mock redis client',
})
})

it('supports specifying a redis connection prefix', () => {
makeActionQueue({
queueName: 'some-queue',
redisConnectionPrefix: '{test}',
})
expect(mocks.queueConstructor).toHaveBeenCalledWith('some-queue', {
connection: 'mock redis client',
prefix: `{test}`,
})
})
})
2 changes: 1 addition & 1 deletion packages/backend/src/queues/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@taskforcesh/bullmq-pro'

import apps from '@/apps'
import { makeActionQueue } from '@/helpers/queues/make-action-queue'
import { makeActionQueue } from '@/queues/helpers/make-action-queue'

//
// Queue storage
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/workers/__tests__/action.itest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
flushQueue,
restoreWorker,
type WorkerState,
} from './helpers'
} from './test-helpers'

const mocks = vi.hoisted(() => ({
processAction: vi.fn(async () => ({})),
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/workers/__tests__/flow.itest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
flushQueue,
restoreWorker,
type WorkerState,
} from './helpers'
} from './test-helpers'

const mocks = vi.hoisted(() => ({
processFlow: vi.fn(async () => ({
Expand Down
Loading

0 comments on commit 752deaa

Please sign in to comment.