A mock server that mimics the Algolia Search and Indexing APIs.
This is very much version 0.0.x
and a hack, not a fully fledged system.
- Very minimal support for adding, updating, and removing data from indices.
- No search queries supported yet (coming when I need them/get around to them)
- I've not written unit or integration tests for the main routes.
I am going to assume you are using the Algolia Javascript API Client here, but if not then similar patterns will apply.
Normally you'd do this
const client = algoliasearch(applicationId, apiKey)
const index = client.initIndex('some-index-name')
await index.addObjects(arrayOfObjects)
To fool the algoliasearch
client into talking to this mock server, do this instead:
const client = algoliasearch(applicationId, apiKey, { protocol: 'http:' })
client.hosts = {
read: ['http://localhost:3000'],
write: ['http://localhost:3000']
}
const index = client.initIndex('some-index-name')
await index.addObjects(arrayOfObjects)
Then all the client requests will go to the mock server (assuming it's running on port 3000
)
You can get a quick overview of what has been sent to the mock server via get `/requests'.
You can reset the request log by sending [delete /requests
]
Set the following environment variables
Variable | Default | Notes |
---|---|---|
PORT |
3000 |
The port the server listens on |
Branch | Tests | Code Coverage | Audit | Comments |
---|---|---|---|---|
develop |
Work in progress | |||
main |
Latest Production Release |
- NodeJS. I use
nvm
to manage Node versions —brew install nvm
. - Docker if you want to use the Swagger Editor. (Use Docker for Mac, not the
homebrew
version)
Clone this (or better yet, fork it then clone your fork)
npm install
npm start
Go to localhost:3000/docs to see the docs.
You can put environment variables in a .env
file.
npm test
to run the unit testsnpm run test:server
will run the integration testsnpm run lint
will lint itnpm run prettier
will prettify itnpm run test:unit:cov
will run the unit tests with code coverage
Please see the contributing notes.