nqm-minimongo
Version:
Client-side mongo database with server sync over http
61 lines (46 loc) • 1.99 kB
text/coffeescript
assert = require('chai').assert
RemoteDb = require "../src/RemoteDb"
db_queries = require "./db_queries"
_ = require 'lodash'
# @col should be a collection called with fields:
# "_id" as string, "a" as string, "b" as integer, "c" as JSON and "geo" as GeoJSON
# @reset should remove all rows from the scratch table and then call the callback
# passed to it.
exports.runTests = ->
describe 'RemoteDb', ->
# Check that it passes all normal queries
describe "passes queries", ->
db_queries.call(this)
describe "merging", ->
beforeEach (done) -> @reset(done)
it "merges changes with base specified", (done) ->
base = { _id: "1", a: "1", b: 1 }
change1 = _.cloneDeep(baseDoc)
change1.a = "2"
change2 = _.cloneDeep(baseDoc)
change2.b = 2
assert.equal doc1.a, "2"
assert.equal doc2.a, "2", "Should merge returned document"
assert.equal doc2.b, 2, "Should merge returned document"
# Should merge on server permanently
assert.equal doc2.a, "2", "Should merge documents"
assert.equal doc2.b, 2, "Should merge documents"
done()
it "overrides changes with no base specified", (done) ->
base = { _id: "1", a: "1", b: 1 }
change1 = _.cloneDeep(baseDoc)
change1.a = "2"
change2 = _.cloneDeep(baseDoc)
change2.b = 2
assert.equal doc1.a, "2"
assert.equal doc2.a, "1", "Should not merge returned document"
assert.equal doc2.b, 2, "Should keep new value"
done()