<commit_before>/* eslint-env jest */
import moment from 'moment'
import MockDate from 'mockdate'
import { getMockUserContext } from '../../test-utils'

jest.mock('../getCurrentCampaignConfig')

beforeEach(() => {
  const mockNow = '2017-05-19T13:59:58.000Z'
  MockDate.set(moment(mockNow))
})

afterEach(() => {
  jest.clearAllMocks()
})

// See createCampaignConfiguration.test.js.
const getMockCampaignConfiguration = () => ({
  campaignId: 'myCoolCampaign',
  content: {
    titleMarkdown: '## Some title',
    descriptionMarkdown: '#### A description goes here.',
  },
  endContent: {
    titleMarkdown: '## Another title',
    descriptionMarkdown: '#### Another description goes here.',
  },
  getCharityData: jest.fn(() =>
    Promise.resolve({
      id: 'some-charity-id',
      image: 'https://cdn.example.com/some-image.jpg',
      imageCaption: null,
      impact: 'This is what we show after a user donates hearts.',
      name: 'Some Charity',
      vcReceived: 9876543,
      website: 'https://foo.com',
    })
  ),
  goal: {
    getCurrentNumber: jest.fn(() => Promise.resolve(112358)),
    impactUnitSingular: 'Heart',
    impactUnitPlural: 'Hearts',
    impactVerbPastTense: 'raised',
    targetNumber: 10e6,
  },
  incrementNewUserCount: jest.fn(),
  incrementTabCount: jest.fn(),
  isActive: jest.fn(),
  showCountdownTimer: true,
  showHeartsDonationButton: true,
  showProgressBar: true,
  time: {
    start: '2020-05-01T18:00:00.000Z',
    end: '2020-05-05T18:00:00.000Z',
  },
})

afterEach(() => {
  jest.clearAllMocks()
})

describe('getCampaign', () => {
  it('is a placeholder', async () => {
    expect.assertions(1)
    const getCurrentCampaignConfig = require('../getCurrentCampaignConfig')
      .default
    getCurrentCampaignConfig.mockReturnValue(getMockCampaignConfiguration())
    const mockUserContext = getMockUserContext()
    const getCampaign = require('../getCampaign').default
    const campaign = await getCampaign(mockUserContext)
    expect(campaign).toEqual({
      campaignId: 'myCoolCampaign',
      charity: {
        id: 'some-charity-id',
        image: 'https://cdn.example.com/some-image.jpg',
        imageCaption: null,
        impact: 'This is what we show after a user donates hearts.',
        name: 'Some Charity',
        vcReceived: 9876543,
        website: 'https://foo.com',
      },
      content: {
        titleMarkdown: '## Some title',
        descriptionMarkdown: '#### A description goes here.',
      },
      endContent: {
        titleMarkdown: '## Another title',
        descriptionMarkdown: '#### Another description goes here.',
      },
      goal: {
        currentNumber: 112358,
        impactUnitSingular: 'Heart',
        impactUnitPlural: 'Hearts',
        impactVerbPastTense: 'raised',
        targetNumber: 10e6,
      },
      incrementNewUserCount: expect.any(Function),
      incrementTabCount: expect.any(Function),
      isActive: expect.any(Function),
      showCountdownTimer: true,
      showHeartsDonationButton: true,
      showProgressBar: true,
      time: {
        start: '2020-05-01T18:00:00.000Z',
        end: '2020-05-05T18:00:00.000Z',
      },
    })
  })
})
<commit_msg>Add tests<commit_after>/* eslint-env jest */
import moment from 'moment'
import MockDate from 'mockdate'
import { getMockUserContext } from '../../test-utils'

jest.mock('../getCurrentCampaignConfig')

beforeEach(() => {
  const mockNow = '2017-05-19T13:59:58.000Z'
  MockDate.set(moment(mockNow))
})

afterEach(() => {
  jest.clearAllMocks()
})

// See createCampaignConfiguration.test.js.
const getMockCampaignConfiguration = () => ({
  campaignId: 'myCoolCampaign',
  content: {
    titleMarkdown: '## Some title',
    descriptionMarkdown: '#### A description goes here.',
  },
  endContent: {
    titleMarkdown: '## Another title',
    descriptionMarkdown: '#### Another description goes here.',
  },
  getCharityData: jest.fn(() =>
    Promise.resolve({
      id: 'some-charity-id',
      image: 'https://cdn.example.com/some-image.jpg',
      imageCaption: null,
      impact: 'This is what we show after a user donates hearts.',
      name: 'Some Charity',
      vcReceived: 9876543,
      website: 'https://foo.com',
    })
  ),
  goal: {
    getCurrentNumber: jest.fn(() => Promise.resolve(112358)),
    impactUnitSingular: 'Heart',
    impactUnitPlural: 'Hearts',
    impactVerbPastTense: 'raised',
    targetNumber: 10e6,
  },
  incrementNewUserCount: jest.fn(),
  incrementTabCount: jest.fn(),
  isActive: jest.fn(),
  showCountdownTimer: true,
  showHeartsDonationButton: true,
  showProgressBar: true,
  time: {
    start: '2020-05-01T18:00:00.000Z',
    end: '2020-05-05T18:00:00.000Z',
  },
})

afterEach(() => {
  jest.clearAllMocks()
})

describe('getCampaign', () => {
  it('returns the expected data', async () => {
    expect.assertions(1)
    const getCurrentCampaignConfig = require('../getCurrentCampaignConfig')
      .default
    getCurrentCampaignConfig.mockReturnValue(getMockCampaignConfiguration())
    const mockUserContext = getMockUserContext()
    const getCampaign = require('../getCampaign').default
    const campaign = await getCampaign(mockUserContext)
    expect(campaign).toEqual({
      campaignId: 'myCoolCampaign',
      charity: {
        id: 'some-charity-id',
        image: 'https://cdn.example.com/some-image.jpg',
        imageCaption: null,
        impact: 'This is what we show after a user donates hearts.',
        name: '<NAME>',
        vcReceived: 9876543,
        website: 'https://foo.com',
      },
      content: {
        titleMarkdown: '## Some title',
        descriptionMarkdown: '#### A description goes here.',
      },
      endContent: {
        titleMarkdown: '## Another title',
        descriptionMarkdown: '#### Another description goes here.',
      },
      goal: {
        currentNumber: 112358,
        impactUnitSingular: 'Heart',
        impactUnitPlural: 'Hearts',
        impactVerbPastTense: 'raised',
        targetNumber: 10e6,
      },
      incrementNewUserCount: expect.any(Function),
      incrementTabCount: expect.any(Function),
      isActive: expect.any(Function),
      showCountdownTimer: true,
      showHeartsDonationButton: true,
      showProgressBar: true,
      time: {
        start: '2020-05-01T18:00:00.000Z',
        end: '2020-05-05T18:00:00.000Z',
      },
    })
  })

  it('does not include a "charity" value if getCharityData returns null', async () => {
    expect.assertions(1)
    const getCurrentCampaignConfig = require('../getCurrentCampaignConfig')
      .default
    const mockCampaignConfig = getMockCampaignConfiguration()
    getCurrentCampaignConfig.mockReturnValue({
      ...mockCampaignConfig,
      getCharityData: jest.fn(() => Promise.resolve(null)),
    })
    const mockUserContext = getMockUserContext()
    const getCampaign = require('../getCampaign').default
    const campaign = await getCampaign(mockUserContext)
    expect(campaign.charity).toBeUndefined()
  })

  it('does not include a "goal" value if goal is not defined in the campaign config', async () => {
    expect.assertions(1)
    const getCurrentCampaignConfig = require('../getCurrentCampaignConfig')
      .default
    const mockCampaignConfig = getMockCampaignConfiguration()
    getCurrentCampaignConfig.mockReturnValue({
      ...mockCampaignConfig,
      goal: undefined,
    })
    const mockUserContext = getMockUserContext()
    const getCampaign = require('../getCampaign').default
    const campaign = await getCampaign(mockUserContext)
    expect(campaign.goal).toBeUndefined()
  })
})

{'fraction_non_alphanumeric': 0.1401980198019802, 'fraction_numerical': 0.03141914191419142, 'mean_word_length': 3.192584394023243, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 23, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3310570', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2325, 'n_words': 475}