Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyusung4698 committed Jul 28, 2020
2 parents ac398bc + 873de04 commit c698d8a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { BrowserModule } from '@angular/platform-browser';
import { AssetService } from '@app/assets';
import { TradeLeaguesHttpLeague } from '@data/poe/schema';
import { CurrencyOverviewHttpService } from './currency-overview-http.service';

describe('CurrencyOverviewHttpService', () => {
let sut: CurrencyOverviewHttpService;

beforeEach(async () => {
TestBed.configureTestingModule({
imports: [
CommonModule,
HttpClientModule,
BrowserModule
]
}).compileComponents();
sut = TestBed.inject<CurrencyOverviewHttpService>(CurrencyOverviewHttpService);
const asset = TestBed.inject<AssetService>(AssetService);
await asset.load().toPromise();
});

const leagueMap = {
[TradeLeaguesHttpLeague.Standard]: 'standard',
[TradeLeaguesHttpLeague.Hardcore]: 'hardcore',
['Harvest']: 'challenge',
['Hardcore Harvest']: 'challengehc',
};

Object.keys(leagueMap).forEach(key => {
it(`getLeaguePath('${key}') should be '${leagueMap[key]}'`, () => {
const result = sut.getLeaguePath(key);
expect(result).toBe(leagueMap[key]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { environment } from '@env/environment';
import { Observable, of, throwError } from 'rxjs';
import { delay, flatMap, retryWhen } from 'rxjs/operators';
import { CurrencyOverviewResponse } from '../schema/currency-overview';
import { OverviewHttpService } from './overview-http.service';

export enum CurrencyOverviewType {
Currency = 'Currency',
Expand All @@ -22,11 +23,13 @@ const RETRY_DELAY = 100;
@Injectable({
providedIn: 'root'
})
export class CurrencyOverviewHttpService {
export class CurrencyOverviewHttpService extends OverviewHttpService {
private readonly baseUrl: string;

constructor(
private readonly httpClient: HttpClient) {
private readonly httpClient: HttpClient
) {
super();
this.baseUrl = `${environment.poeNinja.baseUrl}/api/data/currencyoverview`;
}

Expand All @@ -48,7 +51,7 @@ export class CurrencyOverviewHttpService {

const result: CurrencyOverviewResponse = {
lines: response.lines,
url: `${environment.poeNinja.baseUrl}/challenge/${PATH_TYPE_MAP[type]}`
url: `${environment.poeNinja.baseUrl}/${this.getLeaguePath(leagueId)}/${PATH_TYPE_MAP[type]}`
};
return of(result);
})
Expand Down
38 changes: 38 additions & 0 deletions src/app/data/poe-ninja/service/item-overview-http.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CommonModule } from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { BrowserModule } from '@angular/platform-browser';
import { AssetService } from '@app/assets';
import { TradeLeaguesHttpLeague } from '@data/poe/schema';
import { ItemOverviewHttpService } from './item-overview-http.service';

describe('ItemOverviewHttpService', () => {
let sut: ItemOverviewHttpService;

beforeEach(async () => {
TestBed.configureTestingModule({
imports: [
CommonModule,
HttpClientModule,
BrowserModule
]
}).compileComponents();
sut = TestBed.inject<ItemOverviewHttpService>(ItemOverviewHttpService);
const asset = TestBed.inject<AssetService>(AssetService);
await asset.load().toPromise();
});

const leagueMap = {
[TradeLeaguesHttpLeague.Standard]: 'standard',
[TradeLeaguesHttpLeague.Hardcore]: 'hardcore',
['Harvest']: 'challenge',
['Hardcore Harvest']: 'challengehc',
};

Object.keys(leagueMap).forEach(key => {
it(`getLeaguePath('${key}') should be '${leagueMap[key]}'`, () => {
const result = sut.getLeaguePath(key);
expect(result).toBe(leagueMap[key]);
});
});
});
9 changes: 6 additions & 3 deletions src/app/data/poe-ninja/service/item-overview-http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { environment } from '@env/environment';
import { Observable, of, throwError } from 'rxjs';
import { delay, flatMap, retryWhen } from 'rxjs/operators';
import { ItemOverviewResponse } from '../schema/item-overview';
import { OverviewHttpService } from './overview-http.service';

export enum ItemOverviewType {
Prophecy = 'Prophecy',
Expand Down Expand Up @@ -52,11 +53,13 @@ const RETRY_DELAY = 100;
@Injectable({
providedIn: 'root'
})
export class ItemOverviewHttpService {
export class ItemOverviewHttpService extends OverviewHttpService {
private readonly baseUrl: string;

constructor(
private readonly httpClient: HttpClient) {
private readonly httpClient: HttpClient
) {
super();
this.baseUrl = `${environment.poeNinja.baseUrl}/api/data/itemoverview`;
}

Expand All @@ -78,7 +81,7 @@ export class ItemOverviewHttpService {

const result: ItemOverviewResponse = {
lines: response.lines,
url: `${environment.poeNinja.baseUrl}/challenge/${PATH_TYPE_MAP[type]}`
url: `${environment.poeNinja.baseUrl}/${this.getLeaguePath(leagueId)}/${PATH_TYPE_MAP[type]}`
};
return of(result);
})
Expand Down
18 changes: 18 additions & 0 deletions src/app/data/poe-ninja/service/overview-http.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TradeLeaguesHttpLeague } from '@data/poe/schema';

export abstract class OverviewHttpService {
protected getLeaguePath(leagueId: string): string {
switch (leagueId) {
case TradeLeaguesHttpLeague.Standard:
return 'standard';
case TradeLeaguesHttpLeague.Hardcore:
return 'hardcore';
default:
const exp = new RegExp(`${TradeLeaguesHttpLeague.Hardcore} .*`);
if (exp.exec(leagueId)) {
return 'challengehc';
}
return 'challenge';
}
}
}
1 change: 1 addition & 0 deletions src/app/data/poe/schema/trade-leagues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TradeHttpResponse } from './trade';

export enum TradeLeaguesHttpLeague {
Standard = 'Standard',
Hardcore = 'Hardcore',
}

export interface TradeLeaguesHttpResult {
Expand Down
14 changes: 9 additions & 5 deletions src/app/shared/module/poe/price/item-price-rates.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export class ItemPriceRatesProvider {
case ItemCategory.GemActivegem:
case ItemCategory.GemSupportGem:
case ItemCategory.GemSupportGemplus: {
const key = `${leagueId}_${ItemCategory.Gem}`;
return this.fetch(key, () => this.fetchItem(leagueId, ItemOverviewType.SkillGem));
}
const key = `${leagueId}_${ItemCategory.Gem}`;
return this.fetch(key, () => this.fetchItem(leagueId, ItemOverviewType.SkillGem));
}
case ItemCategory.MapScarab:
case ItemCategory.Leaguestone:
case ItemCategory.MonsterSample:
Expand Down Expand Up @@ -170,7 +170,7 @@ export class ItemPriceRatesProvider {
change: sparkLine.totalChange,
history: sparkLine.data,
chaosAmount: line.chaosEquivalent,
url: response.url
url: `${response.url}${this.getUrlSuffix(line.currencyTypeName)}`
};
return rate;
})
Expand Down Expand Up @@ -199,12 +199,16 @@ export class ItemPriceRatesProvider {
change: sparkLine.totalChange,
history: sparkLine.data,
chaosAmount: line.chaosValue,
url: response.url
url: `${response.url}${this.getUrlSuffix(line.name)}`
};
return rate;
})
};
return result;
}));
}

private getUrlSuffix(name: string): string {
return `?name=${encodeURIComponent(name)}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AssetService } from '@app/assets';
import { TradeChatParserService } from '.';
import { TradeParserType } from './trade-chat';

fdescribe('TradeChatParserService', () => {
describe('TradeChatParserService', () => {
let sut: TradeChatParserService;
beforeEach(async () => {
TestBed.configureTestingModule({
Expand Down

0 comments on commit c698d8a

Please sign in to comment.