fix: saving a research article as a draft does not trigger webhook (#3834)

This commit is contained in:
Cosimo Chetta
2024-08-31 22:50:09 +02:00
committed by GitHub
parent 3ee0a8c8d6
commit ab4b347046
2 changed files with 41 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import { ResearchUpdateStatus } from 'oa-shared'
import { handleResearchUpdatePublished } from './firebase-discord'
import type { SimpleResearchArticle } from './firebase-discord'
@@ -72,4 +73,37 @@ describe('handle research article update change', () => {
)
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)
})
})

View File

@@ -1,6 +1,6 @@
import axios from 'axios'
import * as functions from 'firebase-functions'
import { IModerationStatus } from 'oa-shared'
import { IModerationStatus, ResearchUpdateStatus } from 'oa-shared'
import { CONFIG } from '../config/config'
@@ -78,6 +78,7 @@ interface SimpleResearchArticleUpdate {
_id: string
title: string
collaborators?: string[]
status?: ResearchUpdateStatus
}
export async function handleResearchUpdatePublished(
@@ -99,6 +100,11 @@ export async function handleResearchUpdatePublished(
const newUpdateIndex = updatedContent.updates.length - 1
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
// but it is a list.
// source: