aleclarson / rethinkdb-mock

In-memory RethinkDB
7 stars 3 forks source link
mock rethinkdb

rethinkdb-mock v0.7.1

Spec-compliant unit-testing for RethinkDB queries

The end goal is to replicate the API of rethinkdbdash.
For all intents and purposes, you should get the same results.
Please review the Feature support table before opening an issue.

Reusing and nesting queries are fully supported. :+1:

Check out the Releases tab for details about the newest versions.

 

Why use this?

 

Getting started

  1. Install from Github:
npm install --save-dev rethinkdb-mock
  1. Put some boilerplate in your test environment:
const rethinkdb = require('rethinkdb-mock')

// Replace `rethinkdbdash` with `rethinkdb-mock`
const mock = require('mock-require')
mock('rethinkdbdash', rethinkdb)

// You must use the same database name as the code you're testing.
const db = rethinkdb({
  name: 'test' // The default value
})
  1. Use it in your test suites:
describe('Some test suite', () => {

  // Reset the database between suites.
  beforeAll(() => {
    db.init({
      users: [],
      friends: [],
    })

    // Optionally, load JSON into the database.
    db.load(__dirname, './data.json')
  })

  // Now create your tests...
})

 

Feature support

The entire Rethink API is not yet implemented.
Get an idea of what's supported by referencing the table below.

Open an issue to request a feature be implemented.
But try implementing it yourself if you have time! :+1:

If a method is not behaving as expected, please open an issue!
But first check out TODO.md for a list of missing behaviors.

❌ means "not implemented yet"

⚠️ means "partially implemented"

πŸ’― means "fully implemented"

% Feature
❌ Changefeeds
❌ Binary support
❌ Date-time support
❌ Geospatial support
πŸ’― r.table()
πŸ’― r.tableCreate()
❌ r.tableList()
πŸ’― r.tableDrop()
❌ r.indexCreate()
❌ r.indexList()
❌ r.indexDrop()
❌ r.indexRename()
❌ r.indexStatus()
❌ r.indexWait()
⚠️ r.row
πŸ’― r() or r.expr()
πŸ’― r.do()
❌ r.args()
πŸ’― r.object()
πŸ’― r.branch()
⚠️ r.typeOf()
πŸ’― r.uuid()
⚠️ r.desc()
⚠️ r.asc()
❌ r.js()
❌ r.json()
❌ r.http()
❌ r.error()
❌ r.range()
πŸ’― table.get()
πŸ’― table.getAll()
⚠️ table.insert()
πŸ’― table.delete()
πŸ’― query() or query.bracket()
πŸ’― query.nth()
πŸ’― query.getField()
⚠️ query.hasFields()
❌ query.withFields()
⚠️ query.offsetsOf()
⚠️ query.contains()
⚠️ query.orderBy()
πŸ’― query.isEmpty()
πŸ’― query.count()
πŸ’― query.skip()
πŸ’― query.limit()
πŸ’― query.slice()
❌ query.between()
πŸ’― query.merge()
πŸ’― query.pluck()
⚠️ query.without()
⚠️ query.replace()
⚠️ query.update()
⚠️ query.delete()
πŸ’― query.default()
πŸ’― query.and()
πŸ’― query.or()
⚠️ query.eq()
⚠️ query.ne()
⚠️ query.gt()
⚠️ query.lt()
⚠️ query.ge()
⚠️ query.le()
⚠️ query.add()
⚠️ query.sub()
⚠️ query.mul()
πŸ’― query.div()
❌ query.mod()
❌ query.sum()
❌ query.avg()
❌ query.min()
❌ query.max()
❌ query.not()
❌ query.ceil()
❌ query.floor()
❌ query.round()
❌ query.random()
❌ query.coerceTo()
πŸ’― query.map()
⚠️ query.filter()
❌ query.fold()
❌ query.reduce()
❌ query.forEach()
❌ query.distinct()
❌ query.concatMap()
❌ query.innerJoin()
❌ query.outerJoin()
❌ query.eqJoin()
❌ query.zip()
❌ query.group()
❌ query.ungroup()
❌ query.sample()
❌ query.setInsert()
❌ query.setUnion()
❌ query.setIntersection()
❌ query.setDifference()
❌ query.append()
❌ query.prepend()
❌ query.union()
❌ query.difference()
❌ query.insertAt()
❌ query.spliceAt()
❌ query.deleteAt()
❌ query.changeAt()
❌ query.keys()
❌ query.values()
❌ query.literal()
❌ query.match()
❌ query.split()
❌ query.upcase()
❌ query.downcase()
❌ query.toJSON() or query.toJsonString()
❌ query.info()
❌ query.sync()

 

Contributing

Issues and pull requests are always appreciated! :grin:

If you have any questions, feel free to open an issue.

 

Getting started

# This tool compiles the `src` directory during `npm install`.
npm install -g coffee-build

git clone https://github.com/aleclarson/rethinkdb-mock
npm install

# Manually compile the `src` directory after you make any changes.
coffee -cb -o js src

 

Similar repositories