Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hook names are case-sensitive #44

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/server/hooksystem.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava'
import HookSystem from './hooksystem'

test('HookSystem triggers ModerationQueued with expected parameters', async (t) => {
test('HookSystem triggers moderationqueued with expected parameters', async (t) => {
// Mock the fetch API
const mockFetch: any = (url: string, options: any) => {
t.is(url, 'https://example.com/hook')
Expand All @@ -19,7 +19,7 @@ test('HookSystem triggers ModerationQueued with expected parameters', async (t)
return {
hooks: {
get: async (hookType: string) => {
if (hookType === 'ModerationQueued') {
if (hookType === 'moderationqueued') {
return {
url: 'https://example.com/hook',
method: 'POST',
Expand All @@ -44,7 +44,7 @@ test('HookSystem triggers ModerationQueued with expected parameters', async (t)
t.true(result, 'Hook should be triggered successfully')
})

test('HookSystem triggers OnApproved with expected parameters', async (t) => {
test('HookSystem triggers onapproved with expected parameters', async (t) => {
// Mock the fetch API
const mockFetch: any = (url: string, options: any) => {
t.is(url, 'https://example.com/hook-approved')
Expand All @@ -62,7 +62,7 @@ test('HookSystem triggers OnApproved with expected parameters', async (t) => {
return {
hooks: {
get: async (hookType: string) => {
if (hookType === 'OnApproved') {
if (hookType === 'onapproved') {
return {
url: 'https://example.com/hook-approved',
method: 'POST',
Expand All @@ -84,10 +84,10 @@ test('HookSystem triggers OnApproved with expected parameters', async (t) => {
type: 'TestApproved'
})

t.true(result, 'Hook should be triggered successfully for OnApproved')
t.true(result, 'Hook should be triggered successfully for onapproved')
})

test('HookSystem triggers OnRejected with expected parameters', async (t) => {
test('HookSystem triggers onrejected with expected parameters', async (t) => {
// Mock the fetch API
const mockFetch: any = (url: string, options: any) => {
t.is(url, 'https://example.com/hook-rejected')
Expand All @@ -105,7 +105,7 @@ test('HookSystem triggers OnRejected with expected parameters', async (t) => {
return {
hooks: {
get: async (hookType: string) => {
if (hookType === 'OnRejected') {
if (hookType === 'onrejected') {
return {
url: 'https://example.com/hook-rejected',
method: 'POST',
Expand All @@ -127,5 +127,5 @@ test('HookSystem triggers OnRejected with expected parameters', async (t) => {
type: 'TestRejected'
})

t.true(result, 'Hook should be triggered successfully for OnRejected')
t.true(result, 'Hook should be triggered successfully for onrejected')
})
6 changes: 3 additions & 3 deletions src/server/hooksystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export default class HookSystem {
}

async dispatchModerationQueued (actor: string, activity: APActivity): Promise<boolean> {
return await this.dispatchHook('ModerationQueued', actor, activity)
return await this.dispatchHook('moderationqueued', actor, activity)
}

async dispatchOnApproved (actor: string, activity: APActivity): Promise<boolean> {
return await this.dispatchHook('OnApproved', actor, activity)
return await this.dispatchHook('onapproved', actor, activity)
}

async dispatchOnRejected (actor: string, activity: APActivity): Promise<boolean> {
return await this.dispatchHook('OnRejected', actor, activity)
return await this.dispatchHook('onrejected', actor, activity)
}

private async dispatchHook (hookType: string, actor: string, activity: APActivity): Promise<boolean> {
Expand Down
Loading