Skip to content

Commit

Permalink
OBG-1234 fix ui-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
max402 committed Jun 23, 2021
1 parent b13e8b2 commit 3e1267c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export class ConsentInitiateComponent implements OnInit {

this.sessionService.setRedirectCode(authorizationId, res.headers.get(ApiHeaders.REDIRECT_CODE));

let consent = {"consent":{"access":{"allPsd2":"ALL_ACCOUNTS_WITH_BALANCES"},"frequencyPerDay":4,"validUntil":"2021-06-18","recurringIndicator":true,"combinedServiceIndicator":false}};
this.sessionService.setConsentObject(authorizationId, consent);
this.sessionService.setConsentObject(authorizationId, res.body);
this.navigate(authorizationId, res.body);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Component, OnInit } from '@angular/core';
import {AccountDetails, AisAccountAccessInfo, AisConsentRequest} from '../../api';
import { AccountDetails, AisAccountAccessInfo, AisConsentRequest } from '../../api';
import { ActivatedRoute, Router } from '@angular/router';
import { AisService } from '../services/ais.service';
import { AccountStruct, RedirectStruct, RedirectType } from '../redirect-page/redirect-struct';
import { Consts, HeaderConfig } from '../../models/consts';
import { StorageService } from '../../services/storage.service';
import AllPsd2Enum = AisAccountAccessInfo.AllPsd2Enum;
import AvailableAccountsEnum = AisAccountAccessInfo.AvailableAccountsEnum;

