Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / modules / serialization / test / get-model-version-test.js
blob5cf1696e3d0ef695c2128a83d3c671d1c56a045d
1 'use strict';
3 var persistence = require('gitter-web-persistence');
4 var assert = require('assert');
5 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
6 var getModelVersion = require('../lib/get-model-version');
8 describe('get-model-version', function() {
9 describe('using real mongoose objects #slow', function() {
10 var fixture = fixtureLoader.setup({
11 user1: {}
12 });
14 describe('with initial value', function() {
15 it('should read the _tv value ', function() {
16 return persistence.User.findOne({ _id: fixture.user1._id }).then(function(user) {
17 var v = getModelVersion(user);
18 assert.strictEqual(v, 1);
19 });
20 });
22 it('should read the _tv value on lean objects', function() {
23 return persistence.User.findOne(
24 { _id: fixture.user1._id },
25 { _tv: 1 },
26 { lean: true }
27 ).then(function(user) {
28 var v = getModelVersion(user);
29 assert.strictEqual(v, 1);
30 });
31 });
32 });
34 describe('after increment', function() {
35 before(function() {
36 return fixture.user1.save();
37 });
39 it('should read the _tv value ', function() {
40 return persistence.User.findOne({ _id: fixture.user1._id }).then(function(user) {
41 var v = getModelVersion(user);
42 assert.strictEqual(v, 2);
43 });
44 });
46 it('should read the _tv value on lean objects', function() {
47 return persistence.User.findOne(
48 { _id: fixture.user1._id },
49 { _tv: 1 },
50 { lean: true }
51 ).then(function(user) {
52 var v = getModelVersion(user);
53 assert.strictEqual(v, 2);
54 });
55 });
56 });
57 });
58 });