3 var assert = require('assert');
4 var Promise = require('bluebird');
5 var fixtureLoader = require('gitter-web-test-utils/lib/test-fixtures');
6 var ObjectID = require('mongodb').ObjectID;
7 var recentRoomCore = require('../lib/recent-room-core');
9 describe('recent-room-core', function() {
10 describe('findLastAccessTimesForUsersInRoom #slow', function() {
11 var fixture = fixtureLoader.setup({
14 troupe1: { users: ['user1'] }
17 it('should handle default values', function() {
19 .findLastAccessTimesForUsersInRoom(fixture.troupe1.id, [
23 .then(function(result) {
24 assert(result[fixture.user1.id]);
25 assert(result[fixture.user2.id]);
29 it('should handle non default values', function() {
31 recentRoomCore.saveUserTroupeLastAccess(fixture.user1.id, fixture.troupe1.id),
32 recentRoomCore.saveUserTroupeLastAccess(fixture.user2.id, fixture.troupe1.id)
35 return recentRoomCore.findLastAccessTimesForUsersInRoom(fixture.troupe1.id, [
40 .then(function(result) {
41 var d1 = Date.now() - result[fixture.user1.id];
42 var d2 = Date.now() - result[fixture.user2.id];
52 describe('saveUserTroupeLastAccess #slow', function() {
53 it('should update on insert', function() {
54 var userId = new ObjectID();
55 var troupeId = new ObjectID();
56 return recentRoomCore.saveUserTroupeLastAccess(userId, troupeId).then(function(didUpdate) {
57 assert.strictEqual(didUpdate, true);
61 it('should update on update', function() {
62 var userId = new ObjectID();
63 var troupeId = new ObjectID();
64 var troupeId2 = new ObjectID();
66 .saveUserTroupeLastAccess(userId, troupeId)
67 .then(function(didUpdate) {
68 assert.strictEqual(didUpdate, true);
69 return recentRoomCore.saveUserTroupeLastAccess(userId, troupeId2);
71 .then(function(didUpdate) {
72 assert.strictEqual(didUpdate, true);
76 it('should not update when the date is equal', function() {
77 var userId = new ObjectID();
78 var troupeId = new ObjectID();
79 var lastAccessTime = new Date();
80 var lastAccessTimeOld = new Date(lastAccessTime - 1000);
83 .saveUserTroupeLastAccess(userId, troupeId, lastAccessTime)
84 .then(function(didUpdate) {
85 assert.strictEqual(didUpdate, true);
86 return recentRoomCore.saveUserTroupeLastAccess(userId, troupeId, lastAccessTimeOld);
88 .then(function(didUpdate) {
89 assert.strictEqual(didUpdate, false);