async function testEmailBatches(settings, email_recipient_filter, expectedBatches) {
    const {emailModel} = await sendEmail(agent, settings, email_recipient_filter);

    assert.equal(emailModel.get('source_type'), 'mobiledoc');
    assert(emailModel.get('subject'));
    assert(emailModel.get('from'));
    const expectedTotal = expectedBatches.reduce((acc, batch) => acc + batch.recipients, 0);
    assert.equal(emailModel.get('email_count'), expectedTotal, 'This email should have an email_count of ' + expectedTotal + ' recipients');

    // Did we create batches?
    const batches = await models.EmailBatch.findAll({filter: `email_id:'${emailModel.id}'`});
    assert.equal(batches.models.length, expectedBatches.length);
    const remainingBatches = batches.models.slice();
    const emailRecipients = [];

    for (const expectedBatch of expectedBatches) {
        // Check all batches are in send state
        const index = remainingBatches.findIndex(b => b.get('member_segment') === expectedBatch.segment);
        assert(index !== -1, `Could not find batch with segment ${expectedBatch.segment}`);
        const firstBatch = remainingBatches[index];
        remainingBatches.splice(index, 1);

        assert.equal(firstBatch.get('provider_id'), 'stubbed-email-id');
        assert.equal(firstBatch.get('status'), 'submitted');
        assert.equal(firstBatch.get('member_segment'), expectedBatch.segment);
        assert.equal(firstBatch.get('error_status_code'), null);
        assert.equal(firstBatch.get('error_message'), null);
        assert.equal(firstBatch.get('error_data'), null);

        // Did we create recipients?
        const emailRecipientsFirstBatch = await models.EmailRecipient.findAll({filter: `email_id:'${emailModel.id}'+batch_id:'${firstBatch.id}'`});
        assert.equal(emailRecipientsFirstBatch.models.length, expectedBatch.recipients);

        emailRecipients.push(...emailRecipientsFirstBatch.models);
    }

    // Check members are unique in all batches
    const memberIds = emailRecipients.map(recipient => recipient.get('member_id'));
    assert.equal(memberIds.length, _.uniq(memberIds).length);
}
Test amount of batches and segmenting for a given email

@param {object} settings
@param {string|null} email_recipient_filter
@param {{recipients: number, segment: string | null}[]} expectedBatches