Commit 946311af authored by Laurent's avatar Laurent

Koha: fetch holds

parent a257b11b
import {PortalAdapter} from './adapter';
import * as cheerio from 'cheerio';
import {Account, Loan} from '../../models';
import {Account, Loan, Hold} from '../../models';
import {WrongLoginPassword} from './wrong-login-password';
export class Koha extends PortalAdapter {
......@@ -106,16 +106,57 @@ export class Koha extends PortalAdapter {
let datas = $('table#checkoutst tbody tr');
datas.each((i, elem) => {
let loanNode = $(elem);
let title = loanNode.find('td.title a').text().trim();
let author = loanNode.find('td.author').text().trim();
let date_due = loanNode.find('td.date_due span[title]').attr('title').substring(0, 10);
let loan_node = $(elem);
let title = loan_node.find('td.title a').text().trim();
let record_id = loan_node.find('td.title a').attr('href').split('biblionumber=')[1];
let author = loan_node.find('td.author').text().trim();
let date_due = loan_node.find('td.date_due span[title]').attr('title').substring(0, 10);
loans.push( new Loan()
.setTitle(title)
.setAuthor(author)
.setDateDue(date_due));
.setDateDue(date_due)
.setRecordId(record_id)
.setRecordUrl(account.getUrl() + '/cgi-bin/koha/opac-detail.pl?biblionumber=' + record_id)
);
});
return loans;
}
protected _fetchHolds(account: Account): Promise<Array<Hold>> {
return this
.request(account,
{ url: account.getUrl() + '/cgi-bin/koha/opac-user.pl' })
.then( (response) => { return this._parseHoldsPage(account, response)});
}
protected _parseHoldsPage(account: Account, response): Array<Hold> {
let $ = cheerio.load(response.content.toString());
let holds: Array<Hold> = new Array<Hold>();
let datas = $('table#holdst tbody tr');
datas.each((i, elem) => {
let hold_node = $(elem);
hold_node.find('.tdlabel').remove();
let title_node = hold_node.find('td.title');
let record_id = title_node.find('a').attr('href').split('biblionumber=')[1];
let title = title_node.find('a').text().trim();
title_node.find('a').remove();
let author = title_node.text().trim();
holds.push( new Hold()
.setTitle(title)
.setAuthor(author)
.setLibrary(hold_node.find('td.branch').text().trim())
.setStatus(hold_node.find('td.status').text().trim())
.setRecordId(record_id)
.setRecordUrl(account.getUrl() + '/cgi-bin/koha/opac-detail.pl?biblionumber=' + record_id)
);
});
return holds;
}
}
......@@ -145,9 +145,12 @@ export class OrpheeMedia extends PortalAdapter {
protected _requestWorkaroundCookies(account: Account, options: any): Promise<http.HttpResponse> {
options.dontFollowRedirects = true;
options.headers['Cookie'] = (new Cookies()).getCookies().map( (cookie) => {
let cookies_header = (new Cookies()).getCookies().map( (cookie) => {
return cookie.toString();
});
if (cookies_header.length > 0)
options.headers['Cookie'] = cookies_header;
return this
.request(account, options)
......
......@@ -143,6 +143,74 @@ abstract class KohaWithSuccessfulLogin extends HTTPScenario {
</div>\
</form>');
}
public holdsPage(): string {
return this._encapsulate('\
<table id="holdst" class="table table-bordered table-striped dataTable no-footer" role="grid">\
<caption>Réservations <span class="count">(1 en tout)</span></caption>\
<thead>\
<tr role="row"><th class="anti-the sorting" tabindex="0" aria-controls="holdst" rowspan="1" colspan="1" style="width: 0px;" aria-label="Titre: activate to sort column ascending">Titre</th><th class="psort title-string sorting_asc" tabindex="0" aria-controls="holdst" rowspan="1" colspan="1" style="width: 0px;" aria-sort="ascending" aria-label="Commandé le: activate to sort column ascending">Commandé le</th><th class="title-string sorting" tabindex="0" aria-controls="holdst" rowspan="1" colspan="1" style="width: 0px;" aria-label="Expire le: activate to sort column ascending">Expire le</th><th class="sorting" tabindex="0" aria-controls="holdst" rowspan="1" colspan="1" style="width: 0px;" aria-label="Site de retrait: activate to sort column ascending">Site de retrait</th><th class="sorting" tabindex="0" aria-controls="holdst" rowspan="1" colspan="1" style="width: 0px;" aria-label="Statut: activate to sort column ascending">Statut</th><th class="nosort sorting_disabled" rowspan="1" colspan="1" style="width: 0px;" aria-label="Suspendre">Suspendre</th><th class="nosort sorting_disabled" rowspan="1" colspan="1" style="width: 0px;" aria-label="Modifier">Modifier</th></tr>\
</thead>\
<tbody>\
<tr role="row" class="odd">\
<td class="title">\
<a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=4687">\
Harry Potter et la chambre des secrets T. 02\
</a>\
J K Rowling\
</td>\
<td class="reservedate sorting_1">\
<span title="2017-01-11">\
<span class="tdlabel">Réservé le&nbsp;:</span>\
11/01/2017\
</span>\
</td>\
<td class="expirationdate">\
<span title="0000-00-00">\
<span class="tdlabel">Expiration&nbsp;:</span>\
N\'expire jamais </span>\
</td>\
<td class="branch">\
<span class="tdlabel">Site de retrait&nbsp;:</span>\
Pukapuka\
</td>\
<td class="status">\
<span class="tdlabel">Statut:</span>\
En attente </td>\
<td>\
<a class="btn btn-link js-show" href="#suspendModal1424" role="button" data-toggle="modal"><i class="icon-pause"></i> Suspendre</a>\
<div id="suspendModal1424" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="suspendModal1424Label" aria-hidden="true">\
<form class="form-inline" action="/cgi-bin/koha/opac-modrequest-suspend.pl" method="post">\
<div class="modal-header">\
<button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>\
<h3 id="suspendModal1424Label">Suspendre vos réservations<i>Harry Potter et la chambre des secrets T. 02</i></h3>\
</div>\
<div class="modal-body">\
<input name="reserve_id" value="1424" type="hidden">\
<label for="suspend_until_1424">Suspendre jusqu\'au&nbsp;:</label>\
<input name="suspend_until" id="suspend_until_1424" class="suspend-until hasDatepicker" size="10" readonly=""><img class="ui-datepicker-trigger" src="/opac-tmpl/lib/famfamfam/silk/calendar.png" alt="..." title="...">\
<span class="dateformat">(JJ/MM/AAAA) </span>\
\
<p class="js-show" style="display: block;"><a href="#" onclick="document.getElementById(\'suspend_until_1424\').value=\'\';return false;">Effacer la date pour suspendre indéfiniment</a></p>\
<button class="btn btn-mini js-hide" type="submit" name="submit" style="display: none;">Suspendre</button>\
</div>\
<div class="modal-footer">\
<button class="btn btn-primary" type="submit" name="submit">Suspendre</button>\
<a href="#" data-dismiss="modal" aria-hidden="true" class="cancel">Annuler</a>\
</div>\
</form>\
</div> \
</td>\
<td class="modify">\
<form action="/cgi-bin/koha/opac-modrequest.pl" method="post">\
<input name="biblionumber" value="4687" type="hidden">\
<input name="reserve_id" value="1424" type="hidden">\
<button type="submit" name="submit" class="btn btn-mini btn-danger" onclick="return confirmDelete(MSG_CONFIRM_DELETE_HOLD);"><i class="icon-remove icon-white"></i> Annuler</button></form>\
</td>\
</tr></tbody>\
</table>');
}
}
......@@ -167,12 +235,14 @@ export class KohaUpdateCard extends KohaWithSuccessfulLogin {
}
export class KohaLoansWithSuccessfulLogin extends KohaWithSuccessfulLogin {
export class KohaLoansAndHoldsWithSuccessfulLogin extends KohaWithSuccessfulLogin {
public constructor(base_url: string) {
super(base_url);
this
.then({ url: base_url + '/cgi-bin/koha/opac-user.pl' },
{ content: this.accountPage() });;
{ content: this.accountPage() })
.then({ url: base_url + '/cgi-bin/koha/opac-user.pl' },
{ content: this.holdsPage() });
}
}
......
declare var describe, expect, it, before, beforeEach, chai: any;
import {Loan, Account, Database, WrongLoginPassword, Portal} from '../../models/';
import {Loan, Hold, Account, Database, WrongLoginPassword, Portal} from '../../models/';
import {Koha} from '../../models/portal/koha';
import {KohaSignInWithSuccessfulLogin,
KohaLoansWithSuccessfulLogin,
KohaLoansAndHoldsWithSuccessfulLogin,
KohaUpdateCard,
KohaWithLoginError} from './koha-fixtures';
......@@ -33,8 +33,8 @@ describe('Account on Koha', () => {
});
it('db should have three loans', () => {
let http = new KohaLoansWithSuccessfulLogin('http://koha.biblibre.fr');
it('db should have three loans and one hold', () => {
let http = new KohaLoansAndHoldsWithSuccessfulLogin('http://koha.biblibre.fr');
return adapter.setHTTP(http).refresh(account).then(() => {
let loans = db.findAll(Loan).sort((a, b) => {
return a.getDateDue().localeCompare(b.getDateDue());
......@@ -44,6 +44,17 @@ describe('Account on Koha', () => {
expect(loans[0].getTitle()).to.equals('La famille Rataton');
expect(loans[0].getAuthor()).to.equals('Romain Simon');
expect(loans[0].getDateDue()).to.equals('2017-07-06');
expect(loans[0].getRecordId()).to.equals('345');
expect(loans[0].getRecordUrl()).to.equals('http://koha.biblibre.fr/cgi-bin/koha/opac-detail.pl?biblionumber=345');
let holds = db.findAll(Hold);
expect(holds).to.have.lengthOf(1);
expect(holds[0].getTitle()).to.equals('Harry Potter et la chambre des secrets T. 02');
expect(holds[0].getAuthor()).to.equals('J K Rowling');
expect(holds[0].getLibrary()).to.equals('Pukapuka');
expect(holds[0].getStatus()).to.equals('En attente');
expect(holds[0].getRecordId()).to.equals('4687');
expect(holds[0].getRecordUrl()).to.equals('http://koha.biblibre.fr/cgi-bin/koha/opac-detail.pl?biblionumber=4687');
});
});
......
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