Skip to content

Commit

Permalink
Merge pull request #33 from tictactrip/fix/shifter
Browse files Browse the repository at this point in the history
Fix/shifter
  • Loading branch information
half-shell authored May 27, 2021
2 parents dbdfb2d + cd937c5 commit 1dff481
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions __tests__/unit/shifter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('Shifter', () => {
};

describe('#constructor', () => {
describe('when is not given a strategy with a single country', () => {
it('should throw an error if a strategy has been set without any countries', async () => {
describe('when is not given a mapping with a single country', () => {
it('should throw an error if a mapping has been set without any countries', async () => {
let error: Error;

try {
Expand Down
1 change: 1 addition & 0 deletions src/classes/providers/base/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpProxyAgent } from 'http-proxy-agent';
import { AxiosRequestConfig } from 'axios';

enum EStrategyMode {
MANUAL = 'MANUAL',
CHANGE_IP_EVERY_REQUESTS = 'CHANGE_IP_EVERY_REQUESTS',
}

Expand Down
6 changes: 4 additions & 2 deletions src/classes/providers/shifter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export class Shifter extends Base {
this.config = config;
this.strategy = config.strategy;

if (this.strategy && this.strategy.mode === EStrategyMode.CHANGE_IP_EVERY_REQUESTS) {
this.isCountryPortMappingEmpty(this.strategy.mapping);
this.isCountryPortMappingEmpty(this.strategy.mapping);

if (!this.strategy.mode) {
this.strategy.mode == EStrategyMode.CHANGE_IP_EVERY_REQUESTS;
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/classes/providers/shifter/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { AxiosRequestConfig } from 'axios';
import { IProviderConfig, EStrategyMode } from '../base/types';

type TShifterStrategy = TShifterStrategyChangeIpEveryRequest;

interface IShifterConfig {
proxy: IProviderConfig;
axiosConfig?: AxiosRequestConfig;
Expand Down Expand Up @@ -255,8 +253,8 @@ interface IShifterChangeIp {

type TShifterCountryPortMapping = Partial<Record<EShifterCountry, number[]>>;

type TShifterStrategyChangeIpEveryRequest = {
mode: EStrategyMode.CHANGE_IP_EVERY_REQUESTS;
type TShifterStrategy = {
mode?: EStrategyMode.CHANGE_IP_EVERY_REQUESTS | EStrategyMode.MANUAL;
mapping?: TShifterCountryPortMapping;
};

Expand Down

0 comments on commit 1dff481

Please sign in to comment.