Commit 1666364e authored by Laurent's avatar Laurent

start Primo adapter

parent b2e67007
......@@ -9,4 +9,5 @@ export {KohaCas} from './koha-cas';
export {InMedia} from './inmedia';
export {Symphony} from './symphony';
export {InMediaV2} from './inmedia-v2';
export {Primo} from './primo';
export {Autodetect} from './autodetect';
import {PortalAdapter} from './adapter';
import * as cheerio from 'cheerio';
import {Account, Loan} from '../../models';
import {WrongLoginPassword} from './wrong-login-password';
export class Primo extends PortalAdapter {
public getIdentifier():string {
return 'primo';
}
public getLabel():string {
return 'Primo';
}
public canHandleWebsite($): boolean {
return $('a[href*="libweb/action/login.do?loginFn=signin"]').length;
}
public _signIn(account): Promise<any> {
return Promise.resolve();
}
protected _fetchLoans(account: Account): Promise<Array<Loan>> {
return Promise.resolve(new Array<Loan>());
}
}
......@@ -60,8 +60,8 @@ describe('AccountsController with one account in database', () => {
})
it('form selectedPortalIndex should be nine', () => {
expect(account_form.get('selectedPortalIndex')).to.equal(9);
it('form selectedPortalIndex should be 10', () => {
expect(account_form.get('selectedPortalIndex')).to.equal(10);
})
......
......@@ -106,3 +106,14 @@ export class AutodetectKohaCASUL3 extends AutodetectScenario {
}
}
export class AutodetectPrimo extends AutodetectScenario {
public frontPage(): string {
return this._encapsulate('\
<a href="http://ulw.fr/primo_library/libweb/action/login.do?loginFn=signin&vid=BDL&targetURL=http%3a%2f%2fulw.fr%2fprimo_library%2flibweb%2faction%2fsearch.do%3fvid%3dBDL%26amp%3bdscnt%3d0%26amp%3bdstmp%3d1530957063545%26amp%3binitializeIndex%3dtrue">\
Se connecter\
</a>');
}
}
......@@ -8,7 +8,8 @@ import {AutodetectOrpheemedia,
AutodetectBokeh,
AutodetectKoha,
AutodetectKohaCASUL2,
AutodetectKohaCASUL3} from './autodetect-fixtures';
AutodetectKohaCASUL3,
AutodetectPrimo} from './autodetect-fixtures';
describe('Account with autodetect adapter', () => {
let adapter: Autodetect;
......@@ -119,4 +120,17 @@ describe('Account with autodetect adapter', () => {
expect(account.getAdapterIdentifier()).to.equals('koha-cas');
});
});
it('should detect KSup', () => {
return adapter
.setHTTP(new AutodetectPrimo('http://ulw.fr'))
.refresh(account).then(
() => {
expect.fail('WrongLoginPassword error should be thrown');
},
() => {
expect(account.getAdapterIdentifier()).to.equals('ksup');
});
});
});
import {HTTPScenario} from './http-scenario';
class PrimoWithSuccessfulLogin extends HTTPScenario {
public constructor(base_url: string) {
super();
this
.expect({ url: base_url },
{ content: this.frontPage() })
.then( { url: 'http://ulw.fr/primo_library/libweb/action/login.do?loginFn=signin&vid=BDL&targetURL=http%3a%2f%2fulw.fr%2fprimo_library%2flibweb%2faction%2fsearch.do%3fvid%3dBDL%26amp%3bdscnt%3d0%26amp%3bdstmp%3d1530957063545%26amp%3binitializeIndex%3dtrue' },
{ content: this.loginPage() })
}
public frontPage(): string {
return this._encapsulate('\
<a href="http://ulw.fr/primo_library/libweb/action/login.do?loginFn=signin&vid=BDL&targetURL=http%3a%2f%2fulw.fr%2fprimo_library%2flibweb%2faction%2fsearch.do%3fvid%3dBDL%26amp%3bdscnt%3d0%26amp%3bdstmp%3d1530957063545%26amp%3binitializeIndex%3dtrue">\
Se connecter\
</a>');
}
public loginPage(): string {
}
}
declare var describe, expect, it, before, beforeEach, chai: any
import {Loan, Account, Database, Portal} from '../../models/'
import {Primo} from '../../models/portal/primo'
import {PMBSignInWithSuccessfulLogin,
PMBLoansWithSuccessfulLogin,
PMBUpdateCard} from './pmb-fixtures'
describe('Account on PMB', () => {
let adapter: PMB
let db: Database
let account: Account
beforeEach( () => {
db = Database.open('testdb').clear()
adapter = new PMB()
account = (new Account())
.setUrl('http://pmb.fr')
.setCredentials({login: 'marco',
password: 'polo',
portal: 'pmb'})
db.save(account)
})
describe('With successful Login scenario', () => {
it('db should have two loans', () => {
let http = new PMBLoansWithSuccessfulLogin('http://pmb.fr/')
})
})
})
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