Files
speckle-server/packages/server/modules/webhooks/tests/cleanup.spec.ts
T
Gergő Jedlicska 3d6653f73b hotfix/2.9.2 (#1175)
* Update to new specklepy (#1173)

* Publish images for all branches but limit tagging
* only tag 'latest' and '2' when 'SHOULD_PUBLISH' variable is 'true'

* Publishing helm chart should check for `SHOULD_PUBLISH`

* Move blocking step to publish-helm chart, and allow images to be published

* Pin python requirements and bump to latest versions

* Fix EOL whitespace

* use valid version for psycopg2-binary (the clue is in the 2!)

* fix(fileimports): add exception printing to file imports

* fix(fileimports): bump specklepy version

move to a specklepy version that contains a fix for send without writing to disk

Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>

* Fixes liveness and readiness checks to prevent CSRF error message (#1169)

- provides content-type header
- check that status code is 200

* Fixes broken helm template by adding quotation marks around liveness probe command (#1171)

* fix(server activities): make sure the stream events are properly dispatched

* feat(server webhooks): add scheduled orphaned webhook cleanup

* test(server webhooks): add test to webhook cleanup service

* feat(server webhooks): drop foreign key reference for webhooks schema to streams

* refactor(server req context): refactor req context to have the ip attribute for all requests

* feat(server objects rest api): add ratelimits to objects rest api endpoints

* fix(server rest api): properly handle returning 419

Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>
2022-11-09 13:23:32 +01:00

82 lines
2.3 KiB
TypeScript

import knex from '@/db/knex'
import { createStream } from '@/modules/core/services/streams'
import { createUser } from '@/modules/core/services/users'
import { cleanOrphanedWebhookConfigs } from '@/modules/webhooks/services/cleanup'
import { truncateTables } from '@/test/hooks'
import { expect } from 'chai'
import crs from 'crypto-random-string'
const WEBHOOKS_CONFIG_TABLE = 'webhooks_config'
const WEBHOOKS_EVENTS_TABLE = 'webhooks_events'
const WebhooksConfig = () => knex(WEBHOOKS_CONFIG_TABLE)
const randomId = () => crs({ length: 10 })
const countWebhooks = async () => {
const [{ count }] = await WebhooksConfig().count()
return parseInt(count as string)
}
describe('Webhooks cleanup @webhooks', () => {
before(async () => {
await truncateTables([WEBHOOKS_CONFIG_TABLE, WEBHOOKS_EVENTS_TABLE])
})
it('Cleans orphaned webhook configs', async () => {
const webhookConfig = {
id: randomId(),
streamId: randomId(),
url: 'foobar',
description: 'test_hook',
triggers: {
// eslint-disable-next-line camelcase
stream_update: true
}
}
await WebhooksConfig().insert(webhookConfig)
expect(await countWebhooks()).to.equal(1)
await cleanOrphanedWebhookConfigs()
expect(await countWebhooks()).to.equal(0)
})
it('Cleans orphans, leaves live ones intact', async () => {
const ownerId = await createUser({
name: 'User',
email: 'user@gmail.com',
password: 'jdsadjsadasfdsa'
})
const streamId = await createStream({
name: 'foo',
description: 'bar',
ownerId
})
const webhookConfigs = [
{
id: randomId(),
streamId: randomId(),
url: 'foobar',
description: 'test_hook',
triggers: {
// eslint-disable-next-line camelcase
stream_update: true
}
},
{
id: randomId(),
streamId,
url: 'foobar',
description: 'test_hook',
triggers: {
// eslint-disable-next-line camelcase
stream_update: true
}
}
]
await Promise.all(webhookConfigs.map((c) => WebhooksConfig().insert(c)))
expect(await countWebhooks()).to.equal(2)
await cleanOrphanedWebhookConfigs()
expect(await countWebhooks()).to.equal(1)
})
})