Skip to content

Commit

Permalink
Merge pull request #368 from Bendakh/fix/NoPossibilityToChangeTheLang…
Browse files Browse the repository at this point in the history
…uage

[TP-10326] Make language customizable
  • Loading branch information
achraf-dahech authored Oct 13, 2022
2 parents ebaa7b7 + 8fd4e6f commit e7e55a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/aggregator/services/aggregator.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppModule } from '../../app.module';
import { Connection } from '../interfaces/budget-insight.interface';
import { mockAccount, mockTransaction, mockCategory } from '../interfaces/budget-insight-mock';
import { AggregatorService } from './aggregator.service';
import { BudgetInsightClient } from './budget-insight/budget-insight.client';
import { BudgetInsightClient, ClientConfig } from './budget-insight/budget-insight.client';

describe('AggregatorService', () => {
let service: AggregatorService;
Expand Down Expand Up @@ -97,6 +97,20 @@ describe('AggregatorService', () => {
);
});

it('should create the webviewUrl base on the callbackUrl with a custom language', () => {
const config: ClientConfig = {
clientId: 'budgetInsightClientId',
clientSecret: 'budgetInsightClientSecret',
baseUrl: 'https://fake-budget-insights.com/2.0',
language: 'en',
};

const url: string = service.generateRedirectUrl('callbackUrl', config);
expect(url).toBe(
'https://fake-budget-insights.com/2.0/auth/webview/en/connect?client_id=budgetInsightClientId&redirect_uri=callbackUrl&response_type=code&state=&types=banks',
);
});

it('should get the accounts', async () => {
const spy = jest.spyOn(client, 'fetchBankAccounts').mockReturnValue(Promise.resolve([mockAccount]));
const token = 'token';
Expand Down
4 changes: 3 additions & 1 deletion src/aggregator/services/aggregator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export class AggregatorService {
public generateRedirectUrl(callbackUrl: string, clientConfig?: ClientConfig): string {
const config: ClientConfig = this.budgetInsightClient.getClientConfig(clientConfig);

return `${config.baseUrl}/auth/webview/fr/connect?client_id=${config.clientId}&redirect_uri=${callbackUrl}&response_type=code&state=&types=banks`;
const language = config.language ?? 'fr';

return `${config.baseUrl}/auth/webview/${language}/connect?client_id=${config.clientId}&redirect_uri=${callbackUrl}&response_type=code&state=&types=banks`;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ClientConfig {
clientSecret: string;
baseUrl: string;
nbOfMonths?: number;
language?: string;
}

/**
Expand Down

0 comments on commit e7e55a8

Please sign in to comment.