@Component({
selector: 'app-list-accounts',
Expand Down Expand Up @@ -38,45 +37,54 @@ export class ListAccountsComponent implements OnInit {
const online = !this.storageService.isAfterRedirect() && !settings.cacheLoa;
this.storageService.setAfterRedirect(false);

let consent: AisConsentRequest = {
const consent: AisConsentRequest = {
access: {
allPsd2: AllPsd2Enum.ACCOUNTSWITHBALANCES
},
frequencyPerDay: settings.frequencyPerDay,
validUntil: settings.validUntil,
recurringIndicator: settings.recurringIndicator,
combinedServiceIndicator: settings.combinedServiceIndicator
}
};

this.aisService.getAccounts(this.bankId, settings.loa, JSON.stringify(consent), settings.withBalance, online, settings.consentRequiresAuthentication).subscribe((response) => {
switch (response.status) {
case 202:
this.storageService.setRedirect(
response.headers.get(HeaderConfig.HEADER_FIELD_REDIRECT_CODE),
response.headers.get(HeaderConfig.HEADER_FIELD_AUTH_ID),
response.headers.get(HeaderConfig.HEADER_FIELD_X_XSRF_TOKEN),
parseInt(response.headers.get(HeaderConfig.HEADER_FIELD_REDIRECT_X_MAX_AGE), 0),
RedirectType.AIS
);
const r = new RedirectStruct();
r.redirectUrl = encodeURIComponent(response.headers.get(HeaderConfig.HEADER_FIELD_LOCATION));
r.redirectCode = response.headers.get(HeaderConfig.HEADER_FIELD_REDIRECT_CODE);
r.bankId = this.bankId;
r.bankName = this.storageService.getBankName();
this.router.navigate(['redirect', JSON.stringify(r)], { relativeTo: this.route });
break;
case 200:
// this is added to register url where to forward
// if LoT is cancelled after redirect page is displayed
// to be removed when issue https://github.com/adorsys/open-banking-gateway/issues/848 is resolved
// or Fintech UI refactored
this.accounts = response.body.accounts;
const loa = [];
for (const accountDetail of this.accounts) {
loa.push(new AccountStruct(accountDetail.resourceId, accountDetail.iban, accountDetail.name));
}
this.storageService.setLoa(this.bankId, loa);
}
});
this.aisService
.getAccounts(
this.bankId,
settings.loa,
JSON.stringify(consent),
settings.withBalance,
online,
settings.consentRequiresAuthentication
)
.subscribe((response) => {
switch (response.status) {
case 202:
this.storageService.setRedirect(
response.headers.get(HeaderConfig.HEADER_FIELD_REDIRECT_CODE),
response.headers.get(HeaderConfig.HEADER_FIELD_AUTH_ID),
response.headers.get(HeaderConfig.HEADER_FIELD_X_XSRF_TOKEN),
parseInt(response.headers.get(HeaderConfig.HEADER_FIELD_REDIRECT_X_MAX_AGE), 0),
RedirectType.AIS
);
const r = new RedirectStruct();
r.redirectUrl = encodeURIComponent(response.headers.get(HeaderConfig.HEADER_FIELD_LOCATION));
r.redirectCode = response.headers.get(HeaderConfig.HEADER_FIELD_REDIRECT_CODE);
r.bankId = this.bankId;
r.bankName = this.storageService.getBankName();
this.router.navigate(['redirect', JSON.stringify(r)], { relativeTo: this.route });
break;
case 200:
// this is added to register url where to forward
// if LoT is cancelled after redirect page is displayed
// to be removed when issue https://github.com/adorsys/open-banking-gateway/issues/848 is resolved
// or Fintech UI refactored
this.accounts = response.body.accounts;
const loa = [];
for (const accountDetail of this.accounts) {
loa.push(new AccountStruct(accountDetail.resourceId, accountDetail.iban, accountDetail.name));
}
this.storageService.setLoa(this.bankId, loa);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ describe('ListAccountsComponent', () => {
const mockAccounts: HttpResponse<AccountList> = {} as HttpResponse<AccountList>;

spyOn(aisService, 'getAccounts')
.withArgs(bankId, loaRetrievalInformation, false, true, true)
.withArgs(bankId, loaRetrievalInformation, '', false, true, true)
.and.returnValue(of(mockAccounts));
expect(component.bankId).toEqual(bankId);
aisService.getAccounts(bankId, loaRetrievalInformation, false, true, true).subscribe((res) => {
aisService.getAccounts(bankId, loaRetrievalInformation, '', false, true, true).subscribe((res) => {
expect(res).toEqual(mockAccounts);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AisService } from '../services/ais.service';
import {AccountReport, AisAccountAccessInfo, AisConsentRequest} from '../../api';
import { AccountReport, AisAccountAccessInfo, AisConsentRequest } from '../../api';
import { RedirectStruct, RedirectType } from '../redirect-page/redirect-struct';
import { Consts, HeaderConfig } from '../../models/consts';
import { StorageService } from '../../services/storage.service';
Expand Down Expand Up @@ -39,18 +39,25 @@ export class ListTransactionsComponent implements OnInit {
const settings = this.storageService.getSettings();
const online = !this.storageService.isAfterRedirect() && !settings.cacheLot;

let consent: AisConsentRequest = {
const consent: AisConsentRequest = {
access: {
allPsd2: AllPsd2Enum.ACCOUNTSWITHBALANCES
},
frequencyPerDay: settings.frequencyPerDay,
validUntil: settings.validUntil,
recurringIndicator: settings.recurringIndicator,
combinedServiceIndicator: settings.combinedServiceIndicator
}
};

this.aisService
.getTransactions(this.bankId, this.accountId, settings.lot, JSON.stringify(consent), online, settings.consentRequiresAuthentication)
.getTransactions(
this.bankId,
this.accountId,
settings.lot,
JSON.stringify(consent),
online,
settings.consentRequiresAuthentication
)
.subscribe((response) => {
switch (response.status) {
case 202:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ describe('ListTransactionsComponent', () => {
const loTRetrievalInformation: LoTRetrievalInformation = LoTRetrievalInformation.FROM_TPP_WITH_AVAILABLE_CONSENT;

spyOn(aisService, 'getTransactions')
.withArgs(bankId, accountId, loTRetrievalInformation, true, true)
.withArgs(bankId, accountId, loTRetrievalInformation, '', true, true)
.and.returnValue(of(mockTransactions));
expect(component.bankId).toEqual(bankId);
aisService.getTransactions(bankId, accountId, loTRetrievalInformation, true, true).subscribe((res) => {
aisService.getTransactions(bankId, accountId, loTRetrievalInformation, '', true, true).subscribe((res) => {
expect(res).toEqual(mockTransactions);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ describe('AisService', () => {

it('should get accounts', () => {
const getAccountsSpy = spyOn(aisService, 'getAccounts');
aisService.getAccounts('1234', LoARetrievalInformation.FROM_TPP_WITH_AVAILABLE_CONSENT, true, false, true);
aisService.getAccounts('1234', LoARetrievalInformation.FROM_TPP_WITH_AVAILABLE_CONSENT, '', true, false, true);
expect(getAccountsSpy).toHaveBeenCalled();
});

it('should get transactions', () => {
const getTransactionsSpy = spyOn(aisService, 'getTransactions');
aisService.getTransactions('1234', 'xxxxxxxxxx', LoTRetrievalInformation.FROM_TPP_WITH_AVAILABLE_CONSENT, false, true);
aisService.getTransactions(
'1234',
'xxxxxxxxxx',
LoTRetrievalInformation.FROM_TPP_WITH_AVAILABLE_CONSENT,
'',
false,
true
);
expect(getTransactionsSpy).toHaveBeenCalled();
});
});
10 changes: 8 additions & 2 deletions fintech-examples/fintech-ui/src/app/bank/services/ais.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ export class AisService {
return toConvert.toISOString().split('T')[0];
}

getAccounts(bankId: string, loARetrievalInformation: LoARetrievalInformation, createConsentIfNone: string, withBalance: boolean, online: boolean,
authenticatePsu: boolean) {
getAccounts(
bankId: string,
loARetrievalInformation: LoARetrievalInformation,
createConsentIfNone: string,
withBalance: boolean,
online: boolean,
authenticatePsu: boolean
) {
const okurl = window.location.pathname;
const notOkUrl = okurl.replace(/account.*/, '');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Location } from '@angular/common';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { LoARetrievalInformation, LoTRetrievalInformation } from '../../models/consts';
import { StorageService } from '../../services/storage.service';
import { FinTechAccountInformationService} from "../../api";
import { FinTechAccountInformationService } from '../../api';

@Component({
selector: 'app-settings',
Expand Down

0 comments on commit 3e1267c

Please sign in to comment.