Skip to content

Commit

Permalink
Merge pull request #92 from hunterjm/develop
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
hunterjm authored Feb 6, 2017
2 parents b9eca61 + 28cb105 commit d2f9015
Show file tree
Hide file tree
Showing 10 changed files with 7,884 additions and 275 deletions.
14 changes: 11 additions & 3 deletions app/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ export function login(account, tfCb = () => {}, captchaCb = () => {}) {
return async dispatch => {
try {
const apiClient = init(account, tfCb, captchaCb);
await apiClient.login();
const user = await apiClient.login();
metrics.track('Successful Login');
dispatch(getCredits(account.email));
dispatch(getPilesize(account.email));
dispatch(setCredits(user.userInfo.credits));
const piles = {
2: 'tradepile',
4: 'watchlist',
};
for (const { key, value } of user.pileSizeClientData.entries) {
if (piles[key] !== undefined) {
dispatch(setPilesize(piles[key], value));
}
}
dispatch(push('/players'));
} catch (e) {
// this.setState({ twoFactor: false, loading: false, errors: { detail: e.message } });
Expand Down
5 changes: 4 additions & 1 deletion app/actions/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export function snipe(player, settings) {
state.bid.bidding
// We have enough credits
&& state.account.credits > settings.minCredits
&& state.account.credits > trade.buyNowPrice
// The buy price is the gte the BIN price
&& player.price.buy >= trade.buyNowPrice
// We are below our cap for this player
&& _.get(state, `bid.listed.${player.id}`, 0) < settings.maxCard
// The card has at least one contract
Expand Down Expand Up @@ -195,7 +198,7 @@ export function placeBid(player, settings) {
}

// Make sure we aren't trying to spend more than we want to
if (bid <= player.price.buy) {
if (bid <= player.price.buy && bid <= state.account.credits) {
// Bid!
let tradeResult = {};
try {
Expand Down
5 changes: 3 additions & 2 deletions app/actions/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function bidCycle() {
let state = getState();

// Get unassigned and watchlist here only on first cycle
if (state.bid.cycles === 0) {
if (state.bid.cycles % 10 === 0) {
await dispatch(bidActions.getUnassigned(state.account.email));
await dispatch(bidActions.getWatchlist(state.account.email));
state = getState();
Expand Down Expand Up @@ -69,7 +69,6 @@ export function bidCycle() {
)));

// Only bid if we don't already have a full trade pile and don't own too many of this player
dispatch(bidActions.setBINStatus(!!state.bid.unassigned.length));
if (
state.bid.bidding
&& state.bid.tradepile.length < state.account.pilesize.tradepile
Expand Down Expand Up @@ -101,6 +100,8 @@ export function bidCycle() {
}

// buy now goes directly to unassigned now
state = getState();
dispatch(bidActions.setBINStatus(!!state.bid.unassigned.length));
await dispatch(bidActions.binNowToUnassigned());

// Log sold items
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Account extends Component {
() => {}
);
} catch (e) {
this.setState({ loading: false, errors: { detail: e.message } });
this.setState({ loading: false, twoFactor: false, errors: { detail: e.message } });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fifa-autobuyer",
"productName": "FIFA Autobuyer",
"version": "0.2.2",
"version": "0.3.0",
"description": "Autobuyer for FIFA 17 Ultimate Team",
"main": "./main.js",
"author": {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fifa-autobuyer",
"productName": "FIFA Autobuyer",
"version": "0.2.2",
"version": "0.3.0",
"description": "Autobuyer for FIFA 17 Ultimate Team",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -141,7 +141,6 @@
"minimist": "^1.2.0",
"mocha": "^3.2.0",
"mockery": "^2.0.0",
"nock": "^8.0.0",
"nyc": "^10.0.0",
"react-addons-test-utils": "^15.4.1",
"redux-logger": "^2.7.4",
Expand All @@ -163,7 +162,7 @@
"electron-auto-updater": "^0.9.2",
"electron-debug": "^1.1.0",
"font-awesome": "^4.7.0",
"fut-promise": "^1.0.0",
"fut-promise": "^1.1.0",
"highcharts": "^5.0.6",
"jquery": "^3.1.1",
"lodash": "^4.16.3",
Expand Down
34 changes: 22 additions & 12 deletions test/actions/account.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable no-unused-expressions */
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import sinon from 'sinon';
import nock from 'nock';
import { expect } from 'chai';
import { mockLogin } from '../mocks/login';
import Fut from 'fut-promise';
import * as ApiUtil from '../../app/utils/ApiUtil';
import * as actions from '../../app/actions/account';
import * as types from '../../app/actions/accountTypes';
Expand Down Expand Up @@ -46,17 +44,26 @@ describe('actions', () => {
});
afterEach(() => {
sandbox.restore();
nock.cleanAll();
});

it('should route to /players when login was success', async () => {
mockLogin();
const getPilesizeStub = sandbox.stub()
.returns({ entries: [{ key: 2, value: 30 }, { key: 4, value: 30 }] });
const getCreditsStub = sandbox.stub().returns({ credits: 1000 });
sandbox.stub(ApiUtil, 'getApi').returns({
getPilesize: getPilesizeStub,
getCredits: getCreditsStub
const loginStub = sandbox.stub(Fut.prototype, 'login').returns({
pileSizeClientData: {
entries: [{
key: 2,
value: 30
}, {
key: 4,
value: 30
}, {
key: 6,
value: 15
}]
},
userInfo: {
credits: 10243,
feature: { trade: 2 },
}
});
const account = {
email,
Expand All @@ -67,6 +74,7 @@ describe('actions', () => {
const store = mockStore({ account });

await store.dispatch(actions.login(account));
expect(loginStub.calledOnce).to.eql(true);
expect(store.getActions()).to.include({
type: '@@router/CALL_HISTORY_METHOD',
payload: { method: 'push', args: ['/players'] }
Expand All @@ -91,7 +99,9 @@ describe('actions', () => {

it('should dispatch SET_PILESIZE when getPilesize is completed', async () => {
// Mock pilesize response
const response = { entries: [{ key: 2, value: 30 }, { key: 4, value: 30 }] };
const response = {
entries: [{ key: 2, value: 30 }, { key: 4, value: 30 }, { key: 6, value: 15 }]
};
const getPilesizeStub = sandbox.stub().returns(response);
const getApiStub = sandbox.stub(ApiUtil, 'getApi').returns({
getPilesize: getPilesizeStub
Expand Down
55 changes: 0 additions & 55 deletions test/mocks/api.js

This file was deleted.

163 changes: 0 additions & 163 deletions test/mocks/login.js

This file was deleted.

7,874 changes: 7,840 additions & 34 deletions test/mocks/search.js

Large diffs are not rendered by default.

0 comments on commit d2f9015

Please sign in to comment.