chore(webhooks): rename functions to factory
This commit is contained in:
Родитель
967e02c431
Коммит
b03a8c38bd
|
@ -2,7 +2,7 @@
|
|||
|
||||
const knex = require('@/db/knex')
|
||||
|
||||
const { dispatchStreamEvent } = require('../../webhooks/services/webhooks')
|
||||
const { dispatchStreamEventFactory } = require('@/modules/webhooks/services/webhooks')
|
||||
const { getStream } = require('@/modules/core/repositories/streams')
|
||||
const {
|
||||
createWebhookEventFactory
|
||||
|
@ -47,7 +47,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
await dispatchStreamEvent({
|
||||
await dispatchStreamEventFactory({
|
||||
db: trx ?? knex.db,
|
||||
getServerInfo,
|
||||
getStream,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
||||
import { authorizeResolver } from '@/modules/shared'
|
||||
import {
|
||||
createWebhook,
|
||||
deleteWebhook,
|
||||
updateWebhook
|
||||
createWebhookFactory,
|
||||
deleteWebhookFactory,
|
||||
updateWebhookFactory
|
||||
} from '@/modules/webhooks/services/webhooks'
|
||||
import { Roles } from '@speckle/shared'
|
||||
import {
|
||||
|
@ -73,7 +73,7 @@ export = {
|
|||
context.resourceAccessRules
|
||||
)
|
||||
|
||||
const id = await createWebhook({
|
||||
const id = await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})({
|
||||
|
@ -101,7 +101,7 @@ export = {
|
|||
'The webhook id and stream id do not match. Please check your inputs.'
|
||||
)
|
||||
|
||||
const updated = await updateWebhook({
|
||||
const updated = await updateWebhookFactory({
|
||||
updateWebhookConfig: updateWebhookConfigFactory({ db })
|
||||
})({
|
||||
id: args.webhook.id,
|
||||
|
@ -122,7 +122,7 @@ export = {
|
|||
context.resourceAccessRules
|
||||
)
|
||||
|
||||
return await deleteWebhook({
|
||||
return await deleteWebhookFactory({
|
||||
deleteWebhookConfig: deleteWebhookConfigFactory({ db }),
|
||||
getWebhookById: getWebhookByIdFactory({ db })
|
||||
})(args.webhook)
|
||||
|
|
|
@ -23,7 +23,7 @@ import { Knex } from 'knex'
|
|||
|
||||
const MAX_STREAM_WEBHOOKS = 100
|
||||
|
||||
export const createWebhook =
|
||||
export const createWebhookFactory =
|
||||
({
|
||||
createWebhookConfig,
|
||||
countWebhooksByStreamId
|
||||
|
@ -58,7 +58,7 @@ export const createWebhook =
|
|||
})
|
||||
}
|
||||
|
||||
export const updateWebhook =
|
||||
export const updateWebhookFactory =
|
||||
({ updateWebhookConfig }: { updateWebhookConfig: UpdateWebhookConfig }) =>
|
||||
async (
|
||||
webhook: Pick<Webhook, 'id'> &
|
||||
|
@ -79,7 +79,7 @@ export const updateWebhook =
|
|||
})
|
||||
}
|
||||
|
||||
export const deleteWebhook =
|
||||
export const deleteWebhookFactory =
|
||||
({
|
||||
deleteWebhookConfig,
|
||||
getWebhookById
|
||||
|
@ -99,7 +99,7 @@ export const deleteWebhook =
|
|||
return id
|
||||
}
|
||||
|
||||
export const dispatchStreamEvent =
|
||||
export const dispatchStreamEventFactory =
|
||||
({
|
||||
db,
|
||||
getServerInfo,
|
||||
|
|
|
@ -24,17 +24,17 @@ const {
|
|||
} = require('@/modules/webhooks/repositories/webhooks')
|
||||
const { db } = require('@/db/knex')
|
||||
const {
|
||||
createWebhook,
|
||||
updateWebhook: updateWebhookService,
|
||||
deleteWebhook,
|
||||
dispatchStreamEvent
|
||||
createWebhookFactory,
|
||||
updateWebhookFactory,
|
||||
deleteWebhookFactory,
|
||||
dispatchStreamEventFactory
|
||||
} = require('@/modules/webhooks/services/webhooks')
|
||||
const { Users, Streams } = require('@/modules/core/dbSchema')
|
||||
const { getServerInfo } = require('@/modules/core/services/generic')
|
||||
const { getStream } = require('@/modules/core/repositories/streams')
|
||||
const { getUser } = require('@/modules/core/repositories/users')
|
||||
|
||||
const updateWebhook = updateWebhookService({
|
||||
const updateWebhook = updateWebhookFactory({
|
||||
updateWebhookConfig: updateWebhookConfigFactory({ db })
|
||||
})
|
||||
const getStreamWebhooks = getStreamWebhooksFactory({ db })
|
||||
|
@ -87,7 +87,7 @@ describe('Webhooks @webhooks', () => {
|
|||
|
||||
describe('Create, Read, Update, Delete Webhooks', () => {
|
||||
it('Should create a webhook', async () => {
|
||||
webhookOne.id = await createWebhook({
|
||||
webhookOne.id = await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhookOne)
|
||||
|
@ -103,7 +103,7 @@ describe('Webhooks @webhooks', () => {
|
|||
})
|
||||
|
||||
it('Should update a webhook', async () => {
|
||||
const webhookId = await createWebhook({
|
||||
const webhookId = await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhookOne)
|
||||
|
@ -132,11 +132,11 @@ describe('Webhooks @webhooks', () => {
|
|||
enabled: true,
|
||||
triggers: ['commit_create', 'commit_update']
|
||||
}
|
||||
webhook.id = await createWebhook({
|
||||
webhook.id = await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhook)
|
||||
await deleteWebhook({
|
||||
await deleteWebhookFactory({
|
||||
deleteWebhookConfig: deleteWebhookConfigFactory({ db }),
|
||||
getWebhookById: getWebhookByIdFactory({ db })
|
||||
})(webhook)
|
||||
|
@ -163,7 +163,7 @@ describe('Webhooks @webhooks', () => {
|
|||
enabled: true,
|
||||
triggers: ['commit_create', 'commit_update']
|
||||
}
|
||||
await createWebhook({
|
||||
await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhook)
|
||||
|
@ -192,11 +192,11 @@ describe('Webhooks @webhooks', () => {
|
|||
enabled: true,
|
||||
triggers: ['commit_create', 'commit_update']
|
||||
}
|
||||
const webhookId = await createWebhook({
|
||||
const webhookId = await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhook)
|
||||
await dispatchStreamEvent({
|
||||
await dispatchStreamEventFactory({
|
||||
db,
|
||||
getServerInfo,
|
||||
getStream,
|
||||
|
@ -270,7 +270,7 @@ describe('Webhooks @webhooks', () => {
|
|||
})
|
||||
|
||||
it('Should get stream webhooks and the previous events', async () => {
|
||||
await dispatchStreamEvent({
|
||||
await dispatchStreamEventFactory({
|
||||
db,
|
||||
getServerInfo,
|
||||
getStream,
|
||||
|
@ -351,7 +351,7 @@ describe('Webhooks @webhooks', () => {
|
|||
enabled: true,
|
||||
triggers: ['commit_create', 'commit_update']
|
||||
}
|
||||
webhook.id = await createWebhook({
|
||||
webhook.id = await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhook)
|
||||
|
@ -401,14 +401,14 @@ describe('Webhooks @webhooks', () => {
|
|||
triggers: ['commit_create', 'commit_update']
|
||||
}
|
||||
for (let i = 0; i < limit; i++) {
|
||||
await createWebhook({
|
||||
await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhook)
|
||||
}
|
||||
|
||||
try {
|
||||
await createWebhook({
|
||||
await createWebhookFactory({
|
||||
createWebhookConfig: createWebhookConfigFactory({ db }),
|
||||
countWebhooksByStreamId: countWebhooksByStreamIdFactory({ db })
|
||||
})(webhook)
|
||||
|
|
Загрузка…
Ссылка в новой задаче