@internetarchive/collection-name-cache
Advanced tools
Comparing version 0.2.7-alpha.3 to 0.2.7
@@ -0,0 +0,0 @@ import { SearchService } from '@internetarchive/search-service'; |
@@ -0,0 +0,0 @@ import { __decorate } from "tslib"; |
@@ -267,3 +267,27 @@ import { expect } from '@open-wc/testing'; | ||
}); | ||
it('adds known titles to the cache', async () => { | ||
const mockSearchService = new MockSearchService(); | ||
mockSearchService.searchResult = mockSearchResponse; | ||
const collectionNameCache = new CollectionNameCache({ | ||
searchService: mockSearchService, | ||
loadDelay: 25, | ||
}); | ||
// fill the cache with some already-known collection titles | ||
await collectionNameCache.addKnownTitles({ | ||
'foo-collection': 'Foo Collection', | ||
'bar-collection': 'Bar Collection', | ||
'baz-collection': 'Baz Collection', | ||
}); | ||
// should immediately have them available in the cache | ||
expect(await collectionNameCache.collectionNameFor('foo-collection')).to.equal('Foo Collection'); | ||
expect(await collectionNameCache.collectionNameFor('bar-collection')).to.equal('Bar Collection'); | ||
expect(await collectionNameCache.collectionNameFor('baz-collection')).to.equal('Baz Collection'); | ||
await promisedSleep(50); | ||
// should not have tried to fetch any titles | ||
expect(mockSearchService.searchCallCount).to.equal(0); | ||
await collectionNameCache.preloadIdentifiers(['foo-collection']); | ||
// again, no fetch call should be made, since we already have it cached | ||
expect(mockSearchService.searchCallCount).to.equal(0); | ||
}); | ||
}); | ||
//# sourceMappingURL=collection-name-cache.test.js.map |
@@ -10,3 +10,3 @@ { | ||
"author": "Internet Archive", | ||
"version": "0.2.7-alpha.3", | ||
"version": "0.2.7", | ||
"main": "dist/index.js", | ||
@@ -27,3 +27,3 @@ "module": "dist/index.js", | ||
"@internetarchive/local-cache": "^0.2.1", | ||
"@internetarchive/search-service": "^0.4.7-alpha.1", | ||
"@internetarchive/search-service": "^0.4.7", | ||
"lit": "^2.0.2" | ||
@@ -30,0 +30,0 @@ }, |
@@ -30,3 +30,3 @@ /* eslint-disable camelcase */ | ||
* without sending a request for them. | ||
* | ||
* | ||
* @param identifierTitleMap | ||
@@ -105,3 +105,5 @@ */ | ||
/** @inheritdoc */ | ||
async addKnownTitles(identifierTitleMap: Record<string, string>): Promise<void> { | ||
async addKnownTitles( | ||
identifierTitleMap: Record<string, string> | ||
): Promise<void> { | ||
if (!this.cacheLoaded) await this.loadFromCache(); | ||
@@ -108,0 +110,0 @@ Object.entries(identifierTitleMap).forEach(([identifier, title]) => { |
@@ -342,2 +342,39 @@ import { expect } from '@open-wc/testing'; | ||
}); | ||
it('adds known titles to the cache', async () => { | ||
const mockSearchService = new MockSearchService(); | ||
mockSearchService.searchResult = mockSearchResponse; | ||
const collectionNameCache = new CollectionNameCache({ | ||
searchService: mockSearchService, | ||
loadDelay: 25, | ||
}); | ||
// fill the cache with some already-known collection titles | ||
await collectionNameCache.addKnownTitles({ | ||
'foo-collection': 'Foo Collection', | ||
'bar-collection': 'Bar Collection', | ||
'baz-collection': 'Baz Collection', | ||
}); | ||
// should immediately have them available in the cache | ||
expect( | ||
await collectionNameCache.collectionNameFor('foo-collection') | ||
).to.equal('Foo Collection'); | ||
expect( | ||
await collectionNameCache.collectionNameFor('bar-collection') | ||
).to.equal('Bar Collection'); | ||
expect( | ||
await collectionNameCache.collectionNameFor('baz-collection') | ||
).to.equal('Baz Collection'); | ||
await promisedSleep(50); | ||
// should not have tried to fetch any titles | ||
expect(mockSearchService.searchCallCount).to.equal(0); | ||
await collectionNameCache.preloadIdentifiers(['foo-collection']); | ||
// again, no fetch call should be made, since we already have it cached | ||
expect(mockSearchService.searchCallCount).to.equal(0); | ||
}); | ||
}); |
@@ -0,0 +0,0 @@ import { ItemHit, SearchResponse } from '@internetarchive/search-service'; |
@@ -0,0 +0,0 @@ import { Result } from '@internetarchive/result-type'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
161172
1640