diff --git a/functions/src/Integrations/firebase-discord.test.ts b/functions/src/Integrations/firebase-discord.test.ts index 562452db3..b54f4dc4f 100644 --- a/functions/src/Integrations/firebase-discord.test.ts +++ b/functions/src/Integrations/firebase-discord.test.ts @@ -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 => { + wasMockSendMessagedCalled = true + return Promise.resolve() + } + + handleResearchUpdatePublished( + webhookUrl, + previousContent, + newContent, + mockSendMessage, + ) + expect(wasMockSendMessagedCalled).toEqual(false) + }) }) diff --git a/functions/src/Integrations/firebase-discord.ts b/functions/src/Integrations/firebase-discord.ts index c79deda05..cb54a69e3 100644 --- a/functions/src/Integrations/firebase-discord.ts +++ b/functions/src/Integrations/firebase-discord.ts @@ -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: