@databank/algolia-mock-server v0.9.0
algolia-server-mock
:warning: this package is work in progress do not rely sole on it for unit testings!
algolia-mock-server is a personal effort to create an algoliasearch
compatible
server counterpart that mimics the functionality of Algolia REST Api.
It is primarely ment for unit testing in TypeScript projects.
Usage
Install
npm install --save-dev @databank/algolia-mock-server
Usage in unit tests
// Algolia client
import algoliasearch from 'algoliasearch';
// algolia-mock-server can distinguish between admin and read only credentials,
// and will fail writing to index if using read key,
// and when using admin key it will retrieve unretrievable attributes
const mockWriteKey = "ADMINKEY"
const mockReadKey = "READKEY"
const client = algoliasearch('YourApplicationID', mockWriteKey , {
hosts: [{ url: 'localhost:3000', protocol: 'http' }],
});
// algolia-server-mock
import { createServer, } from 'http';
import { httpHandler, mockStorageMemory } from '@databank/algolia-mock-server';
const storage = mockStorageMemory();
const server = createServer(httpHandler(storage));
beforeAll(() => server.listen(3000));
afterAll(() => server.close());
test('TestMyFunction', async () => {
await myFunctionThatWritesToAlgolia();
const index = client.initIndex('my_data_index');
const algoliaObject = await index.getObject("test");
expect( algoliaObject ).toStrictEqual( expectedObject )
})
Coverage
Algolia Client Coverage (npm algoliasearch
)
index.search()
- partialindex.searchForFacetValues()
- partialindex.findObject()
index.getObjectPosition()
index.getObject()
index.saveObject()
index.saveObjects()
index.partialUpdateObject()
index.partialUpdateObjects()
index.replaceAllObjects()
index.deleteObject()
index.deleteObjects()
index.deleteBy()
index.clearObjects()
index.batch()
- partialindex.saveSynonym()
index.replaceAllSynonyms()
index.deleteSynonym()
index.clearSynonyms()
index.saveRule()
index.saveRules()
index.replaceAllRules()
index.deleteRule()
index.clearRules()
index.getSettings()
index.setSettings()
- partialindex.delete()
client.multipleQueries()
- partialclient.multipleGetObjects()
client.moveIndex()
client.copyIndex()
client.copyRules()
client.copySynonyms()
client.copySettings()
client.addApiKey()
client.updateApiKey()
client.deleteApiKey()
client.multipleBatch()
REST API Coverage
- Index
- Get Settings
- Set Settings - partial
- Search - partial
- Search for facet values - partial
- Browse index
- Single object operations
- Get Object
index.getObject()
- support for
attributesToRetrieve
- nested
attributesToRetrieve
eg. invoice.lines.*.name - skip
unretrievableAttributes
- skipping nested attributes still in progress
- support for
- Delete object
- Get Object
- Multi object operations
- Add/Replace Object
- Delete by Query
- Clear Objects used by
index.clearObjects()
- Partially update objects
- Batch write operations
addObject
updateObject
used byindex.saveObject()
andindex.saveObjects()
partialUpdateObject
partialUpdateObjectNoCreate
deleteObject
used byindex.deleteObject()
andindex.deleteObjects()
delete
clear
- Batch write operations - multiple indexes
- Get objects
- Multi index operations x Search multiple indexes - partial
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago