Skip to content

Commit a1fdadc

Browse files
fix/pass-v2.1-to-v2.2 (#313)
1 parent 1eb25eb commit a1fdadc

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [2.2.2] - 2021-05-19
10+
11+
### Fixed
12+
13+
- When ttl 0 was set, a request to the server was not made again, it brought it from memory, it was corrected in the isLive function of common.
14+
- When the value of a remote filter contained '&', the generated url did not keep the '&'.
15+
916
## [2.2.1] - 2020-10-17
1017

1118
### Fixed

src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DocumentCollection } from './document-collection';
55
import { Resource } from './resource';
66

77
export function isLive(cacheable: ICacheable, ttl?: number): boolean {
8-
let ttl_in_seconds = ttl && typeof ttl === 'number' ? ttl : cacheable.ttl || 0;
8+
let ttl_in_seconds = typeof ttl === 'number' ? ttl : cacheable.ttl || 0;
99

1010
return Date.now() < cacheable.cache_last_update + ttl_in_seconds * 1000;
1111
}

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-jsonapi",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "JSON API library for Angular",
55
"module": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js",
66
"es2015": "ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.js",

src/service.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,32 @@ for (let store_cache_method of store_cache_methods) {
156156
expect(http_request_spy).toHaveBeenCalledTimes(0);
157157
});
158158

159+
it(`with cached on memory (live) collection emits source ^memory-server| when force ttl = 0 on call`, async () => {
160+
// caching collection
161+
test_response_subject.next(new HttpResponse({ body: TestFactory.getCollectionDocumentData(Book) }));
162+
booksService.collections_ttl = 5; // live
163+
await booksService.all({ store_cache_method: store_cache_method }).toPromise();
164+
165+
let http_request_spy = spyOn(HttpClient.prototype, 'request').and.callThrough();
166+
let expected = [
167+
// expected emits
168+
{ builded: true, loaded: false, source: 'memory' },
169+
{ builded: true, loaded: true, source: 'server' }
170+
];
171+
172+
let emits = await booksService
173+
.all({ ttl: 0, store_cache_method: store_cache_method })
174+
.pipe(
175+
map(emit => {
176+
return { builded: emit.builded, loaded: emit.loaded, source: emit.source };
177+
}),
178+
toArray()
179+
)
180+
.toPromise();
181+
expect(emits).toMatchObject(expected);
182+
expect(http_request_spy).toHaveBeenCalledTimes(1);
183+
});
184+
159185
it(`with cached on memory (dead) collection emits source ^memory-server|`, async () => {
160186
// caching collection
161187
test_response_subject.next(new HttpResponse({ body: TestFactory.getCollectionDocumentData(Book) }));

src/services/path-collection-builder.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ describe('Path Builder', () => {
7777
expect(path_collection_builder.get().includes('fields[authors]=name,address&fields[books]=title')).toBeTruthy();
7878
});
7979

80+
it('if filter with characters such as "&" are provided, they must be formatted and included in get_params', () => {
81+
path_collection_builder.applyParams(testService, { remotefilter: { field: 'foo&bar' } });
82+
expect(path_collection_builder.get().includes('filter[field]=foo%26bar')).toBeTruthy();
83+
});
84+
8085
it('if page params are provided, applyParams should call addParam one or two times with the page number and size', () => {
8186
Core.injectedServices.rsJsonapiConfig.parameters.page.number = 'page_index';
8287
Core.injectedServices.rsJsonapiConfig.parameters.page.size = 'page_size';

src/services/url-params-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class UrlParamsBuilder {
1414
let ret = '';
1515
if (Array.isArray(params) || params instanceof Object) {
1616
Base.forEach(params, (value, key) => {
17-
ret += this.toparamsarray(value, add + '[' + key + ']');
17+
ret += this.toparamsarray(encodeURIComponent(value), add + '[' + key + ']');
1818
});
1919
} else {
2020
ret += add + '=' + params;

0 commit comments

Comments
 (0)