Skip to content

Commit

Permalink
Merge pull request #318 from meriamBenSassi/fix/redirect
Browse files Browse the repository at this point in the history
[FIX] Fix the fetching redirectUrl process
  • Loading branch information
meriamBenSassi authored Feb 7, 2022
2 parents da80dbf + 85e11cd commit 0088f47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
18 changes: 6 additions & 12 deletions src/aggregator/services/aggregator.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ describe('AggregatorService', () => {

describe('generateRedirectUrl', () => {
it('should not throw when the user already exists', async () => {
const errorConflict: Error & { code?: number } = new Error('user already exists');
errorConflict.code = HttpStatus.CONFLICT;
const errorConflict: Error & { response: { status: number } } = new Error('user already exists') as Error & {
response: { status: number };
};
errorConflict.response = { status: HttpStatus.CONFLICT };
const registerSpy = jest.spyOn(client, 'register').mockResolvedValueOnce(Promise.reject(errorConflict));
const authenticateSpy = jest.spyOn(client, 'authenticate').mockResolvedValueOnce({
access_token: 'access-token',
Expand Down Expand Up @@ -207,16 +209,8 @@ describe('AggregatorService', () => {
redirect_url: 'https://bridge/redirection-url',
});

await service.generateRedirectUrl(
customerMock.id,
'https://domain.com/call-back?param=1',
);
expect(connectItemSpy).toHaveBeenCalledWith(
'access-token',
"callzback",
undefined,
undefined,
);
await service.generateRedirectUrl(customerMock.id, 'https://domain.com/call-back?param=1');
expect(connectItemSpy).toHaveBeenCalledWith('access-token', 'callzback', undefined, undefined);
});
});

Expand Down
5 changes: 2 additions & 3 deletions src/aggregator/services/aggregator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export class AggregatorService {
try {
await this.bridgeClient.register(userAccount, clientConfig);
} catch (err) {
const error: Error & { code?: number } = err as Error & { code?: number };
const error: { response: { status: number } } = err as Error & { response: { status: number } };
// Ignore error conflict user already exists
if (error.code !== HttpStatus.CONFLICT) {
if (error.response.status !== HttpStatus.CONFLICT) {
throw error;
}
}
Expand All @@ -73,7 +73,6 @@ export class AggregatorService {
if (splittedCbUrl === undefined) {
throw new Error('No callbackUrl provided');
}

const lastUrlSegment: string = splittedCbUrl[splittedCbUrl.length - 1];
const lastUrlSegmentWithoutQueryParams: string = lastUrlSegment.split('?')[0];
const uuid: string = lastUrlSegmentWithoutQueryParams.replace(/-/g, 'z');
Expand Down
8 changes: 6 additions & 2 deletions src/aggregator/services/bridge/bridge.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ export class BridgeClient {
*/
public async connectItem(
accessToken: string,
context: string,
context?: string,
email?: string,
clientConfig?: ClientConfig,
): Promise<ConnectItemResponse> {
let url: string = `${config.bridge.baseUrl}/v2/connect/items/add/url?country=fr&context=${context}`;
let url: string = `${config.bridge.baseUrl}/v2/connect/items/add/url?country=fr`;

if (context !== undefined && context !== '') {
url += `&context=${context}`;
}

if (email !== undefined) {
url += `&prefill_email=${email}`;
Expand Down

0 comments on commit 0088f47

Please sign in to comment.