mirror of
https://github.com/fergalmoran/onearmy-community-platform.git
synced 2025-12-22 09:37:54 +00:00
fix: saving a research article as a draft does not trigger webhook (#3834)
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { ResearchUpdateStatus } from 'oa-shared'
|
||||||
import { handleResearchUpdatePublished } from './firebase-discord'
|
import { handleResearchUpdatePublished } from './firebase-discord'
|
||||||
|
|
||||||
import type { SimpleResearchArticle } from './firebase-discord'
|
import type { SimpleResearchArticle } from './firebase-discord'
|
||||||
@@ -72,4 +73,37 @@ describe('handle research article update change', () => {
|
|||||||
)
|
)
|
||||||
expect(wasMockSendMessagedCalled).toEqual(false)
|
expect(wasMockSendMessagedCalled).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not send message when update is a draft', () => {
|
||||||
|
const webhookUrl = 'exmaple.com'
|
||||||
|
const previousContent: SimpleResearchArticle = {
|
||||||
|
slug: 'test',
|
||||||
|
updates: [],
|
||||||
|
}
|
||||||
|
const newContent: SimpleResearchArticle = {
|
||||||
|
slug: 'test',
|
||||||
|
updates: [
|
||||||
|
{
|
||||||
|
_id: 'bobmore',
|
||||||
|
title: 'test',
|
||||||
|
collaborators: ['Bob'],
|
||||||
|
status: ResearchUpdateStatus.DRAFT,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
let wasMockSendMessagedCalled = false
|
||||||
|
const mockSendMessage = (_: string): Promise<any> => {
|
||||||
|
wasMockSendMessagedCalled = true
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleResearchUpdatePublished(
|
||||||
|
webhookUrl,
|
||||||
|
previousContent,
|
||||||
|
newContent,
|
||||||
|
mockSendMessage,
|
||||||
|
)
|
||||||
|
expect(wasMockSendMessagedCalled).toEqual(false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import * as functions from 'firebase-functions'
|
import * as functions from 'firebase-functions'
|
||||||
import { IModerationStatus } from 'oa-shared'
|
import { IModerationStatus, ResearchUpdateStatus } from 'oa-shared'
|
||||||
|
|
||||||
import { CONFIG } from '../config/config'
|
import { CONFIG } from '../config/config'
|
||||||
|
|
||||||
@@ -78,6 +78,7 @@ interface SimpleResearchArticleUpdate {
|
|||||||
_id: string
|
_id: string
|
||||||
title: string
|
title: string
|
||||||
collaborators?: string[]
|
collaborators?: string[]
|
||||||
|
status?: ResearchUpdateStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleResearchUpdatePublished(
|
export async function handleResearchUpdatePublished(
|
||||||
@@ -99,6 +100,11 @@ export async function handleResearchUpdatePublished(
|
|||||||
const newUpdateIndex = updatedContent.updates.length - 1
|
const newUpdateIndex = updatedContent.updates.length - 1
|
||||||
const newUpdate = updatedContent.updates[newUpdateIndex]
|
const newUpdate = updatedContent.updates[newUpdateIndex]
|
||||||
|
|
||||||
|
if (newUpdate.status === ResearchUpdateStatus.DRAFT) {
|
||||||
|
console.log('Update is a draft')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// On Research Updates, we actually expect the collaborators to be a single person
|
// On Research Updates, we actually expect the collaborators to be a single person
|
||||||
// but it is a list.
|
// but it is a list.
|
||||||
// source:
|
// source:
|
||||||
|
|||||||
Reference in New Issue
Block a user