Giter Club home page Giter Club logo

mock-algolia's Introduction

mock-algolia

A mock server that mimics the Algolia Search and Indexing APIs.

Docker

Links

Current Status

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.

To Use

I am going to assume you are using the Algolia Javascript API Client here, but if not then similar patterns will apply.

Prep the client

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)

Checking what was sent

You can get a quick overview of what has been sent to the mock server via get `/requests'.

Resetting the mock server

You can reset the request log by sending [delete /requests]

Configuration

Set the following environment variables

Variable Default Notes
PORT 3000 The port the server listens on

Development

Branches

Branch Tests Code Coverage Audit Comments
develop CircleCI codecov Vulnerabilities Work in progress
main CircleCI codecov Vulnerabilities Latest Production Release

Prerequisites

  • 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)

To build and run locally

Clone this (or better yet, fork it then clone your fork)

npm install
npm start

Go to localhost:3000/docs to see the docs.

.env file

You can put environment variables in a .env file.

Testing

  • npm test to run the unit tests
  • npm run test:server will run the integration tests
  • npm run lint will lint it
  • npm run prettier will prettify it
  • npm run test:unit:cov will run the unit tests with code coverage

Contributing

Please see the contributing notes.

mock-algolia's People

Contributors

anasanzari avatar davesag avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mock-algolia's Issues

[Docker] Issue running docker

Hello !

First, thanks a lot for this project, I was looking for something like so for a very long time :)

I was trying to launch the docker file locally but got the following error preventing container to run:

internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module './src/server'
Require stack:
- /app/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/app/index.js:2:16)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/index.js' ]
}

I think there is a simple fix in the Dockerfile, I'll have a look.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.