mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
refactor: use range query for canteen module
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
*/
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {Client} from '@openstapps/api/lib/client';
|
||||
import {SCDish, SCMessage, SCSaveableThing, SCSearchQuery,
|
||||
SCSearchResponse, SCSearchValueFilter, SCThing, SCThingOriginType, SCThings, SCThingType} from '@openstapps/core';
|
||||
import {
|
||||
SCDish, SCMessage, SCMultiSearchRequest, SCSaveableThing, SCSearchQuery,
|
||||
SCSearchResponse, SCSearchValueFilter, SCThing, SCThingOriginType, SCThings, SCThingType,
|
||||
} from '@openstapps/core';
|
||||
import {sampleThingsMap} from '../../_helpers/data/sample-things';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {DataModule} from './data.module';
|
||||
@@ -96,6 +98,61 @@ describe('DataProvider', () => {
|
||||
expect(response).toEqual(sampleResponse);
|
||||
});
|
||||
|
||||
it('should provide backend data items using multi search query', async () => {
|
||||
spyOn(Client.prototype as any, 'multiSearch').and.callFake(() => ({
|
||||
then: (callback: any) => {
|
||||
return callback({
|
||||
a: sampleResponse,
|
||||
});
|
||||
},
|
||||
}));
|
||||
const response = await dataProvider.multiSearch({a: sampleQuery});
|
||||
expect(response).toEqual({a: sampleResponse});
|
||||
});
|
||||
|
||||
it('should partition search requests correctly', async () => {
|
||||
const request = {
|
||||
a: 'a',
|
||||
b: 'b',
|
||||
c: 'c',
|
||||
d: 'd',
|
||||
e: 'e',
|
||||
} as SCMultiSearchRequest; // and response...
|
||||
const requestCheck = Object.assign({}, request);
|
||||
const responseShould = {
|
||||
a: 'A',
|
||||
b: 'B',
|
||||
c: 'C',
|
||||
d: 'D',
|
||||
e: 'E',
|
||||
};
|
||||
|
||||
dataProvider.backendQueriesLimit = 2;
|
||||
spyOn(Client.prototype as any, 'multiSearch').and.callFake((req: SCMultiSearchRequest) => ({
|
||||
then: (callback: any) => {
|
||||
let i = 0;
|
||||
for (const key in req) {
|
||||
if (req.hasOwnProperty(key)) {
|
||||
i++;
|
||||
// @ts-ignore
|
||||
expect(requestCheck[key]).not.toBeNull();
|
||||
expect(requestCheck[key]).toEqual(req[key]);
|
||||
// @ts-ignore
|
||||
requestCheck[key] = null;
|
||||
// @ts-ignore
|
||||
req[key] = req[key].toUpperCase();
|
||||
}
|
||||
}
|
||||
expect(i).toBeLessThanOrEqual(dataProvider.backendQueriesLimit);
|
||||
|
||||
return callback(req);
|
||||
},
|
||||
}));
|
||||
|
||||
const response = await dataProvider.multiSearch(request);
|
||||
expect(response).toEqual(responseShould);
|
||||
});
|
||||
|
||||
it('should put an data item into the local database (storage)', async () => {
|
||||
let providedThing: SCSaveableThing<SCThing>;
|
||||
spyOn(storageProvider, 'put' as any).and.callFake((_id: any, thing: any) => {
|
||||
|
||||
Reference in New Issue
Block a user