Add utils
This commit is contained in:
parent
358f91177c
commit
4f6a09fb02
|
@ -17,6 +17,10 @@ export default class AuditLogsProcessor implements EventProcessor {
|
||||||
static auditLogsEnabled = false
|
static auditLogsEnabled = false
|
||||||
static auditLogQueue: BullQueue.Queue<AuditLogQueueEvent>
|
static auditLogQueue: BullQueue.Queue<AuditLogQueueEvent>
|
||||||
|
|
||||||
|
get queue() {
|
||||||
|
return AuditLogsProcessor.auditLogQueue
|
||||||
|
}
|
||||||
|
|
||||||
// can't use constructor as need to return promise
|
// can't use constructor as need to return promise
|
||||||
static init(fn: AuditLogFn) {
|
static init(fn: AuditLogFn) {
|
||||||
AuditLogsProcessor.auditLogsEnabled = true
|
AuditLogsProcessor.auditLogsEnabled = true
|
||||||
|
|
|
@ -5,8 +5,8 @@ import Processors from "./Processors"
|
||||||
import { AuditLogFn } from "@budibase/types"
|
import { AuditLogFn } from "@budibase/types"
|
||||||
|
|
||||||
export const analyticsProcessor = new AnalyticsProcessor()
|
export const analyticsProcessor = new AnalyticsProcessor()
|
||||||
const loggingProcessor = new LoggingProcessor()
|
export const loggingProcessor = new LoggingProcessor()
|
||||||
const auditLogsProcessor = new AuditLogsProcessor()
|
export const auditLogsProcessor = new AuditLogsProcessor()
|
||||||
|
|
||||||
export function init(auditingFn: AuditLogFn) {
|
export function init(auditingFn: AuditLogFn) {
|
||||||
return AuditLogsProcessor.init(auditingFn)
|
return AuditLogsProcessor.init(auditingFn)
|
||||||
|
|
|
@ -4,3 +4,4 @@ export { generator } from "./structures"
|
||||||
export * as testContainerUtils from "./testContainerUtils"
|
export * as testContainerUtils from "./testContainerUtils"
|
||||||
export * as utils from "./utils"
|
export * as utils from "./utils"
|
||||||
export * from "./jestUtils"
|
export * from "./jestUtils"
|
||||||
|
export * as queue from "./queue"
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { Queue } from "bull"
|
||||||
|
|
||||||
|
export async function processMessages(queue: Queue) {
|
||||||
|
do {
|
||||||
|
await queue.whenCurrentJobsFinished()
|
||||||
|
} while (await queue.count())
|
||||||
|
|
||||||
|
await queue.whenCurrentJobsFinished()
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import { mocks, structures } from "@budibase/backend-core/tests"
|
import { mocks, structures, queue } from "@budibase/backend-core/tests"
|
||||||
import { context, events, features } from "@budibase/backend-core"
|
import { context, events, features } from "@budibase/backend-core"
|
||||||
import { Event, IdentityType } from "@budibase/types"
|
import { Event, IdentityType } from "@budibase/types"
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration } from "../../../../tests"
|
||||||
|
@ -54,6 +54,11 @@ describe("/api/global/auditlogs (%s)", () => {
|
||||||
await context.doInAppContext(APP_ID, async () => {
|
await context.doInAppContext(APP_ID, async () => {
|
||||||
await events.app.created(structures.apps.app(APP_ID))
|
await events.app.created(structures.apps.app(APP_ID))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await queue.processMessages(
|
||||||
|
events.processors.auditLogsProcessor.queue
|
||||||
|
)
|
||||||
|
|
||||||
// fetch the user created events
|
// fetch the user created events
|
||||||
const response = await config.api.auditLogs.search({
|
const response = await config.api.auditLogs.search({
|
||||||
events: [Event.USER_CREATED],
|
events: [Event.USER_CREATED],
|
||||||
|
|
Loading…
Reference in New Issue