<commit_before>/* eslint-env jest */
import buildMissionReturnType from '../utils'
import getCurrentUserMission from '../getCurrentUserMission'
import {
  DatabaseOperation,
  setMockDBResponse,
  clearAllMockDBResponses,
} from '../../test-utils'

jest.mock('../utils')
jest.mock('../../databaseClient')
jest.mock('../../globals/globals')

afterEach(() => {
  jest.clearAllMocks()
  clearAllMockDBResponses()
})
const mockUserMissions = [
  {
    userId: '<KEY>',
    missionId: '123456789',
    created: '2017-07-19T03:05:12Z',
    tabs: 234,
    longestTabStreak: 4,
    currentTabStreak: 2,
    missionMaxTabsDay: 10,
    acknowledgedMissionStarted: true,
    acknowledgedMissionComplete: false,
  },
  {
    userId: '<KEY>',
    missionId: '123456789',
    created: '2017-07-19T03:05:12Z',
    tabs: 24,
    longestTabStreak: 4,
    currentTabStreak: 2,
    missionMaxTabsDay: 10,
    acknowledgedMissionStarted: true,
    acknowledgedMissionComplete: false,
  },
]
const mockMissionDocument = {
  id: '123456789',
  squadName: 'TestSquad',
  created: '2017-07-19T03:05:12Z',
  started: '2017-07-19T03:05:12Z',
  tabGoal: 1000,
  acceptedSquadMembers: ['<KEY>', '<KEY>'],
  pendingSquadMembersExisting: ['efghijklmnopqrs'],
  pendingSquadMembersEmailInvite: ['<EMAIL>'],
  rejectedSquadMembers: [],
  endOfMissionAwards: [],
  missionType: 'cats',
}
// const mockParams = [userContext, userId, ['test123', 'test124'], 'alec']
describe('getCurrentUserMission tests', () => {
  it('it successfully gets current mission for users with a mission', async () => {
    expect.assertions(2)
    setMockDBResponse(DatabaseOperation.QUERY, {
      Items: mockUserMissions,
    })
    setMockDBResponse(DatabaseOperation.GET, {
      Item: mockMissionDocument,
    })
    await getCurrentUserMission({
      currentMissionId: '123456789',
      id: '123',
    })
    expect(buildMissionReturnType).toHaveBeenCalled()
    expect(buildMissionReturnType).toHaveBeenCalledWith(
      mockMissionDocument,
      mockUserMissions,
      '123'
    )
  })
})<commit_msg>clean up get user mission test<commit_after>/* eslint-env jest */
import buildMissionReturnType from '../utils'
import getCurrentUserMission from '../getCurrentUserMission'
import {
  DatabaseOperation,
  setMockDBResponse,
  clearAllMockDBResponses,
} from '../../test-utils'

jest.mock('../utils')
jest.mock('../../databaseClient')
jest.mock('../../globals/globals')

afterEach(() => {
  jest.clearAllMocks()
  clearAllMockDBResponses()
})
const mockUserMissions = [
  {
    userId: 'cL5KcFKHd9fEU5C9Vstj3g4JAc73',
    missionId: '123456789',
    created: '2017-07-19T03:05:12Z',
    tabs: 234,
    longestTabStreak: 4,
    currentTabStreak: 2,
    missionMaxTabsDay: 10,
    acknowledgedMissionStarted: true,
    acknowledgedMissionComplete: false,
  },
  {
    userId: 'abcdefghijklmno',
    missionId: '123456789',
    created: '2017-07-19T03:05:12Z',
    tabs: 24,
    longestTabStreak: 4,
    currentTabStreak: 2,
    missionMaxTabsDay: 10,
    acknowledgedMissionStarted: true,
    acknowledgedMissionComplete: false,
  },
]
const mockMissionDocument = {
  id: '123456789',
  squadName: 'TestSquad',
  created: '2017-07-19T03:05:12Z',
  started: '2017-07-19T03:05:12Z',
  tabGoal: 1000,
  acceptedSquadMembers: ['cL5KcFKHd9fEU5C9Vstj3g4JAc73', 'abcdefghijklmno'],
  pendingSquadMembersExisting: ['efghijklmnopqrs'],
  pendingSquadMembersEmailInvite: ['<EMAIL>'],
  rejectedSquadMembers: [],
  endOfMissionAwards: [],
  missionType: 'cats',
}
const mockDefaultMissionReturn = {
  missionId: '123456789',
  status: 'started',
  squadName: 'TestSquad',
  tabGoal: 1000,
  endOfMissionAwards: [],
  created: '2017-07-19T03:05:12Z',
  tabCount: 258,
  squadMembers: [
    {
      username: 'alec',
      status: 'accepted',
      longestTabStreak: 4,
      currentTabStreak: 2,
      missionMaxTabsDay: 10,
      tabs: 234,
    },
    {
      username: 'kevin',
      status: 'accepted',
      longestTabStreak: 4,
      currentTabStreak: 2,
      missionMaxTabsDay: 10,
      tabs: 24,
    },
  ],
}
// const mockParams = [userContext, userId, ['test123', 'test124'], 'alec']
describe('getCurrentUserMission tests', () => {
  it('it successfully gets current mission for users with a mission', async () => {
    expect.assertions(3)
    buildMissionReturnType.mockReturnValue(mockDefaultMissionReturn)
    setMockDBResponse(DatabaseOperation.QUERY, {
      Items: mockUserMissions,
    })
    setMockDBResponse(DatabaseOperation.GET, {
      Item: mockMissionDocument,
    })

    const currentMission = await getCurrentUserMission({
      currentMissionId: '123456789',
      id: '123',
    })
    expect(buildMissionReturnType).toHaveBeenCalled()
    expect(buildMissionReturnType).toHaveBeenCalledWith(
      mockMissionDocument,
      mockUserMissions,
      '123'
    )
    expect(currentMission).toEqual(mockDefaultMissionReturn)
  })

  it('it returns null if user is not in a current mission', async () => {
    expect.assertions(1)
    setMockDBResponse(DatabaseOperation.QUERY, {
      Items: mockUserMissions,
    })
    setMockDBResponse(DatabaseOperation.GET, {
      Item: mockMissionDocument,
    })
    buildMissionReturnType.mockReturnValue(mockDefaultMissionReturn)
    const currentMission = await getCurrentUserMission({
      id: '123',
    })
    expect(currentMission).toEqual(null)
  })
})
{'fraction_non_alphanumeric': 0.13307277126372605, 'fraction_numerical': 0.05713753954959985, 'mean_word_length': 3.9167429094236046, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, 'https://': 0, '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': '6021828', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1845, 'n_words': 320}