Skip to content

Commit

Permalink
fixed bug in stats zeta calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
NB10328 authored and NB10328 committed Nov 27, 2020
1 parent 60efba1 commit b6fd464
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swgoh-api-swgohgg",
"version": "0.0.5",
"version": "0.0.6",
"description": "SWGoH helper API for swgoh.gg",
"main": "index.js",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion swgohgg-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class SwgohGGApi {
result.chars.gear[unit.data.gear_level - 1]++;

// increase zeta count
result.chars.charZetas += unit.data.zeta_abilities.length;
result.chars.zetas += unit.data.zeta_abilities.length;
} else if (unit.data.combat_type == CombatTypeEnum.CombatTypeShip) {
// increase ship count
result.ships.count++;
Expand Down
42 changes: 12 additions & 30 deletions test/swgohgg-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
const { SwgohGGApi, AbilityTypeEnum, CombatTypeEnum } = require('../swgohgg-api');
const assert = require('assert');

// default api object
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

describe('Static methods', () => {
it('getToken', () => {
assert.strictEqual(SwgohGGApi.getToken('user', 'password'), 'dXNlcjpwYXNzd29yZA==');
Expand Down Expand Up @@ -60,6 +56,7 @@ describe('Static methods', () => {
assert.strictEqual(playerStats.chars.count, playerStats.chars.gear.reduce((accumulator, currentValue) => accumulator + currentValue));
assert.strictEqual(playerStats.chars.galacticLegendCount, 1);
assert.strictEqual(playerStats.chars.count, SwgohGGApi.getCharacterCount(player));
assert.strictEqual(playerStats.chars.zetas, 105);

assert.strictEqual(playerStats.ships.count, playerStats.ships.levels.reduce((accumulator, currentValue) => accumulator + currentValue));
assert.strictEqual(playerStats.ships.count, playerStats.ships.rarities.reduce((accumulator, currentValue) => accumulator + currentValue));
Expand All @@ -84,11 +81,10 @@ describe('Base methods', () => {
});

describe ('API foundation', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

it('fetchRetry(GET)', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

it('fetchRetry(GET)', () => {
const reply = api.fetchRetry('GET', 'https://postman-echo.com/get?foo1=bar1&foo2=bar2', undefined, 3);

const jsonReply = JSON.parse(reply.responseText);
Expand All @@ -98,20 +94,14 @@ describe ('API foundation', () => {
});

it('fetchRetry(POST)', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

const reply = api.fetchRetry('POST', 'https://postman-echo.com/post?hand=wave', undefined, 3);
const reply = api.fetchRetry('POST', 'https://postman-echo.com/post?hand=wave', undefined, 3);

const jsonReply = JSON.parse(reply.responseText);

assert.strictEqual(jsonReply.args.hand, 'wave');
});

it('fetchRetry(POST payload)', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

const reply = api.fetchRetry('POST', 'https://postman-echo.com/post', { id: 10, name: 'John' }, 3);

const jsonReply = JSON.parse(reply.responseText);
Expand All @@ -122,10 +112,11 @@ describe ('API foundation', () => {
});

describe('Local cache', () => {
it('fetchCharacters', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);
// default api object
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

it('fetchCharacters', () => {
const chars = api.fetchCharacters();

assert.strictEqual(chars.size > 0, true);
Expand All @@ -134,9 +125,6 @@ describe('Local cache', () => {
});

it('fetchShips', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

const ships = api.fetchShips();

assert.strictEqual(ships.size > 0, true);
Expand All @@ -145,9 +133,6 @@ describe('Local cache', () => {
});

it('fetchAbilities', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

const abilities = api.fetchAbilities();

assert.strictEqual(abilities.size > 0, true);
Expand All @@ -156,9 +141,6 @@ describe('Local cache', () => {
});

it('fetchGear', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

const gear = api.fetchGear();

assert.strictEqual(gear.size > 0, true);
Expand All @@ -169,9 +151,6 @@ describe('Local cache', () => {
});

it ('buildCache', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

api.buildCache();

assert.strictEqual(api.cache.characters.size > 0, true);
Expand Down Expand Up @@ -232,6 +211,9 @@ describe('Local cache', () => {
});

describe('API data', () => {
const config = require('../config.json');
const api = new SwgohGGApi(config.user, config.password);

it('getPlayer', () => {
const player = api.getPlayer('232669733');

Expand Down

0 comments on commit b6fd464

Please sign in to comment.