Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct method to get pid from $ref #100

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions projects/rero/ng-core/src/lib/utils/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Invenio angular core
* Copyright (C) 2019 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { extractIdOnRef } from './utils';
import { TestBed } from '@angular/core/testing';

describe('Utils', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should evaluate /5 to 5', () => {

const ref = 'ils.rero.ch/api/documents/5';
expect(extractIdOnRef(ref)).toEqual('5');

});

it('should evaluate /28 to 28', () => {

const ref = 'ils.rero.ch/api/documents/28';
expect(extractIdOnRef(ref)).toEqual('28');

});

it('should evaluate /286 to 286', () => {

const ref = 'ils.rero.ch/api/documents/286';
expect(extractIdOnRef(ref)).toEqual('286');

});

it('should evaluate /9999 to 9999', () => {

const ref = 'ils.rero.ch/api/documents/9999';
expect(extractIdOnRef(ref)).toEqual('9999');

});

it('should evaluate /19999 to 19999', () => {

const ref = 'ils.rero.ch/api/documents/19999';
expect(extractIdOnRef(ref)).toEqual('19999');

});

});
4 changes: 2 additions & 2 deletions projects/rero/ng-core/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

export function extractIdOnRef(ref: string) {
const rx = /.*\/?(.+)$/ig;
return rx.exec(ref)[1];
const pidRegExp = new RegExp('.*/(.*)$');
return pidRegExp.exec(ref)[1];
}

export function cleanDictKeys(data: any) {
Expand Down