Skip to content

Commit

Permalink
feat: make trade-location understand Xbox and Playstation realms (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbjorge committed Oct 4, 2022
1 parent 7514945 commit 817525b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/helpers/trade-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TradeLocation from 'better-trading/services/trade-location';
type PositionalParams = [{slug: string; type: string}];
interface NamedParams {
suffix?: string;
league: string;
league: string; // in non-PC realms, should be of form "realm/LeagueName", eg "xbox/Legion"
}

export default class TradeUrl extends Helper {
Expand Down
12 changes: 11 additions & 1 deletion app/services/trade-location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default class TradeLocation extends Service.extend(Evented) {
this.startLocationPolling();
}

// in non-PC realms, league should be of form "realm/LeagueName", eg "xbox/Legion"
getTradeUrl(type: string, slug: string, league: string) {
return [BASE_URL, type, league, slug].join('/');
}
Expand All @@ -97,7 +98,16 @@ export default class TradeLocation extends Service.extend(Evented) {
}

private parseCurrentPath(): ExactTradeLocationStruct {
const [type, league, slug, live] = window.location.pathname.replace('/trade/', '').split('/');
const tradeRealms = ['xbox', 'sony'];
const pathParts = window.location.pathname.replace('/trade/', '').split('/');
let type, league, slug, live;
if (tradeRealms.includes(pathParts[1])) {
let realm, leagueInRealm;
[type, realm, leagueInRealm, slug, live] = pathParts;
league = `${realm}/${leagueInRealm}`;
} else {
[type, league, slug, live] = pathParts;
}

return {
type: type || null,
Expand Down
4 changes: 2 additions & 2 deletions changelogs/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

## Improvements 💅

...
- Bookmarks are now supported for Xbox and Playstation players! Thanks @lesse83 for reporting that this didn't work prevoiusly ([#117](https://github.com/exile-center/better-trading/issues/117))!

## Bug fixes 🐛

- Fixed "equivalent pricing" currency icons looking squished when using the "default" (not "compact") trade view ([#114](https://github.com/exile-center/better-trading/issues/114)). Thanks @vvs for reporting the issue!
- Fixed "equivalent pricing" currency icons looking squished when using the "default" (not "compact") trade view. Thanks @vvs for reporting the issue ([#114](https://github.com/exile-center/better-trading/issues/114))!
54 changes: 51 additions & 3 deletions tests/unit/services/trade-location-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Unit | Services | TradeLocation', () => {
});
});

describe('get league', () => {
describe('get league (PC realm)', () => {
it('should returns the active league from the base URL', () => {
window.location.pathname = '/trade/search/Legion';

Expand All @@ -111,6 +111,32 @@ describe('Unit | Services | TradeLocation', () => {
});
});

describe('get league (non-PC realm)', () => {
it('should returns the active league from the base URL', () => {
window.location.pathname = '/trade/search/xbox/Legion';

expect(service.league).to.equal('xbox/Legion');
});

it('should returns the active league from a trade URL', () => {
window.location.pathname = '/trade/search/sony/Legion/q1w2e3r4t5';

expect(service.league).to.equal('sony/Legion');
});

it('should returns the active league from a bulk exchange URL', () => {
window.location.pathname = '/trade/exchange/xbox/Legion/q1w2e3r4t5';

expect(service.league).to.equal('xbox/Legion');
});

it('should returns the active league from a live search URL', () => {
window.location.pathname = '/trade/search/sony/Legion/q1w2e3r4t5/live';

expect(service.league).to.equal('sony/Legion');
});
});

describe('get slug', () => {
it('should handle the absence of a current trade', () => {
window.location.pathname = '/trade/search/Legion';
Expand All @@ -135,16 +161,38 @@ describe('Unit | Services | TradeLocation', () => {

expect(service.slug).to.equal('q1w2e3r4t5');
});

it('should returns the active trade slug from an Xbox realm trade URL', () => {
window.location.pathname = '/trade/search/xbox/Legion/q1w2e3r4t5/live';

expect(service.slug).to.equal('q1w2e3r4t5');
});

it('should returns the active trade slug from a Playstation realm live search URL', () => {
window.location.pathname = '/trade/search/sony/Legion/q1w2e3r4t5/live';

expect(service.slug).to.equal('q1w2e3r4t5');
});
});

describe('getTradeUrl', () => {
it('should forge the proper URL', () => {
window.location.pathname = '/trade/search/Legion/q1w2e3r4t5';

expect(service.getTradeUrl('search', 'foobar', 'some-league')).to.be.equal(
'https://www.pathofexile.com/trade/search/some-league/foobar'
);
});

it('should support Xbox realm', () => {
expect(service.getTradeUrl('search', 'foobar', 'xbox/some-league')).to.be.equal(
'https://www.pathofexile.com/trade/search/xbox/some-league/foobar'
);
});

it('should support Playstation realm', () => {
expect(service.getTradeUrl('search', 'foobar', 'sony/some-league')).to.be.equal(
'https://www.pathofexile.com/trade/search/sony/some-league/foobar'
);
});
});

describe('locationPollingTask', () => {
Expand Down

0 comments on commit 817525b

Please sign in to comment.