Commit 85457c4e authored by Laurent's avatar Laurent

fix Ermes error when thumbnail missing

parent 9fdee617
......@@ -89,23 +89,6 @@ export class Ermes extends PortalAdapter {
}
protected _parseLoansCSV(account, response): Array<Loan> {
let loans: Array<Loan> = new Array<Loan>()
let datas = papa.parse(response.content.toString(),
{delimiter:'',
skipEmptyLines:true})['data']
datas.shift()
datas.forEach((elem) => {
loans.push(new Loan()
.setTitle(elem[0])
.setAuthor(elem[1])
.setDateDue(elem[9].split('/').reverse().join('-')))
})
return loans
}
protected _fetchAccountPortalId(account: Account): Promise<any> {
if (account.credentials['portal_id'])
return Promise.resolve(account.credentials['portal_id'])
......@@ -172,16 +155,8 @@ export class Ermes extends PortalAdapter {
let record_id = record_search_id ? record_search_id[2] : ''
let loan_data = JSON.parse(node.find('.loan-data').text().trim() || '{}')
let author = node.find('.vignette_document img')
.attr('alt')
.split('|')
.slice(-1)[0]
.trim();
if (!author) {
author = node.find('.title[title] + p').text().split('.')[0].trim()
}
let author = this._parseAuthor(node);
let date_due = loan_data.DateRetour
? loan_data.DateRetour
: node.find('.dateretour .loan-info-value').text().trim().split(' ')[0].trim()
......@@ -202,6 +177,20 @@ export class Ermes extends PortalAdapter {
}
protected _parseAuthor(node): string {
let author = node.find('.vignette_document img').attr('alt');
if (author)
return author.split('|').slice(-1)[0].trim();
author = node.find('.title[title] + p').text();
if (author)
return author.split('.')[0].trim();
return '';
}
protected _fetchHolds(account): Promise<Array<Hold>> {
return this
._requestAccountCategory(account, 'Loans')
......@@ -237,14 +226,7 @@ export class Ermes extends PortalAdapter {
let hold_data = JSON.parse(node.find('.loan-data').text().trim() || '{}')
let author = node.find('.vignette_document img')
.attr('alt')
.split('|')
.slice(-1)[0]
.trim();
if (!author) {
author = node.find('.title[title] + p').text().split('.')[0].trim()
}
let author = this._parseAuthor(node);
let status = node.find('.whenavailableend').length
? L('hold_available')
......
This diff is collapsed.
......@@ -6,6 +6,7 @@ import {ErmesLoansWithSuccessfulLoginCSV,
ErmesSignInWithSuccessfulLogin,
ErmesOldSignInWithSuccessfulLogin,
ErmesWithLoginError,
ErmesPartialLoansWithSuccessfulLogin,
ErmesLoansWithSuccessfulLoginV1,
ErmesLoansWithSuccessfulLoginV2,
ErmesLoansWithSuccessfulLoginV3} from './ermes-fixtures'
......@@ -31,21 +32,6 @@ describe('Account on Ermes', () => {
describe('With successful Login scenario', () => {
// it('loans from CSV should save two loans in db', () => {
// let http = new ErmesLoansWithSuccessfulLoginCSV('http://ermes.fr', time)
// return adapter.setHTTP(http).refresh(account).then(() => {
// let loans = db.findAll(Loan).sort((a, b) => {
// return a.getDateDue().localeCompare(b.getDateDue())
// })
// expect(loans).to.have.lengthOf(2)
// expect(loans[0].getTitle()).to.equals('Copains')
// expect(loans[0].getAuthor()).to.equals('Stehr, Frédéric')
// expect(loans[0].getDateDue()).to.equals('2018-03-22')
// })
// })
it('sign in should set account label to Marco Polo', () => {
let http = new ErmesSignInWithSuccessfulLogin('http://ermes.fr', time)
return adapter.setHTTP(http).signIn(account).then(() => {
......@@ -136,6 +122,15 @@ describe('Account on Ermes', () => {
expect(holds[0].getRecordUrl()).to.equals('http://ermes.fr/Default/doc/ORPHEE/frOr1425701132/imagier-mouvemente');
})
})
it('with partial infos should not fail', () => {
let http = new ErmesPartialLoansWithSuccessfulLogin('http://ermes.fr', time)
return adapter.setHTTP(http).refresh(account).then(() => {
expect(account.findLoans(db)).to.have.lengthOf(1)
expect(account.findHolds(db)).to.have.lengthOf(1)
})
})
})
......
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