UNPKG

tf2-currency

Version:

Set of tools that manage operations with tf2 currency.

875 lines (874 loc) 33.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var currency_class_1 = require("./currency.class"); var currency_helper_1 = require("./currency.helper"); describe('Currency', function () { describe('constructor', function () { it('Creates an instance', function () { var currency = new currency_class_1.Currency({ keys: 12, metal: 23.88, }); expect(currency).toHaveProperty('keys', 12); expect(currency).toHaveProperty('metalInWeapons', 430); expect(currency).toHaveProperty('metal', 23.88); }); it('Keys are negative', function () { var currency = new currency_class_1.Currency({ keys: -12, metal: 23.88, }); expect(currency).toHaveProperty('keys', -12); expect(currency).toHaveProperty('metal', 23.88); expect(currency).toHaveProperty('metalInWeapons', 430); }); it('Metal is negative', function () { var currency = new currency_class_1.Currency({ keys: 12, metal: -23.88, }); expect(currency).toHaveProperty('keys', 12); expect(currency).toHaveProperty('metal', -23.88); expect(currency).toHaveProperty('metalInWeapons', -430); }); it('No metal present', function () { var currency = new currency_class_1.Currency({ keys: 1 }); expect(currency).toHaveProperty('keys', 1); expect(currency).toHaveProperty('metalInWeapons', 0); }); }); describe('fromWeapons', function () { it('With conversion', function () { var currency = currency_class_1.Currency.fromWeapons(1005, 10); expect(currency).toHaveProperty('keys', 5); expect(currency).toHaveProperty('metalInWeapons', 105); }); it('With conversion', function () { var currency = currency_class_1.Currency.fromWeapons(1005); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metalInWeapons', 1005); expect(currency).toHaveProperty('metal', 55.83); }); }); describe('fromScrap', function () { it('Requires conversion', function () { var currency = currency_class_1.Currency.fromScrap(1000, 62); expect(currency).toHaveProperty('keys', 1); expect(currency).toHaveProperty('metal', 49.11); expect(currency).toHaveProperty('metalInWeapons', 884); }); it('Does not require conversion', function () { var currency = currency_class_1.Currency.fromScrap(397); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 44.11); expect(currency).toHaveProperty('metalInWeapons', 794); }); it('Has weapon value', function () { var currency = currency_class_1.Currency.fromScrap(397.5); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 44.16); expect(currency).toHaveProperty('metalInWeapons', 795); }); it('Negative with conversion and weapon value', function () { var currency = currency_class_1.Currency.fromScrap(-1000.5, 62); expect(currency).toHaveProperty('keys', -1); expect(currency).toHaveProperty('metal', -49.16); expect(currency).toHaveProperty('metalInWeapons', -885); }); }); describe('fromKeys', function () { it('Requires conversion', function () { var currency = currency_class_1.Currency.fromKeys(3.2, 62); expect(currency).toHaveProperty('keys', 3); expect(currency).toHaveProperty('metal', 12.44); expect(currency).toHaveProperty('metalInWeapons', 224); }); it('Does not require conversion', function () { var currency = currency_class_1.Currency.fromKeys(3); expect(currency).toHaveProperty('keys', 3); expect(currency).toHaveProperty('metal', 0); expect(currency).toHaveProperty('metalInWeapons', 0); }); it('Throws an exception because of missing conversion', function () { try { var currency = currency_class_1.Currency.fromKeys(3.22); expect(currency).not.toBeDefined(); } catch (e) { expect(e).toBeInstanceOf(Error); } }); it('Negative key value', function () { var currency = currency_class_1.Currency.fromKeys(-3.2, 62); expect(currency).toHaveProperty('keys', -3); expect(currency).toHaveProperty('metal', -12.44); expect(currency).toHaveProperty('metalInWeapons', -224); }); }); describe('toScrap', function () { it('Converts with conversion', function () { var currency = new currency_class_1.Currency({ keys: 12, metal: 32.66, }); expect(currency.toScrap(62)).toEqual(6990); }); it('Converts without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.66, }); expect(currency.toScrap()).toEqual(294); }); it('Throws an error because of no conversion', function () { try { var currency = new currency_class_1.Currency({ keys: 12, metal: 32.66, }); currency.toScrap(); expect(currency).not.toBeDefined(); } catch (e) { expect(e).toBeInstanceOf(Error); } }); it('Has weapon value', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.72, }); expect(currency.toScrap()).toEqual(294.5); }); it('Has negative value', function () { var currency = new currency_class_1.Currency({ keys: -1, metal: -32.72, }); expect(currency.toScrap(60)).toEqual(-834.5); }); }); describe('toKeys', function () { it('Converts with conversion', function () { var currency = new currency_class_1.Currency({ keys: 12, metal: 32.66, }); expect(currency.toKeys(62)).toEqual(12.53); }); it('Converts without conversion', function () { var currency = new currency_class_1.Currency({ keys: 13, metal: 0, }); expect(currency.toKeys()).toEqual(13); }); it('Throws an error because of no conversion', function () { try { var currency = new currency_class_1.Currency({ keys: 12, metal: 32.66, }); currency.toKeys(); expect(currency).not.toBeDefined(); } catch (e) { expect(e).toBeInstanceOf(Error); } }); it('Converts negative value', function () { var currency = new currency_class_1.Currency({ keys: -12, metal: -32.66, }); expect(currency.toKeys(62)).toEqual(-12.53); }); }); describe('toString', function () { it('Keys and metal', function () { expect(new currency_class_1.Currency({ keys: 12, metal: 53.22, }).toString()).toEqual('12 keys, 53.22 metal'); }); it('1 key', function () { expect(new currency_class_1.Currency({ keys: 1, metal: 0, }).toString()).toEqual('1 key'); }); it('Just metal', function () { expect(new currency_class_1.Currency({ keys: 0, metal: 53.22, }).toString()).toEqual('53.22 metal'); }); it('0 keys, 0 metal', function () { expect(new currency_class_1.Currency({ keys: 0, metal: 0, }).toString()).toEqual('0 keys, 0 metal'); }); it('Has weapon value #1', function () { expect(new currency_class_1.Currency({ keys: 0, metalInWeapons: 101, }).toString()).toEqual('5.61 metal'); }); it('Has weapon value #2', function () { expect(new currency_class_1.Currency({ keys: 0, metalInWeapons: 1, }).toString()).toEqual('0.05 metal'); }); it('Has weapon value #3', function () { expect(new currency_class_1.Currency({ keys: 0, metalInWeapons: 261, }).toString()).toEqual('14.49 metal'); }); it('Has weapon value #3', function () { expect(new currency_class_1.Currency({ keys: 0, metalInWeapons: 265, }).toString()).toEqual('14.72 metal'); }); }); describe('toJSON', function () { it('Converts via JSON.stringify', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(JSON.parse(JSON.stringify(currency))).toEqual({ keys: 53, metal: 32.11, }); }); }); describe('toWeaponizedJSON', function () { it('Gives correct form', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 10, }); expect(currency.toWeaponizedJSON()).toEqual({ keys: 53, metalInWeapons: 10, }); }); }); describe('addScrap', function () { it('Adds with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.addScrap(365, 60); expect(currency).toHaveProperty('keys', 54); expect(currency).toHaveProperty('metal', 12.66); expect(currency).toHaveProperty('metalInWeapons', 228); }); it('Adds without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.addScrap(365); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 72.66); expect(currency).toHaveProperty('metalInWeapons', 1308); }); it('Adds with weapon value', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.addScrap(365.5, 60); expect(currency).toHaveProperty('keys', 54); expect(currency).toHaveProperty('metal', 12.72); expect(currency).toHaveProperty('metalInWeapons', 229); }); it('Adds negative value', function () { var currency = new currency_class_1.Currency({ keys: -53, metal: -32.11, }); currency.addScrap(-365.5, 60); expect(currency).toHaveProperty('keys', -54); expect(currency).toHaveProperty('metal', -12.72); expect(currency).toHaveProperty('metalInWeapons', -229); }); }); describe('addMetal', function () { it('Adds with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.addMetal(40.55, 60); expect(currency).toHaveProperty('keys', 54); expect(currency).toHaveProperty('metal', 12.66); expect(currency).toHaveProperty('metalInWeapons', 228); }); it('Adds without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.addMetal(40.55); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 72.66); expect(currency).toHaveProperty('metalInWeapons', 1308); }); it('Adds with weapon value', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.addMetal(40.61); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 72.72); expect(currency).toHaveProperty('metalInWeapons', 1309); }); it('Adds negative value', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: -32.11, }); currency.addMetal(-40.61); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', -72.72); expect(currency).toHaveProperty('metalInWeapons', -1309); }); }); describe('addKeys', function () { it('Adds with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.addKeys(1.6, 60); expect(currency).toHaveProperty('keys', 55); expect(currency).toHaveProperty('metal', 8.11); expect(currency).toHaveProperty('metalInWeapons', 146); }); it('Adds negative value', function () { var currency = new currency_class_1.Currency({ keys: -53, metal: -32.11, }); currency.addKeys(-1.6, 60); expect(currency).toHaveProperty('keys', -55); expect(currency).toHaveProperty('metal', -8.11); expect(currency).toHaveProperty('metalInWeapons', -146); }); }); describe('addCurrency', function () { it('Adds with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.addCurrency({ keys: 3, metal: 30.55, }, 60); expect(currency).toHaveProperty('keys', 57); expect(currency).toHaveProperty('metal', 2.66); expect(currency).toHaveProperty('metalInWeapons', 48); }); it('Adds without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.addCurrency({ keys: 0, metal: 30.55, }); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 62.66); expect(currency).toHaveProperty('metalInWeapons', 1128); }); it('Adds with weapon value', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.addCurrency({ keys: 0, metal: 30.61, }); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 62.72); expect(currency).toHaveProperty('metalInWeapons', 1129); }); it('Adds negative currency', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: -32.11, }); currency.addCurrency({ keys: 0, metal: -30.61, }); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', -62.72); expect(currency).toHaveProperty('metalInWeapons', -1129); }); }); describe('removeWeapons', function () { it('Removes without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metalInWeapons: 10, }); expect(currency.removeWeapons(5).toWeaponizedJSON()).toEqual({ keys: 0, metalInWeapons: 5, }); }); it('Removes with conversion', function () { var currency = new currency_class_1.Currency({ keys: 12, metalInWeapons: 10, }); expect(currency.removeWeapons(5, 50).toWeaponizedJSON()).toEqual({ keys: 12, metalInWeapons: 5, }); }); }); describe('removeScrap', function () { it('Removes with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.removeScrap(365, 60); expect(currency).toHaveProperty('keys', 52); expect(currency).toHaveProperty('metal', 51.55); expect(currency).toHaveProperty('metalInWeapons', 928); }); it('Removes without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.removeScrap(288); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 0.11); expect(currency).toHaveProperty('metalInWeapons', 2); }); it('Throws for no conversion', function () { var err; try { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.removeScrap(365); } catch (e) { err = e; } expect(err).toBeInstanceOf(Error); }); it('Removes with weapon value', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.removeScrap(365.5, 60); expect(currency).toHaveProperty('keys', 52); expect(currency).toHaveProperty('metal', 51.49); expect(currency).toHaveProperty('metalInWeapons', 927); }); it('Removes negative value', function () { var currency = new currency_class_1.Currency({ keys: -53, metal: -32.11, }); currency.removeScrap(-365, 60); expect(currency).toHaveProperty('keys', -52); expect(currency).toHaveProperty('metal', -51.55); expect(currency).toHaveProperty('metalInWeapons', -928); }); }); describe('removeMetal', function () { it('Removes with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.removeMetal(40.55, 60); expect(currency).toHaveProperty('keys', 52); expect(currency).toHaveProperty('metal', 51.55); expect(currency).toHaveProperty('metalInWeapons', 928); }); it('Removes without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.removeMetal(32); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 0.11); expect(currency).toHaveProperty('metalInWeapons', 2); }); it('Removes with weapon value', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.removeMetal(32.05); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 0.05); expect(currency).toHaveProperty('metalInWeapons', 1); }); }); describe('removeKeys', function () { it('Removes with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.removeKeys(3.6, 60); expect(currency).toHaveProperty('keys', 49); expect(currency).toHaveProperty('metal', 56.11); expect(currency).toHaveProperty('metalInWeapons', 1010); }); }); describe('removeCurrency', function () { it('Removes with conversion', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); currency.removeCurrency({ keys: 2, metal: 36, }, 60); expect(currency).toHaveProperty('keys', 50); expect(currency).toHaveProperty('metal', 56.11); expect(currency).toHaveProperty('metalInWeapons', 1010); }); it('Removes without conversion', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.removeCurrency({ keys: 0, metal: 31, }); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 1.11); expect(currency).toHaveProperty('metalInWeapons', 20); }); it('Throws for no keys', function () { var err; try { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.removeCurrency({ keys: 2, metal: 31, }); } catch (e) { err = e; } expect(err).toBeInstanceOf(Error); }); it('Removes with weapon value', function () { var currency = new currency_class_1.Currency({ keys: 0, metal: 32.11, }); currency.removeCurrency({ keys: 0, metal: 31.05, }); expect(currency).toHaveProperty('keys', 0); expect(currency).toHaveProperty('metal', 1.05); expect(currency).toHaveProperty('metalInWeapons', 19); }); }); describe('isEqual', function () { it('Returns same result as isEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isEqual({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isEqual)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isBigger', function () { it('Returns same result as isBigger helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isBigger({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isBigger)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isSmaller', function () { it('Returns same result as isSmaller helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isSmaller({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isSmaller)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isBiggerOrEqual', function () { it('Returns same result as isBiggerOrEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isBiggerOrEqual({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isBiggerOrEqual)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isSmallerOrEqual', function () { it('Returns same result as isSmallerOrEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isSmallerOrEqual({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isSmallerOrEqual)(currency, { keys: 53, metal: 32.11, })); }); }); describe('clone', function () { it('Clones the object', function () { var currency = new currency_class_1.Currency({ keys: 50, metal: 20, }); var cloneCurrency = currency.clone(); expect(cloneCurrency).toEqual(currency); expect(cloneCurrency).toBeInstanceOf(currency_class_1.Currency); }); }); describe('isEmpty', function () { it('Is empty', function () { expect(new currency_class_1.Currency({ keys: 0, metal: 0, }).isEmpty()).toEqual(true); }); it('Is not empty #1', function () { expect(new currency_class_1.Currency({ keys: -1, metal: -20, }).isEmpty()).toEqual(false); }); it('Is not empty #2', function () { expect(new currency_class_1.Currency({ keys: 2, metal: 0, }).isEmpty()).toEqual(false); }); }); describe('w', function () { describe('isEqual', function () { it('Returns same result as isEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 32, }); expect(currency.wIsEqual({ keys: 53, metalInWeapons: 32, })).toEqual(currency_helper_1.w.isEqual(currency, { keys: 53, metalInWeapons: 32, })); }); }); describe('isBigger', function () { it('Returns same result as isBigger helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isBigger({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isBigger)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isSmaller', function () { it('Returns same result as isSmaller helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isSmaller({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isSmaller)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isBiggerOrEqual', function () { it('Returns same result as isBiggerOrEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isBiggerOrEqual({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isBiggerOrEqual)(currency, { keys: 53, metal: 32.11, })); }); }); describe('isSmallerOrEqual', function () { it('Returns same result as isSmallerOrEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.isSmallerOrEqual({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.isSmallerOrEqual)(currency, { keys: 53, metal: 32.11, })); }); }); describe('compareTo', function () { it('Returns same result as compareTo helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metal: 32.11, }); expect(currency.compareTo({ keys: 53, metal: 32.11, })).toEqual((0, currency_helper_1.compareTo)(currency, { keys: 53, metal: 32.11, })); }); }); describe('wIsBigger', function () { it('Returns same result as w.isBigger helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 11, }); expect(currency.wIsBigger({ keys: 53, metalInWeapons: 12, })).toEqual(currency_helper_1.w.isBigger(currency, { keys: 53, metalInWeapons: 12, })); }); }); describe('wIsSmaller', function () { it('Returns same result as w.isSmaller helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 11, }); expect(currency.wIsSmaller({ keys: 53, metalInWeapons: 12, })).toEqual(currency_helper_1.w.isSmaller(currency, { keys: 53, metalInWeapons: 12, })); }); }); describe('wIsBiggerOrEqual', function () { it('Returns same result as w.isBiggerOrEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 11, }); expect(currency.wIsBiggerOrEqual({ keys: 53, metalInWeapons: 12, })).toEqual(currency_helper_1.w.isBiggerOrEqual(currency, { keys: 53, metalInWeapons: 12, })); }); }); describe('wIsSmallerOrEqual', function () { it('Returns same result as w.isSmallerOrEqual helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 11, }); expect(currency.wIsSmallerOrEqual({ keys: 53, metalInWeapons: 12, })).toEqual(currency_helper_1.w.isSmallerOrEqual(currency, { keys: 53, metalInWeapons: 12, })); }); }); describe('wCompareTo', function () { it('Returns same result as w.compareTo helper', function () { var currency = new currency_class_1.Currency({ keys: 53, metalInWeapons: 11, }); expect(currency.wCompareTo({ keys: 53, metalInWeapons: 12, })).toEqual(currency_helper_1.w.compareTo(currency, { keys: 53, metalInWeapons: 12, })); }); }); }); });