diff --git a/README.md b/README.md index 4b05907c..f9fef5ba 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ You can do a one-click deploy on Render using the button below: [![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/parcelvoy/platform) -Make sure to the `BASE_URL` to the URL of the web server. +Make sure to set the `BASE_URL` environment variable to the URL of the web server. ### Docker Compose diff --git a/apps/platform/src/campaigns/CampaignService.ts b/apps/platform/src/campaigns/CampaignService.ts index 3482f843..abf5e043 100644 --- a/apps/platform/src/campaigns/CampaignService.ts +++ b/apps/platform/src/campaigns/CampaignService.ts @@ -421,6 +421,6 @@ export const campaignPreview = async (project: Project, campaign: Campaign) => { } export const estimatedSendSize = async (campaign: Campaign) => { - const lists: List[] = await List.query().whereIn('id', campaign.lists ?? []) + const lists: List[] = await List.query().whereIn('id', campaign.list_ids ?? []) return lists.reduce((acc, list) => (list.users_count ?? 0) + acc, 0) } diff --git a/apps/platform/src/campaigns/__tests__/CampaignService.spec.ts b/apps/platform/src/campaigns/__tests__/CampaignService.spec.ts index f6b24d38..603bc008 100644 --- a/apps/platform/src/campaigns/__tests__/CampaignService.spec.ts +++ b/apps/platform/src/campaigns/__tests__/CampaignService.spec.ts @@ -6,9 +6,10 @@ import { createSubscription, subscribe } from '../../subscriptions/SubscriptionS import { User } from '../../users/User' import { uuid } from '../../utilities' import Campaign, { CampaignSend, SentCampaign } from '../Campaign' -import { allCampaigns, createCampaign, getCampaign, sendCampaign, generateSendList } from '../CampaignService' +import { allCampaigns, createCampaign, getCampaign, sendCampaign, generateSendList, estimatedSendSize } from '../CampaignService' import { createProvider } from '../../providers/ProviderRepository' import { createTestProject } from '../../projects/__tests__/ProjectTestHelpers' +import ListStatsJob from '../../lists/ListStatsJob' afterEach(() => { jest.clearAllMocks() @@ -237,4 +238,39 @@ describe('CampaignService', () => { expect(updatedCampaign?.state).toEqual('scheduled') }) }) + + describe('estimatedSendSize', () => { + + test('send size is equal to combination of all lists', async () => { + const params = await createCampaignDependencies() + const list1 = await createList(params.project_id, { + name: uuid(), + type: 'static', + is_visible: true, + }) + const list2 = await createList(params.project_id, { + name: uuid(), + type: 'static', + is_visible: true, + }) + + const campaign = await createTestCampaign(params, { + list_ids: [list1.id, list2.id], + send_at: new Date(), + }) as SentCampaign + + for (let i = 0; i < 20; i++) { + const user = await createUser(params.project_id) + await addUserToList(user, list1) + await addUserToList(user, list2) + await subscribe(user.id, params.subscription_id) + } + + await ListStatsJob.handler({ listId: list1.id, projectId: params.project_id }) + await ListStatsJob.handler({ listId: list2.id, projectId: params.project_id }) + + const sendSize = await estimatedSendSize(campaign) + expect(sendSize).toEqual(40) + }) + }) })