Commit 3eff2988 authored by Laurent's avatar Laurent

WIP: Add adapter for new InMedia

parent dcee9cc0
......@@ -8,4 +8,5 @@ export {Koha} from './koha';
export {KohaCas} from './koha-cas';
export {InMedia} from './inmedia';
export {Symphony} from './symphony';
export {InMediaV2} from './inmedia-v2';
export {Autodetect} from './autodetect';
......@@ -37,6 +37,9 @@ export class InMediaV2 extends PortalAdapter {
protected _handleSignIn(account: Account, response: http.HttpResponse): Promise<any> {
if (response.statusCode == 401)
return Promise.reject(new WrongLoginPassword());
let datas = response.content.toJSON()
account.credentials['token'] = datas.token
account.beConnected()
......@@ -44,14 +47,44 @@ export class InMediaV2 extends PortalAdapter {
}
protected _fetchAccountSummary(account: Account): Promise<any> {
return this
.request(account,
{ url: account.getUrl() + '/in/rest/api/accountSummary',
headers: { authorization: 'Bearer ' + account.credentials['token'] }})
.then( (response) => {
return response.content.toJSON()
})
}
protected _fetchAccountLabel(account: Account): Promise<string> {
return this
._fetchAccountSummary(account)
.then( (datas) => {
return datas['name'];
})
}
public updateCard(account: Account): Promise<any> {
return this
._fetchAccountSummary(account)
.then( (datas) => {
let card = account.getCard()
card.setNumber(datas['subscriberId'])
card.setExpirationDate(this._formatDate(datas['expiryDate']))
})
}
public requestUser(account: Account, action: string): Promise<any> {
return this
.request(account,
{ url: account.getUrl() + '/in/rest/api/accountPage?type=' + action,
headers: { authorization: 'Bearer ' + account.credentials['token'] }})
.then( (response) => {
let datas = response.content.toJSON();
return datas;
return response.content.toJSON();
});
}
......@@ -61,13 +94,11 @@ export class InMediaV2 extends PortalAdapter {
.requestUser(account, 'loans&pageNo=1&pageSize=100')
.then( (datas) => {
return datas['items'].map( (loan) => {
let date_due = loan['data']['returnDate'];
return new Loan()
.setLoanId(loan['data']['seqNo'])
.setTitle(loan['data']['title'])
.setAuthor(loan['data']['author'])
.setDateDue([date_due.substr(0,4), date_due.substr(4,2), date_due.substr(6,2)].join('-'))
.setDateDue(this._formatDate(loan['data']['returnDate']))
.setLibrary(loan['data']['branch']['desc'])
.setRecordThumbnail(account.getUrl() + '/in/rest/Thumb/image?isPhysical=1&isbn=' + loan['data']['isbn13'])
})
......@@ -93,6 +124,13 @@ export class InMediaV2 extends PortalAdapter {
}
protected _formatDate(date: string): string {
return [date.substr(0,4),
date.substr(4,2),
date.substr(6,2)].join('-')
}
protected _holdStatus(code: string): string {
let codes = {RESV_NOT_AVAILABLE: L('hold_not_available'),
RESV_AVAILABLE: L('hold_available')};
......
......@@ -60,8 +60,8 @@ describe('AccountsController with one account in database', () => {
})
it('form selectedPortalIndex should be height', () => {
expect(account_form.get('selectedPortalIndex')).to.equal(8);
it('form selectedPortalIndex should be nine', () => {
expect(account_form.get('selectedPortalIndex')).to.equal(9);
})
......
......@@ -14,24 +14,28 @@ export class InMediaV2SignIn extends HTTPScenario {
content: 'locale=fr&username=marco&password=polo',
headers: {"Content-Type": "application/json"} },
{ content: JSON.stringify(
{"defaultBasketId":"basket:649934:default:",
"ilsUser":true,
"omnidexid":"9845",
"token":"zetoken",
"userid":"123456"}
)
})
{ content: this.authenticateJSON() })
}
public authenticateJSON(): string {
return JSON.stringify(
{"defaultBasketId":"basket:649934:default:",
"ilsUser":true,
"omnidexid":"9845",
"token":"zetoken",
"userid":"123456"}
);
}
public accountInfoJSON(): string {
return JSON.stringify(
{
"address1": "4 rue des fleurs",
"address1": "3 rue des papillons",
"address2": ".",
"address3": "MARSEILLE",
"birthDateYYYMMDD": "19820709",
"birthDateYYYMMDD": "19780405",
"branchCode": "LGR",
"categoryCode": "EN",
"cspCount": "0",
......@@ -48,7 +52,7 @@ export class InMediaV2SignIn extends HTTPScenario {
"hasLoanList": false,
"hasSugestionList": false,
"isExpired": true,
"lastName": "BEC",
"lastName": "POL",
"litigations": [
"",
"",
......@@ -65,10 +69,10 @@ export class InMediaV2SignIn extends HTTPScenario {
"postalCode": "13012",
"quarter": {
"can_opac": true,
"code": "9",
"code": "7",
"desc_dut": "",
"desc_eng": "",
"desc_fre": "9e arrondissement",
"desc_fre": "7e arrondissement",
"desc_ger": "",
"is_active": false
},
......@@ -78,7 +82,7 @@ export class InMediaV2SignIn extends HTTPScenario {
"schoolGroupCode": "",
"statusOk": "true",
"status_ok": "true",
"subscriberId": "E100987654321",
"subscriberId": "E34568234",
"subscriptionDate": "20151021",
"suggestionList": [],
"telephone": "",
......@@ -209,10 +213,13 @@ export class InMediaV2SignIn extends HTTPScenario {
export class InMediaV2AccountInfo extends InMediaV2SignIn {
public setup(base_url) {
this
.expect({ url: base_url + '/in/rest/api/accountSummary',
headers: {"authorization": "Bearer zetoken"} },
{ content: this.accountInfoJSON() })
super.setup(base_url);
this.expect({ url: base_url + '/in/rest/api/accountSummary',
headers: {"authorization": "Bearer zetoken"} },
{ content: this.accountInfoJSON() })
this.expect({ url: base_url + '/in/rest/api/accountSummary',
headers: {"authorization": "Bearer zetoken"} },
{ content: this.accountInfoJSON() })
}
}
......@@ -231,3 +238,20 @@ export class InMediaV2LoansAndHolds extends InMediaV2SignIn {
{ content: this.holdsJSON() })
}
}
export class InMediaV2WithLoginError extends InMediaV2SignIn {
public setup(base_url) {
this
.expect({ url: base_url + '/in/rest/api/authenticate',
method: "POST",
content: 'locale=fr&username=marco&password=polo',
headers: {"Content-Type": "application/json"} },
{ content: '',
statusCode: 401
})
}
}
declare var describe, expect, it, before, beforeEach, chai: any
import {Loan, Hold, Portal, Account, Database} from '../../models/'
import {Loan,
Hold,
Portal,
Account,
Database,
WrongLoginPassword} from '../../models/'
import {InMediaV2} from '../../models/portal/inmedia-v2'
import {InMediaV2SignIn,
InMediaV2WithLoginError,
InMediaV2AccountInfo,
InMediaV2LoansAndHolds} from './inmedia-v2-fixtures'
......@@ -54,5 +61,38 @@ describe('Account on InMedia V2', () => {
})
})
})
})
it('account label should be Marco Polo', () => {
let http = new InMediaV2AccountInfo('https://inmediav2.fr')
return new InMediaV2().setHTTP(http).signIn(account).then(() => {
expect(account.label).to.equals('POLO Marco');
})
})
it('with wrong credentials should raise wrong login password', () => {
let http = new InMediaV2WithLoginError('https://inmediav2.fr')
return new InMediaV2().setHTTP(http).refresh(account).then(
() => {
expect.fail('Error should be thrown');
},
(error) => {
error.should.be.an.instanceOf(WrongLoginPassword);
}
)
})
it('should have Portal.updateAccountInfo to setup card', () => {
let portal = new Portal();
portal.findAdapterIdentifiedBy('inmedia-v2').setHTTP(new InMediaV2AccountInfo('https://inmediav2.fr'));
return portal.signIn(account)
.then( () => { return portal.updateAccountInfo(account) })
.then( () => {
let card = account.getCard();
expect(card.getNumber()).to.equals('E34568234');
expect(card.getExpirationDate()).to.equals('2018-05-18');
});
})
})
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