Commit 4d5eaee5 authored by Laurent's avatar Laurent

Iguana: fetch account label

parent 3f42646b
......@@ -21,6 +21,23 @@ export class IguanaV3 extends PortalAdapter {
}
public updateCard(account: Account): Promise<any> {
account.setCardNumber(account.credentials['login']);
return Promise.resolve();
}
protected _fetchAccountLabel(account: Account): Promise<string> {
return this
._soapRequest(account,
'UserDataSummary',
{ SessionId: account.credentials['session_id'] } )
.then( (datas: any) => {
return datas.UserDataSummaryResponse.UserDataSummaryResult.NickName['_text'];
});
}
protected _fetchLoans(account: Account): Promise<Array<Loan>> {
return this
._soapRequest(account,
......@@ -34,6 +51,10 @@ export class IguanaV3 extends PortalAdapter {
})
.then( (datas: any) => {
let items = datas.CurrentLoansResponse.CurrentLoansResult.Items.Item;
if (!items)
return new Array<Loan>();
return (Array.isArray(items) ? items : [items]).map( (item) => {
let title_parts = /([^\/]+)\/([^;]+)/.exec(item.Title._text);
......@@ -64,6 +85,9 @@ export class IguanaV3 extends PortalAdapter {
.then( (datas: any) => {
let items = datas.CurrentReservationsResponse.CurrentReservationsResult.Items.Item;
if (!items)
return new Array<Hold>();
return (Array.isArray(items) ? items : [items]).map( (item) => {
let title_parts = /([^:\/]+).*\/([^;]+)/.exec(item.Title._text);
......
declare var expect: any;
import {HTTPScenario} from './http-scenario';
export class IguanaV3LoansAndHoldsWithSuccessfulLogin extends HTTPScenario {
export class IguanaV3LSignInWithSuccessfulLogin extends HTTPScenario {
public constructor(base_url: string) {
super();
this.setup(base_url);
......@@ -18,6 +19,24 @@ export class IguanaV3LoansAndHoldsWithSuccessfulLogin extends HTTPScenario {
public setup(base_url:string) {
this
.setupSignIn(base_url)
.then({ url: base_url + '/iguana/Proxy.UserActivities.cls',
method: 'POST',
content: this.soapEnvelope('<UserDataSummary>'
+ '<SessionId>12345678</SessionId>'
+ '</UserDataSummary>'),
headers: {"Content-Type": "text/xml; charset=UTF-8",
SOAPAction: 'UserDataSummary'
}
},
{ content: this.userDataSummaryResponse() })
}
public setupSignIn(base_url: string) {
return this
.expect({ url: base_url },
{ content: this.homePage() })
......@@ -44,33 +63,9 @@ export class IguanaV3LoansAndHoldsWithSuccessfulLogin extends HTTPScenario {
{ content: '' }
)
.then({ url: base_url + '/iguana/Proxy.UserActivities.cls',
method: 'POST',
content: this.soapEnvelope('<CurrentLoans>'
+ '<SessionId>12345678</SessionId>'
+ '<Data><From>1</From><To>20</To></Data>'
+ '</CurrentLoans>'),
headers: {"Content-Type": "text/xml; charset=UTF-8",
SOAPAction: 'CurrentLoans'
}
},
{ content: this.loansResponse()})
.then({ url: base_url + '/iguana/Proxy.UserActivities.cls',
method: 'POST',
content: this.soapEnvelope('<CurrentReservations>'
+ '<SessionId>12345678</SessionId>'
+ '<Data><From>1</From><To>20</To></Data>'
+ '</CurrentReservations>'),
headers: {"Content-Type": "text/xml; charset=UTF-8",
SOAPAction: 'CurrentReservations'
}
},
{ content: this.holdsResponse()})
}
public checkCredentialsResponse(): string {
return this.soapEnvelope('<CheckCredentialsResponse xmlns="http://tempuri.org">'
+ '<CheckCredentialsResult>'
......@@ -92,15 +87,59 @@ export class IguanaV3LoansAndHoldsWithSuccessfulLogin extends HTTPScenario {
}
public userDataSummaryResponse(): string {
return this.soapEnvelope('<UserDataSummaryResponse xmlns="http://tempuri.org">'
+ '<UserDataSummaryResult>'
+ '<NickName>Polo Marco</NickName>'
+ '</UserDataSummaryResult>'
+ '</UserDataSummaryResponse>');
}
public homePage(): string{
return '<html>\
<head>\
<script>\
Vfocus.Settings.sessionID = "2pu4GQqnf0";\
<script>\
Vfocus.Settings.sessionID = "2pu4GQqnf0";\
</script>\
</head>\
<body></body>\
</html>';
}
}
export class IguanaV3LoansAndHoldsWithSuccessfulLogin extends IguanaV3LSignInWithSuccessfulLogin {
public setup(base_url:string) {
this
.setupSignIn(base_url)
.then({ url: base_url + '/iguana/Proxy.UserActivities.cls',
method: 'POST',
content: this.soapEnvelope('<CurrentLoans>'
+ '<SessionId>12345678</SessionId>'
+ '<Data><From>1</From><To>20</To></Data>'
+ '</CurrentLoans>'),
headers: {"Content-Type": "text/xml; charset=UTF-8",
SOAPAction: 'CurrentLoans'
}
},
{ content: this.loansResponse()})
.then({ url: base_url + '/iguana/Proxy.UserActivities.cls',
method: 'POST',
content: this.soapEnvelope('<CurrentReservations>'
+ '<SessionId>12345678</SessionId>'
+ '<Data><From>1</From><To>20</To></Data>'
+ '</CurrentReservations>'),
headers: {"Content-Type": "text/xml; charset=UTF-8",
SOAPAction: 'CurrentReservations'
}
},
{ content: this.holdsResponse()})
}
public loansResponse(): string {
......@@ -190,3 +229,41 @@ export class IguanaV3LoansAndHoldsWithSuccessfulLogin extends HTTPScenario {
</CurrentReservationsResponse>');
}
}
export class IguanaV3EmptyLoansAndHoldsWithSuccessfulLogin extends IguanaV3LoansAndHoldsWithSuccessfulLogin {
public loansResponse(): string {
return this.soapEnvelope('\
<CurrentLoansResponse xmlns="http://tempuri.org">\
<CurrentLoansResult>\
<Items>\
</Items>\
<RenewalAllowed>1</RenewalAllowed>\
<RenewalAdmCost>0</RenewalAdmCost>\
<TotalRecords>0</TotalRecords>\
<Sort>\
<SortBy>Title,LoanLocation,DueDate,DocType</SortBy>\
<SortCurrent>ATitle</SortCurrent>\
</Sort>\
</CurrentLoansResult>\
</CurrentLoansResponse>')
}
public holdsResponse(): string {
return this.soapEnvelope('\
<CurrentReservationsResponse xmlns="http://tempuri.org">\
<CurrentReservationsResult>\
<Items>\
</Items>\
<TotalRecords>0</TotalRecords>\
<Sort>\
<SortBy>Title,DocType</SortBy>\
<SortCurrent>ATitle</SortCurrent>\
</Sort>\
</CurrentReservationsResult>\
</CurrentReservationsResponse>');
}
}
......@@ -2,7 +2,9 @@ declare var describe, expect, it, before, beforeEach, chai: any
import {Loan, Hold, Account, Database, WrongLoginPassword, Portal} from '../../models/'
import {IguanaV3} from '../../models/portal/iguana-v3'
import {IguanaV3LoansAndHoldsWithSuccessfulLogin} from './iguana-v3-fixtures'
import {IguanaV3LSignInWithSuccessfulLogin,
IguanaV3EmptyLoansAndHoldsWithSuccessfulLogin,
IguanaV3LoansAndHoldsWithSuccessfulLogin} from './iguana-v3-fixtures'
......@@ -54,5 +56,22 @@ describe('Account on IguanaV3', () => {
expect(holds[1].getStatus()).to.equals(L('hold_not_available'))
})
})
it('db should have no loans and nor holds', () => {
let http = new IguanaV3EmptyLoansAndHoldsWithSuccessfulLogin('http://iguana.fr')
return new IguanaV3().setHTTP(http).refresh(account).then(() => {
expect(account.findLoans(db)).to.have.lengthOf(0)
expect(account.findHolds(db)).to.have.lengthOf(0)
})
})
it('label should be set to Marco Polo', () => {
let http = new IguanaV3LSignInWithSuccessfulLogin('http://iguana.fr');
return new IguanaV3().setHTTP(http).signIn(account).then(() => {
expect(account.label).to.equals('Polo Marco');
});
});
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment