fix(ombi): retrieve and include settings ID in webhook enable payload (resolves #41)
Build and Push Docker Image / build (push) Successful in 1m10s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 4m35s
CI / Security audit (push) Successful in 5m8s
CI / Swagger Validation & Coverage (push) Successful in 6m50s
CI / Tests & coverage (push) Successful in 7m25s
Build and Push Docker Image / build (push) Successful in 1m10s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 4m35s
CI / Security audit (push) Successful in 5m8s
CI / Swagger Validation & Coverage (push) Successful in 6m50s
CI / Tests & coverage (push) Successful in 7m25s
This commit is contained in:
@@ -225,9 +225,27 @@ router.post('/webhook/enable', requireAuth, async (req, res) => {
|
|||||||
|
|
||||||
// Call Ombi API to register webhook
|
// Call Ombi API to register webhook
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
// Get existing settings to retrieve the database ID
|
||||||
|
const currentRes = await axios.get(
|
||||||
|
`${ombiInst.url}/api/v1/Settings/notifications/webhook`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'ApiKey': ombiInst.apiKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).catch(err => {
|
||||||
|
logToFile(`[Ombi] Warning fetching existing webhook settings: ${err.message}`);
|
||||||
|
return { data: {} };
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentConfig = currentRes.data || {};
|
||||||
|
const settingsId = currentConfig.id || 0;
|
||||||
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${ombiInst.url}/api/v1/Settings/notifications/webhook`,
|
`${ombiInst.url}/api/v1/Settings/notifications/webhook`,
|
||||||
{
|
{
|
||||||
|
id: settingsId,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
webhookUrl: webhookUrl,
|
webhookUrl: webhookUrl,
|
||||||
applicationToken: ombiInst.apiKey
|
applicationToken: ombiInst.apiKey
|
||||||
|
|||||||
@@ -850,7 +850,15 @@ describe('POST /api/ombi/webhook/enable', () => {
|
|||||||
|
|
||||||
it('enables webhook successfully', async () => {
|
it('enables webhook successfully', async () => {
|
||||||
nock(OMBI_BASE)
|
nock(OMBI_BASE)
|
||||||
.post('/api/v1/Settings/notifications/webhook')
|
.get('/api/v1/Settings/notifications/webhook')
|
||||||
|
.reply(200, { id: 42, enabled: false, webhookUrl: null, applicationToken: null });
|
||||||
|
nock(OMBI_BASE)
|
||||||
|
.post('/api/v1/Settings/notifications/webhook', {
|
||||||
|
id: 42,
|
||||||
|
enabled: true,
|
||||||
|
webhookUrl: `${SOFARR_BASE}/api/webhook/ombi`,
|
||||||
|
applicationToken: 'test-ombi-key'
|
||||||
|
})
|
||||||
.reply(200, { success: true });
|
.reply(200, { success: true });
|
||||||
|
|
||||||
const { cookies, csrfToken } = await authenticateUser(app, 'TestUser', false);
|
const { cookies, csrfToken } = await authenticateUser(app, 'TestUser', false);
|
||||||
@@ -866,7 +874,34 @@ describe('POST /api/ombi/webhook/enable', () => {
|
|||||||
expect(res.body.applicationToken).toBe('test-ombi-key');
|
expect(res.body.applicationToken).toBe('test-ombi-key');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('enables webhook successfully even if GET settings fails', async () => {
|
||||||
|
nock(OMBI_BASE)
|
||||||
|
.get('/api/v1/Settings/notifications/webhook')
|
||||||
|
.reply(500, { error: 'Failed to fetch settings' });
|
||||||
|
nock(OMBI_BASE)
|
||||||
|
.post('/api/v1/Settings/notifications/webhook', {
|
||||||
|
id: 0,
|
||||||
|
enabled: true,
|
||||||
|
webhookUrl: `${SOFARR_BASE}/api/webhook/ombi`,
|
||||||
|
applicationToken: 'test-ombi-key'
|
||||||
|
})
|
||||||
|
.reply(200, { success: true });
|
||||||
|
|
||||||
|
const { cookies, csrfToken } = await authenticateUser(app, 'TestUser', false);
|
||||||
|
|
||||||
|
const res = await request(app)
|
||||||
|
.post('/api/ombi/webhook/enable')
|
||||||
|
.set('Cookie', cookies)
|
||||||
|
.set('X-CSRF-Token', csrfToken)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(res.body.success).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('handles Ombi API errors gracefully', async () => {
|
it('handles Ombi API errors gracefully', async () => {
|
||||||
|
nock(OMBI_BASE)
|
||||||
|
.get('/api/v1/Settings/notifications/webhook')
|
||||||
|
.reply(200, { id: 42 });
|
||||||
nock(OMBI_BASE)
|
nock(OMBI_BASE)
|
||||||
.post('/api/v1/Settings/notifications/webhook')
|
.post('/api/v1/Settings/notifications/webhook')
|
||||||
.reply(500, { error: 'Internal server error' });
|
.reply(500, { error: 'Internal server error' });
|
||||||
|
|||||||
Reference in New Issue
Block a user