Skip to content

Commit

Permalink
Merge pull request #112 from lagoshny/issue-110
Browse files Browse the repository at this point in the history
Issue 110
  • Loading branch information
lagoshny authored Jul 21, 2023
2 parents 28f6611 + c976630 commit c5d07cc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.6.1 (2023-07-21)
#### Changes
Fixed [issue-110](https://github.com/lagoshny/ngx-hateoas-client/issues/110).

## 3.6.0 (2023-07-07)
#### Changes
Updated to Angular 16.
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-hateoas-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lagoshny/ngx-hateoas-client",
"version": "3.6.0",
"version": "3.6.1",
"description": "This client used to develop `Angular 12+` applications working with RESTfulll server API with HAL/JSON response type (supports server implementation by Spring HATEOAS)",
"readme": "README.md",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PagedResourceCollectionHttpService } from '../../service/internal/paged
import { DependencyInjector } from '../../util/dependency-injector';
import { of } from 'rxjs';
import { ResourceCollection } from './resource-collection';
import { PagedGetOption } from '../declarations';
import { PagedGetOption, Sort } from '../declarations';

describe('PagedResourceCollection', () => {

Expand Down Expand Up @@ -147,5 +147,62 @@ describe('PagedResourceCollection', () => {
});
});

it('CUSTOM_PAGE should use sort params passed as params', () => {
pagedResourceCollectionHttpServiceSpy.get.and.returnValue(of(new PagedResourceCollection(new ResourceCollection())));

const pagedResourceCollection = new PagedResourceCollection(new SimpleResourceCollection(), {
...pageDataWithLinks,
_links: {
...pageDataWithLinks._links,
self: {
href: 'http://localhost:8080/api/v1/tasks?page=0&size=1&sort=first,ASC'
}
}
});
const sortParams: Sort = {first: 'ASC', second: 'DESC'};
pagedResourceCollection.customPage({pageParams: {page: 2, size: 8}, sort: sortParams})
.subscribe((customPageCollection) => {
const urlString: string = pagedResourceCollectionHttpServiceSpy.get.calls.argsFor(0)[0];
const url = new URL(urlString);
expect(url.searchParams.has('page')).toBeFalse();
expect(url.searchParams.has('size')).toBeFalse();
expect(url.searchParams.has('sort')).toBeFalse();

const actualSortParams = pagedResourceCollectionHttpServiceSpy.get.calls.argsFor(0)[1].sort;
expect(sortParams).toBe(actualSortParams);
});
});

it('CUSTOM_PAGE should use previous sort params when sort params is not passed', () => {
pagedResourceCollectionHttpServiceSpy.get.and.returnValue(of(new PagedResourceCollection(new ResourceCollection())));

const pagedResourceCollection = new PagedResourceCollection(new SimpleResourceCollection(), {
...pageDataWithLinks,
_links: {
...pageDataWithLinks._links,
self: {
href: 'http://localhost:8080/api/v1/tasks?page=0&size=1&sort=first,ASC&sort=second,DESC'
}
}
});
pagedResourceCollection.customPage({pageParams: {page: 2, size: 8}})
.subscribe((customPageCollection) => {
const urlString: string = pagedResourceCollectionHttpServiceSpy.get.calls.argsFor(0)[0];
const url = new URL(urlString);
expect(url.searchParams.has('page')).toBeFalse();
expect(url.searchParams.has('size')).toBeFalse();
expect(url.searchParams.has('sort')).toBeTrue();
});
});

it('PAGE should not change pageSize when request new page', () => {
pagedResourceCollectionHttpServiceSpy.get.and.returnValue(of(new PagedResourceCollection(new ResourceCollection(), pageDataWithLinks)));

const pagedResourceCollection = new PagedResourceCollection(new SimpleResourceCollection(), pageDataWithLinks);
pagedResourceCollection.page(2).subscribe(pagedCollection => {
expect(pagedCollection.pageSize).toBe(10);
});
});

});

Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export class PagedResourceCollection<T extends BaseResource> extends ResourceCol
const requestUrl = new URL(this.selfLink.href);
requestUrl.searchParams.delete('page');
requestUrl.searchParams.delete('size');
requestUrl.searchParams.delete('sort');
if (!isEmpty(params.sort)) {
requestUrl.searchParams.delete('sort');
}

return doRequest<T>(requestUrl.href, options?.useCache, params).pipe(
tap(() => {
StageLogger.resourceEndLog(this.resources[0], 'CustomPage', {result: 'custom page was performed successful'});
Expand Down

0 comments on commit c5d07cc

Please sign in to comment.