mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 17:42:57 +00:00
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/ban-ts-comment,@typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/ban-ts-comment,@typescript-eslint/no-explicit-any */
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2018, 2019 StApps
|
* Copyright (C) 2018-2021 StApps
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the Free
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
* Software Foundation, version 3.
|
* Software Foundation, version 3.
|
||||||
@@ -74,11 +74,11 @@ describe('DataProvider', () => {
|
|||||||
type: SCThingType.Message,
|
type: SCThingType.Message,
|
||||||
uid: sampleThing.uid,
|
uid: sampleThing.uid,
|
||||||
};
|
};
|
||||||
const otherSampleThing: SCMessage = {
|
|
||||||
...sampleThing,
|
const fakeStorage = new Map([
|
||||||
uid: 'message-456',
|
['foo', 'Bar'],
|
||||||
name: 'bar',
|
['bar', {foo: 'BarFoo'} as any],
|
||||||
};
|
]);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@@ -92,6 +92,7 @@ describe('DataProvider', () => {
|
|||||||
|
|
||||||
it('should generate data key', async () => {
|
it('should generate data key', async () => {
|
||||||
dataProvider.storagePrefix = 'foo.data';
|
dataProvider.storagePrefix = 'foo.data';
|
||||||
|
|
||||||
expect(dataProvider.getDataKey('123')).toBe('foo.data.123');
|
expect(dataProvider.getDataKey('123')).toBe('foo.data.123');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -104,6 +105,7 @@ describe('DataProvider', () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const response = await dataProvider.search(sampleQuery);
|
const response = await dataProvider.search(sampleQuery);
|
||||||
|
|
||||||
expect(response).toEqual(sampleResponse);
|
expect(response).toEqual(sampleResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -116,6 +118,7 @@ describe('DataProvider', () => {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
const response = await dataProvider.multiSearch({a: sampleQuery});
|
const response = await dataProvider.multiSearch({a: sampleQuery});
|
||||||
|
|
||||||
expect(response).toEqual({a: sampleResponse});
|
expect(response).toEqual({a: sampleResponse});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -160,8 +163,8 @@ describe('DataProvider', () => {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const response = await dataProvider.multiSearch(request);
|
const response = await dataProvider.multiSearch(request);
|
||||||
|
|
||||||
expect(response).toEqual(responseShould);
|
expect(response).toEqual(responseShould);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -173,22 +176,28 @@ describe('DataProvider', () => {
|
|||||||
providedThing.origin.created = sampleSavable.origin.created;
|
providedThing.origin.created = sampleSavable.origin.created;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(storageProvider.put).not.toHaveBeenCalled();
|
expect(storageProvider.put).not.toHaveBeenCalled();
|
||||||
expect(providedThing!).not.toBeDefined();
|
expect(providedThing!).not.toBeDefined();
|
||||||
|
|
||||||
await dataProvider.put(sampleThing);
|
await dataProvider.put(sampleThing);
|
||||||
|
|
||||||
expect(providedThing!).toBeDefined();
|
expect(providedThing!).toBeDefined();
|
||||||
expect(providedThing!).toEqual(sampleSavable);
|
expect(providedThing!).toEqual(sampleSavable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should correctly set and get single data item from the local database (storage)', async () => {
|
it('should correctly set and get single data item from the local database (storage)', async () => {
|
||||||
await dataProvider.put(sampleThing);
|
spyOn(storageProvider, 'get').and.returnValue(
|
||||||
spyOn(storageProvider, 'get').and.callThrough();
|
(async () => sampleSavable)(),
|
||||||
|
);
|
||||||
|
|
||||||
expect(storageProvider.get).not.toHaveBeenCalled();
|
expect(storageProvider.get).not.toHaveBeenCalled();
|
||||||
|
|
||||||
const providedThing = await dataProvider.get(
|
const providedThing = await dataProvider.get(
|
||||||
sampleThing.uid,
|
sampleThing.uid,
|
||||||
DataScope.Local,
|
DataScope.Local,
|
||||||
);
|
);
|
||||||
providedThing.origin.created = sampleSavable.origin.created;
|
|
||||||
expect(storageProvider.get).toHaveBeenCalledWith(
|
expect(storageProvider.get).toHaveBeenCalledWith(
|
||||||
dataProvider.getDataKey(sampleThing.uid),
|
dataProvider.getDataKey(sampleThing.uid),
|
||||||
);
|
);
|
||||||
@@ -196,19 +205,20 @@ describe('DataProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should provide all data items from the local database (storage)', async () => {
|
it('should provide all data items from the local database (storage)', async () => {
|
||||||
await dataProvider.put(sampleThing);
|
const fakeStorage = new Map([
|
||||||
await dataProvider.put(otherSampleThing);
|
['foo', 'Bar'],
|
||||||
const result = await dataProvider.getAll();
|
['bar', {foo: 'BarFoo'} as any],
|
||||||
expect([...result.keys()].sort()).toEqual([
|
|
||||||
dataProvider.getDataKey(sampleThing.uid),
|
|
||||||
dataProvider.getDataKey(otherSampleThing.uid),
|
|
||||||
]);
|
]);
|
||||||
expect(result.get(dataProvider.getDataKey(sampleThing.uid))!.data).toEqual(
|
spyOn(storageProvider, 'search').and.callFake(async () => {
|
||||||
sampleThing,
|
return fakeStorage;
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await dataProvider.getAll();
|
||||||
|
|
||||||
|
expect([...result.keys()].sort()).toEqual([...fakeStorage.keys()].sort());
|
||||||
|
expect([...result.values()].sort()).toEqual(
|
||||||
|
[...fakeStorage.values()].sort(),
|
||||||
);
|
);
|
||||||
expect(
|
|
||||||
result.get(dataProvider.getDataKey(otherSampleThing.uid))!.data,
|
|
||||||
).toEqual(otherSampleThing);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide single data from the backend', async () => {
|
it('should provide single data from the backend', async () => {
|
||||||
@@ -219,11 +229,14 @@ describe('DataProvider', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(Client.prototype.getThing).not.toHaveBeenCalled();
|
expect(Client.prototype.getThing).not.toHaveBeenCalled();
|
||||||
|
|
||||||
const providedThing = await dataProvider.get(
|
const providedThing = await dataProvider.get(
|
||||||
sampleThing.uid,
|
sampleThing.uid,
|
||||||
DataScope.Remote,
|
DataScope.Remote,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(Client.prototype.getThing).toHaveBeenCalledWith(sampleThing.uid);
|
expect(Client.prototype.getThing).toHaveBeenCalledWith(sampleThing.uid);
|
||||||
expect(providedThing).toBe(sampleThing);
|
expect(providedThing).toBe(sampleThing);
|
||||||
});
|
});
|
||||||
@@ -244,39 +257,39 @@ describe('DataProvider', () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const result = await dataProvider.get(sampleThing.uid);
|
const result = await dataProvider.get(sampleThing.uid);
|
||||||
|
|
||||||
expect(result.get(DataScope.Local)).toEqual(sampleSavable);
|
expect(result.get(DataScope.Local)).toEqual(sampleSavable);
|
||||||
expect(result.get(DataScope.Remote)).toEqual(sampleThing);
|
expect(result.get(DataScope.Remote)).toEqual(sampleThing);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly delete a data item from the local database (storage)', async () => {
|
it('should properly delete a data item from the local database (storage)', async () => {
|
||||||
spyOn(storageProvider, 'delete').and.callThrough();
|
spyOn(storageProvider, 'delete');
|
||||||
await dataProvider.put(sampleThing);
|
|
||||||
expect(await storageProvider.length()).toBe(1);
|
|
||||||
await dataProvider.delete(sampleThing.uid);
|
await dataProvider.delete(sampleThing.uid);
|
||||||
|
|
||||||
expect(storageProvider.delete).toHaveBeenCalledWith(
|
expect(storageProvider.delete).toHaveBeenCalledWith(
|
||||||
dataProvider.getDataKey(sampleThing.uid),
|
dataProvider.getDataKey(sampleThing.uid),
|
||||||
);
|
);
|
||||||
expect(await storageProvider.length()).toBe(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly delete all the data items from the local database (storage)', async () => {
|
it('should properly delete all the data items from the local database (storage)', async () => {
|
||||||
spyOn(storageProvider, 'delete').and.callThrough();
|
spyOn(storageProvider, 'delete');
|
||||||
await dataProvider.put(sampleThing);
|
spyOn(storageProvider, 'search').and.callFake(async () => {
|
||||||
await dataProvider.put(otherSampleThing);
|
return fakeStorage;
|
||||||
await storageProvider.put('some-uid', {some: 'thing'});
|
});
|
||||||
expect(await storageProvider.length()).not.toBe(0);
|
|
||||||
await dataProvider.deleteAll();
|
await dataProvider.deleteAll();
|
||||||
expect(storageProvider.delete).toHaveBeenCalledWith(
|
|
||||||
dataProvider.getDataKey(sampleThing.uid),
|
expect(storageProvider.delete).toHaveBeenCalledWith('foo', 'bar');
|
||||||
dataProvider.getDataKey(otherSampleThing.uid),
|
|
||||||
);
|
|
||||||
const result = await storageProvider.getAll();
|
|
||||||
expect([...result.keys()]).toEqual(['some-uid']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly check if a data item has already been saved', async () => {
|
it('should properly check if a data item has already been saved', async () => {
|
||||||
expect(await dataProvider.isSaved(sampleThing.uid)).toBeFalsy();
|
spyOn(storageProvider, 'has').and.callFake(async storageKey => {
|
||||||
await dataProvider.put(sampleThing);
|
return (async () => {
|
||||||
|
return dataProvider.getDataKey(sampleThing.uid) === storageKey;
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await dataProvider.isSaved('some-uuid')).toBeFalsy();
|
||||||
expect(await dataProvider.isSaved(sampleThing.uid)).toBeTruthy();
|
expect(await dataProvider.isSaved(sampleThing.uid)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,50 +31,65 @@ describe('StorageProvider', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [StorageModule],
|
imports: [StorageModule],
|
||||||
providers: [
|
providers: [StorageProvider],
|
||||||
StorageProvider,
|
|
||||||
// { provide: Storage, useClass: StorageMock }
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
storageProvider = TestBed.get(StorageProvider);
|
storageProvider = TestBed.get(StorageProvider);
|
||||||
storage = TestBed.get(Storage);
|
storage = TestBed.get(Storage);
|
||||||
await storage.clear();
|
spyOn(storage, 'forEach').and.callFake(function_ => {
|
||||||
|
let i = 0;
|
||||||
|
for (const key of sampleEntries.keys()) {
|
||||||
|
function_(sampleEntries.get(key), key, i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (async () => {
|
||||||
|
/* just return a promise */
|
||||||
|
})();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call ready method of storage on init', () => {
|
it('should call ready method of storage on init', () => {
|
||||||
spyOn(storage, 'ready');
|
spyOn(storage, 'ready');
|
||||||
storageProvider.init();
|
storageProvider.init();
|
||||||
|
|
||||||
expect(storage.ready).toHaveBeenCalled();
|
expect(storage.ready).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call set method of storage to put a value', () => {
|
it('should call set method of storage to put a value', () => {
|
||||||
spyOn(storage, 'set');
|
spyOn(storage, 'set');
|
||||||
storageProvider.put('some-uid', {some: 'thing'});
|
storageProvider.put('some-uid', {some: 'thing'});
|
||||||
|
|
||||||
expect(storage.set).toHaveBeenCalledWith('some-uid', {some: 'thing'});
|
expect(storage.set).toHaveBeenCalledWith('some-uid', {some: 'thing'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call get method of storage to get a value', () => {
|
it('should call get method of storage to get a value', () => {
|
||||||
spyOn(storage, 'get');
|
spyOn(storage, 'get');
|
||||||
storageProvider.get<any>('some-uid');
|
storageProvider.get('some-uid');
|
||||||
|
|
||||||
expect(storage.get).toHaveBeenCalledWith('some-uid');
|
expect(storage.get).toHaveBeenCalledWith('some-uid');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly put and get a value', async () => {
|
it('should properly put and get a value', async () => {
|
||||||
|
const fakeStorageSystem = new Map<string, any>();
|
||||||
|
|
||||||
|
spyOn(storage, 'set').and.callFake((id, value) => {
|
||||||
|
return (async () => fakeStorageSystem.set(id, value))();
|
||||||
|
});
|
||||||
|
spyOn(storage, 'get').and.callFake(id => {
|
||||||
|
return (async () => fakeStorageSystem.get(id))();
|
||||||
|
});
|
||||||
|
|
||||||
await storageProvider.init();
|
await storageProvider.init();
|
||||||
await storageProvider.put('some-uid', {some: 'thing'});
|
await storageProvider.put('some-uid', {some: 'thing'});
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
const result = await storageProvider.get('some-uid');
|
||||||
const result: Map<string, object> = await storageProvider.get<
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
expect(result).toEqual({some: 'thing'});
|
||||||
Map<string, object>
|
|
||||||
>('some-uid');
|
|
||||||
await expect(result).toEqual({some: 'thing'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when value is null', async () => {
|
it('should throw an error when value is null', async () => {
|
||||||
// eslint-disable-next-line unicorn/error-message
|
// eslint-disable-next-line unicorn/error-message
|
||||||
let error: Error = new Error();
|
let error: Error = new Error();
|
||||||
// eslint-disable-next-line unicorn/no-null
|
// eslint-disable-next-line unicorn/no-null
|
||||||
spyOn(storage, 'get').and.returnValue(Promise.resolve(null));
|
spyOn(storage, 'get').and.returnValue((async () => null)());
|
||||||
try {
|
try {
|
||||||
await storageProvider.get('something-else');
|
await storageProvider.get('something-else');
|
||||||
} catch (error_) {
|
} catch (error_) {
|
||||||
@@ -86,101 +101,103 @@ describe('StorageProvider', () => {
|
|||||||
it('should put multiple values into the storage', async () => {
|
it('should put multiple values into the storage', async () => {
|
||||||
spyOn(storageProvider, 'put');
|
spyOn(storageProvider, 'put');
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
await storageProvider.putMultiple(sampleEntries);
|
||||||
expect((storageProvider.put as jasmine.Spy).calls.count()).toEqual(3);
|
|
||||||
expect(storageProvider.put).toHaveBeenCalledWith('foo', 'Bar');
|
expect(storageProvider.put).toHaveBeenCalledTimes(sampleEntries.size);
|
||||||
expect(storageProvider.put).toHaveBeenCalledWith('bar', {foo: 'BarFoo'});
|
|
||||||
|
for (const key of sampleEntries.keys()) {
|
||||||
|
expect(storageProvider.put).toHaveBeenCalledWith(
|
||||||
|
key,
|
||||||
|
sampleEntries.get(key),
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get multiple values from the storage', async () => {
|
it('should get multiple values from the storage', async () => {
|
||||||
spyOn(storageProvider, 'get').and.callThrough();
|
spyOn(storageProvider, 'get').and.callFake(id => {
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
return (async () => sampleEntries.get(id))();
|
||||||
|
});
|
||||||
const entries = await storageProvider.getMultiple(['foo', 'bar']);
|
const entries = await storageProvider.getMultiple(['foo', 'bar']);
|
||||||
expect((storageProvider.get as jasmine.Spy).calls.count()).toEqual(2);
|
|
||||||
|
expect(storageProvider.get).toHaveBeenCalledTimes(2);
|
||||||
expect(storageProvider.get).toHaveBeenCalledWith('foo');
|
expect(storageProvider.get).toHaveBeenCalledWith('foo');
|
||||||
expect(storageProvider.get).toHaveBeenCalledWith('bar');
|
expect(storageProvider.get).toHaveBeenCalledWith('bar');
|
||||||
|
|
||||||
expect([...entries.values()]).toEqual(['Bar', {foo: 'BarFoo'}]);
|
expect([...entries.values()]).toEqual(['Bar', {foo: 'BarFoo'}]);
|
||||||
expect([...entries.keys()]).toEqual(['foo', 'bar']);
|
expect([...entries.keys()]).toEqual(['foo', 'bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get all values from the storage', async () => {
|
it('should get all values from the storage', async () => {
|
||||||
spyOn(storageProvider, 'get').and.callThrough();
|
const allValuesMap = await storageProvider.getAll();
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
|
||||||
const entries = await storageProvider.getAll();
|
for (const key of sampleEntries.keys()) {
|
||||||
expect(
|
expect(allValuesMap.get(key)).toEqual(sampleEntries.get(key));
|
||||||
[...entries.values()].map(item => (item.foo ? item.foo : item)).sort(),
|
}
|
||||||
).toEqual(
|
|
||||||
[...sampleEntries.values()]
|
|
||||||
.map(item => (item.foo ? item.foo : item))
|
|
||||||
.sort(),
|
|
||||||
);
|
|
||||||
expect([...entries.keys()].sort()).toEqual(['bar', 'foo', 'foo.bar']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete one or more entries from the storage', async () => {
|
it('should delete one or more entries from the storage', async () => {
|
||||||
spyOn(storage, 'remove').and.callThrough();
|
const storageRemoveSpy = spyOn(storage, 'remove');
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
|
||||||
let entries = await storageProvider.getAll();
|
|
||||||
expect([...entries.values()].length).toBe(3);
|
|
||||||
await storageProvider.delete('bar');
|
|
||||||
|
|
||||||
expect(storage.remove).toHaveBeenCalled();
|
await storageProvider.delete('bar');
|
||||||
entries = await storageProvider.getAll();
|
expect(storage.remove).toHaveBeenCalledTimes(1);
|
||||||
expect([...entries.values()]).toEqual(['Bar', 123]);
|
|
||||||
|
storageRemoveSpy.calls.reset();
|
||||||
|
|
||||||
await storageProvider.delete('foo', 'foo.bar');
|
await storageProvider.delete('foo', 'foo.bar');
|
||||||
expect(await storageProvider.length()).toBe(0);
|
expect(storage.remove).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete all entries in the storage', async () => {
|
it('should delete all entries in the storage', async () => {
|
||||||
spyOn(storage, 'clear').and.callThrough();
|
spyOn(storage, 'clear');
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
|
||||||
let entries = await storageProvider.getAll();
|
|
||||||
expect([...entries.values()].length).not.toBe(0);
|
|
||||||
await storageProvider.deleteAll();
|
await storageProvider.deleteAll();
|
||||||
|
|
||||||
entries = await storageProvider.getAll();
|
|
||||||
expect(storage.clear).toHaveBeenCalled();
|
expect(storage.clear).toHaveBeenCalled();
|
||||||
expect([...entries.values()].length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should provide number of entries', async () => {
|
|
||||||
spyOn(storage, 'length').and.callThrough();
|
|
||||||
|
|
||||||
expect(await storageProvider.length()).toBe(0);
|
|
||||||
expect(storage.length).toHaveBeenCalled();
|
|
||||||
|
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
|
||||||
expect(await storageProvider.length()).toBe(3);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide information if storage is empty', async () => {
|
it('should provide information if storage is empty', async () => {
|
||||||
spyOn(storage, 'length').and.callThrough();
|
let n: number;
|
||||||
|
spyOn(storage, 'length').and.callFake(async () => n);
|
||||||
|
|
||||||
expect(await storageProvider.isEmpty()).toBeTruthy();
|
n = 0;
|
||||||
expect(storage.length).toHaveBeenCalled();
|
|
||||||
|
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
const testEmpty = await storageProvider.isEmpty();
|
||||||
|
|
||||||
|
expect(testEmpty).toBeTruthy();
|
||||||
|
|
||||||
|
n = 1;
|
||||||
expect(await storageProvider.isEmpty()).toBeFalsy();
|
expect(await storageProvider.isEmpty()).toBeFalsy();
|
||||||
|
|
||||||
|
expect(storage.length).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should provide number of entries', async () => {
|
||||||
|
const n = 5;
|
||||||
|
spyOn(storage, 'length').and.callFake(async () => n);
|
||||||
|
|
||||||
|
expect(await storageProvider.length()).toBe(n);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide information if storage contains a specific entry (key)', async () => {
|
it('should provide information if storage contains a specific entry (key)', async () => {
|
||||||
spyOn(storage, 'keys').and.returnValue(
|
spyOn(storage, 'keys').and.returnValue(
|
||||||
Promise.resolve([...sampleEntries.keys()]),
|
(async () => [...sampleEntries.keys()])(),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(await storageProvider.has('foo')).toBeTruthy();
|
expect(await storageProvider.has('foo')).toBeTruthy();
|
||||||
expect(await storageProvider.has('something-else')).toBeFalsy();
|
expect(await storageProvider.has('something-else')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow search by regex', async () => {
|
it('should allow search by regex', async () => {
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
|
||||||
const found: Map<string, any> = await storageProvider.search<any>(/bar/);
|
const found: Map<string, any> = await storageProvider.search<any>(/bar/);
|
||||||
|
|
||||||
expect([...found.keys()].sort()).toEqual(['bar', 'foo.bar']);
|
expect([...found.keys()].sort()).toEqual(['bar', 'foo.bar']);
|
||||||
expect([...found.values()]).toEqual([{foo: 'BarFoo'}, 123]);
|
expect([...found.values()]).toEqual([{foo: 'BarFoo'}, 123]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow search by string', async () => {
|
it('should allow search by string', async () => {
|
||||||
await storageProvider.putMultiple(sampleEntries);
|
spyOn(storage, 'get').and.callFake(id => {
|
||||||
|
return (async () => sampleEntries.get(id))();
|
||||||
|
});
|
||||||
const found: Map<string, any> = await storageProvider.search<any>('foo.ba');
|
const found: Map<string, any> = await storageProvider.search<any>('foo.ba');
|
||||||
|
|
||||||
expect([...found.keys()]).toEqual(['foo.bar']);
|
expect([...found.keys()]).toEqual(['foo.bar']);
|
||||||
expect([...found.values()]).toEqual([123]);
|
expect([...found.values()]).toEqual([123]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user