<commit_before>jest.mock('../../../internal/esi-agent');

const API = require('../../../api');

let api = new API();
let agent = api._esiAgent;

function createKillIDs(count) {
  let mails = [];
  for (let i = 0; i < count; i++) {
    mails.push({
      'killmail_id': i,
      'killmail_hash': 'hash' + i
    });
  }
  return mails;
}

function expectMailsSinglePage(charId, maxKillId, token, mails) {
  agent.__expectRoute('get_characters_character_id_killmails_recent', {
    'character_id': charId,
    'max_kill_id': maxKillId,
    'max_count': 50
  }, {
    returns: mails,
    token: token
  });
}

function expectKillsSinglePage(charId, maxKillId, token, mails) {
  expectMailsSinglePage(charId, maxKillId, token, mails);
  for (let i = 0; i < mails.length; i++) {
    agent.__expectRoute('get_killmails_killmail_id_killmail_hash', {
      'killmail_id': mails[i].killmail_id,
      'killmail_hash': mails[i].killmail_hash
    }, { overrides: {'killmail_id': mails[i].killmail_id } });
  }
}

function expectKills(charId, token, mails) {
  let maxKillId = null;
  for (let offset = 0; offset < mails.length; offset += 50) {
    let end = offset + 50;
    if (mails.length < end) {
      end = mails.length;
    }

    let pageMails = mails.slice(offset, end);
    expectKillsSinglePage(charId, maxKillId, token, pageMails);
    maxKillId = pageMails[pageMails.length - 1].killmail_id;
  }
}

function expectMails(charId, token, mails) {
  let maxKillId = null;
  for (let offset = 0; offset < mails.length; offset += 50) {
    let end = offset + 50;
    if (mails.length < end) {
      end = mails.length;
    }

    let pageMails = mails.slice(offset, end);
    expectMailsSinglePage(charId, maxKillId, token, pageMails);
    maxKillId = pageMails[pageMails.length - 1].killmail_id;
  }
}

afterEach(() => {
  agent.__reset();
});

test('CharacterInfo.info', () => {
  agent.__expectRoute('get_characters_character_id', { 'character_id': 1 });
  return api.characters(1).info().then(result => {
    expect(result).toBeDefined();
  });
});

test('CharacterInfo.portrait', () => {
  agent.__expectRoute('get_characters_character_id_portrait',
      { 'character_id': 1 });
  return api.characters(1).portrait().then(result => {
    expect(result).toBeDefined();
  });
});

test('CharacterInfo.history', () => {
  agent.__expectRoute('get_characters_character_id_corporationhistory',
      { 'character_id': 1 });
  return api.characters(1).history().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.assets', () => {
  agent.__expectRoute('get_characters_character_id_assets',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').assets().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.clones', () => {
  agent.__expectRoute('get_characters_character_id_clones',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').clones().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.recentKills maxKillId', () => {
  expectKillsSinglePage(1, 2, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKills(2).then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.recentKills', () => {
  expectKillsSinglePage(1, null, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKills().then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.kills', () => {
  expectKills(1, 'my_token', createKillIDs(153));
  return api.characters(1, 'my_token').kills().then(result => {
    expect(result.length).toEqual(153);
  });
});

test('Character.recentKillmailss maxKillId', () => {
  expectMailsSinglePage(1, 2, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKillmails(2).then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.recentKillmails', () => {
  expectMailsSinglePage(1, null, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKillmails().then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.killmails', () => {
  expectMails(1, 'my_token', createKillIDs(153));
  return api.characters(1, 'my_token').killmails().then(result => {
    expect(result.length).toEqual(153);
  });
});

test('Character.loyaltyPoints', () => {
  agent.__expectRoute('get_characters_character_id_loyalty_points',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').loyaltyPoints().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.ship', () => {
  agent.__expectRoute('get_characters_character_id_ship', { 'character_id': 1 },
      { token: 'my_token' });
  return api.characters(1, 'my_token').ship().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.location', () => {
  agent.__expectRoute('get_characters_character_id_location',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').location().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.wallets', () => {
  agent.__expectRoute('get_characters_character_id_wallets',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').wallets().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.skills', () => {
  agent.__expectRoute('get_characters_character_id_skills',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').skills().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.skillqueue', () => {
  agent.__expectRoute('get_characters_character_id_skillqueue',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').skillqueue().then(result => {
    expect(result).toBeDefined();
  });
});

test('Characters.names small', () => {<commit_msg>Unit tests for character update<commit_after>jest.mock('../../../internal/esi-agent');

const API = require('../../../api');

let api = new API();
let agent = api._esiAgent;

function createKillIDs(count) {
  let mails = [];
  for (let i = 0; i < count; i++) {
    mails.push({
      'killmail_id': i,
      'killmail_hash': 'hash' + i
    });
  }
  return mails;
}

function expectMailsSinglePage(charId, maxKillId, token, mails) {
  agent.__expectRoute('get_characters_character_id_killmails_recent', {
    'character_id': charId,
    'max_kill_id': maxKillId,
    'max_count': 50
  }, {
    returns: mails,
    token: token
  });
}

function expectKillsSinglePage(charId, maxKillId, token, mails) {
  expectMailsSinglePage(charId, maxKillId, token, mails);
  for (let i = 0; i < mails.length; i++) {
    agent.__expectRoute('get_killmails_killmail_id_killmail_hash', {
      'killmail_id': mails[i].killmail_id,
      'killmail_hash': mails[i].killmail_hash
    }, { overrides: {'killmail_id': mails[i].killmail_id } });
  }
}

function expectKills(charId, token, mails) {
  let maxKillId = null;
  for (let offset = 0; offset < mails.length; offset += 50) {
    let end = offset + 50;
    if (mails.length < end) {
      end = mails.length;
    }

    let pageMails = mails.slice(offset, end);
    expectKillsSinglePage(charId, maxKillId, token, pageMails);
    maxKillId = pageMails[pageMails.length - 1].killmail_id;
  }
}

function expectMails(charId, token, mails) {
  let maxKillId = null;
  for (let offset = 0; offset < mails.length; offset += 50) {
    let end = offset + 50;
    if (mails.length < end) {
      end = mails.length;
    }

    let pageMails = mails.slice(offset, end);
    expectMailsSinglePage(charId, maxKillId, token, pageMails);
    maxKillId = pageMails[pageMails.length - 1].killmail_id;
  }
}

afterEach(() => {
  agent.__reset();
});

test('CharacterInfo.info', () => {
  agent.__expectRoute('get_characters_character_id', { 'character_id': 1 });
  return api.characters(1).info().then(result => {
    expect(result).toBeDefined();
  });
});

test('CharacterInfo.portrait', () => {
  agent.__expectRoute('get_characters_character_id_portrait',
      { 'character_id': 1 });
  return api.characters(1).portrait().then(result => {
    expect(result).toBeDefined();
  });
});

test('CharacterInfo.history', () => {
  agent.__expectRoute('get_characters_character_id_corporationhistory',
      { 'character_id': 1 });
  return api.characters(1).history().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.assets', () => {
  agent.__expectRoute('get_characters_character_id_assets',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').assets().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.clones', () => {
  agent.__expectRoute('get_characters_character_id_clones',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').clones().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.recentKills maxKillId', () => {
  expectKillsSinglePage(1, 2, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKills(2).then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.recentKills', () => {
  expectKillsSinglePage(1, null, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKills().then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.kills', () => {
  expectKills(1, 'my_token', createKillIDs(153));
  return api.characters(1, 'my_token').kills().then(result => {
    expect(result.length).toEqual(153);
  });
});

test('Character.recentKillmailss maxKillId', () => {
  expectMailsSinglePage(1, 2, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKillmails(2).then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.recentKillmails', () => {
  expectMailsSinglePage(1, null, 'my_token', createKillIDs(2));
  return api.characters(1, 'my_token').recentKillmails().then(result => {
    expect(result.length).toEqual(2);
  });
});

test('Character.killmails', () => {
  expectMails(1, 'my_token', createKillIDs(153));
  return api.characters(1, 'my_token').killmails().then(result => {
    expect(result.length).toEqual(153);
  });
});

test('Character.loyaltyPoints', () => {
  agent.__expectRoute('get_characters_character_id_loyalty_points',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').loyaltyPoints().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.ship', () => {
  agent.__expectRoute('get_characters_character_id_ship', { 'character_id': 1 },
      { token: 'my_token' });
  return api.characters(1, 'my_token').ship().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.location', () => {
  agent.__expectRoute('get_characters_character_id_location',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').location().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.wallets', () => {
  agent.__expectRoute('get_characters_character_id_wallets',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').wallets().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.skills', () => {
  agent.__expectRoute('get_characters_character_id_skills',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').skills().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.skillqueue', () => {
  agent.__expectRoute('get_characters_character_id_skillqueue',
      { 'character_id': 1 }, { token: 'my_token' });
  return api.characters(1, 'my_token').skillqueue().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.agentResearch', () => {
  agent.__expectRoute('get_characters_character_id_agents_research',
      {'character_id': 1}, {token: 'my_token'});
  return api.characters(1, 'my_token').agentResearch().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.chatChannels', () => {
  agent.__expectRoute('get_characters_character_id_chat_channels',
      {'character_id': 1}, {token: 'my_token'});
  return api.characters(1, 'my_token').chatChannels().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.medals', () => {
  agent.__expectRoute('get_characters_character_id_medals',
      {'character_id': 1}, {token: 'my_token'});
  return api.characters(1, 'my_token').medals().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.opportunities', () => {
  agent.__expectRoute('get_characters_character_id_opportunities',
      {'character_id': 1}, {token: 'my_token'});
  return api.characters(1, 'my_token').opportunities().then(result => {
    expect(result).toBeDefined();
  });
});

test('Character.standings', () => {
  agent.__expectRoute('get_characters_character_id_standings',
      {'character_id': 1}, {token: 'my_token'});
  return api.characters(1, 'my_token').standings().then(result => {
    expect(result).toBeDefined();
  });
});

test('Characters.affiliation', () => {
  agent.__expectRoute('post_characters_affiliation',
      {'characters': [2]});
  return api.characters.affiliations([2]).then(result => {
    expect(result).toBeDefined();
  });
});

test('Characters.names small', () => {
{'fraction_non_alphanumeric': 0.19178994082840237, 'fraction_numerical': 0.011834319526627219, 'mean_word_length': 4.610373443983402, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 87, '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': '6023440', 'n_tokens_mistral': 4818, 'n_tokens_neox': 4660, 'n_words': 659}