UserSessionsManagerTests.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. /* eslint-disable
  2. n/handle-callback-err,
  3. max-len,
  4. no-return-assign,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const sinon = require('sinon')
  15. const { expect } = require('chai')
  16. const modulePath = '../../../../app/src/Features/User/UserSessionsManager.js'
  17. const SandboxedModule = require('sandboxed-module')
  18. describe('UserSessionsManager', function () {
  19. beforeEach(function () {
  20. this.user = {
  21. _id: 'abcd',
  22. email: 'user@example.com',
  23. }
  24. this.sessionId = 'some_session_id'
  25. this.rclient = {
  26. multi: sinon.stub(),
  27. exec: sinon.stub(),
  28. get: sinon.stub(),
  29. del: sinon.stub(),
  30. sadd: sinon.stub(),
  31. srem: sinon.stub(),
  32. smembers: sinon.stub(),
  33. mget: sinon.stub(),
  34. pexpire: sinon.stub(),
  35. }
  36. this.rclient.multi.returns(this.rclient)
  37. this.rclient.get.returns(this.rclient)
  38. this.rclient.del.returns(this.rclient)
  39. this.rclient.sadd.returns(this.rclient)
  40. this.rclient.srem.returns(this.rclient)
  41. this.rclient.smembers.returns(this.rclient)
  42. this.rclient.pexpire.returns(this.rclient)
  43. this.rclient.exec.callsArgWith(0, null)
  44. this.UserSessionsRedis = {
  45. client: () => this.rclient,
  46. sessionSetKey: user => `UserSessions:{${user._id}}`,
  47. }
  48. this.settings = {
  49. redis: {
  50. web: {},
  51. },
  52. }
  53. return (this.UserSessionsManager = SandboxedModule.require(modulePath, {
  54. requires: {
  55. '@overleaf/settings': this.settings,
  56. './UserSessionsRedis': this.UserSessionsRedis,
  57. },
  58. }))
  59. })
  60. describe('_sessionKey', function () {
  61. it('should build the correct key', function () {
  62. const result = this.UserSessionsManager._sessionKey(this.sessionId)
  63. return result.should.equal('sess:some_session_id')
  64. })
  65. })
  66. describe('trackSession', function () {
  67. beforeEach(function () {
  68. this.call = callback => {
  69. return this.UserSessionsManager.trackSession(
  70. this.user,
  71. this.sessionId,
  72. callback
  73. )
  74. }
  75. this.rclient.exec.callsArgWith(0, null)
  76. return (this._checkSessions = sinon
  77. .stub(this.UserSessionsManager, '_checkSessions')
  78. .returns(null))
  79. })
  80. afterEach(function () {
  81. return this._checkSessions.restore()
  82. })
  83. it('should not produce an error', function (done) {
  84. return this.call(err => {
  85. expect(err).to.not.exist
  86. return done()
  87. })
  88. })
  89. it('should call the appropriate redis methods', function (done) {
  90. return this.call(err => {
  91. this.rclient.multi.callCount.should.equal(1)
  92. this.rclient.sadd.callCount.should.equal(1)
  93. this.rclient.pexpire.callCount.should.equal(1)
  94. this.rclient.exec.callCount.should.equal(1)
  95. return done()
  96. })
  97. })
  98. it('should call _checkSessions', function (done) {
  99. return this.call(err => {
  100. this._checkSessions.callCount.should.equal(1)
  101. return done()
  102. })
  103. })
  104. describe('when rclient produces an error', function () {
  105. beforeEach(function () {
  106. return this.rclient.exec.callsArgWith(0, new Error('woops'))
  107. })
  108. it('should produce an error', function (done) {
  109. return this.call(err => {
  110. expect(err).to.be.instanceof(Error)
  111. return done()
  112. })
  113. })
  114. it('should not call _checkSessions', function (done) {
  115. return this.call(err => {
  116. this._checkSessions.callCount.should.equal(0)
  117. return done()
  118. })
  119. })
  120. })
  121. describe('when no user is supplied', function () {
  122. beforeEach(function () {
  123. return (this.call = callback => {
  124. return this.UserSessionsManager.trackSession(
  125. null,
  126. this.sessionId,
  127. callback
  128. )
  129. })
  130. })
  131. it('should not produce an error', function (done) {
  132. return this.call(err => {
  133. expect(err).to.not.exist
  134. return done()
  135. })
  136. })
  137. it('should not call the appropriate redis methods', function (done) {
  138. return this.call(err => {
  139. this.rclient.multi.callCount.should.equal(0)
  140. this.rclient.sadd.callCount.should.equal(0)
  141. this.rclient.pexpire.callCount.should.equal(0)
  142. this.rclient.exec.callCount.should.equal(0)
  143. return done()
  144. })
  145. })
  146. it('should not call _checkSessions', function (done) {
  147. return this.call(err => {
  148. this._checkSessions.callCount.should.equal(0)
  149. return done()
  150. })
  151. })
  152. })
  153. describe('when no sessionId is supplied', function () {
  154. beforeEach(function () {
  155. return (this.call = callback => {
  156. return this.UserSessionsManager.trackSession(
  157. this.user,
  158. null,
  159. callback
  160. )
  161. })
  162. })
  163. it('should not produce an error', function (done) {
  164. return this.call(err => {
  165. expect(err).to.not.exist
  166. return done()
  167. })
  168. })
  169. it('should not call the appropriate redis methods', function (done) {
  170. return this.call(err => {
  171. this.rclient.multi.callCount.should.equal(0)
  172. this.rclient.sadd.callCount.should.equal(0)
  173. this.rclient.pexpire.callCount.should.equal(0)
  174. this.rclient.exec.callCount.should.equal(0)
  175. return done()
  176. })
  177. })
  178. it('should not call _checkSessions', function (done) {
  179. return this.call(err => {
  180. this._checkSessions.callCount.should.equal(0)
  181. return done()
  182. })
  183. })
  184. })
  185. })
  186. describe('untrackSession', function () {
  187. beforeEach(function () {
  188. this.call = callback => {
  189. return this.UserSessionsManager.untrackSession(
  190. this.user,
  191. this.sessionId,
  192. callback
  193. )
  194. }
  195. this.rclient.exec.callsArgWith(0, null)
  196. return (this._checkSessions = sinon
  197. .stub(this.UserSessionsManager, '_checkSessions')
  198. .returns(null))
  199. })
  200. afterEach(function () {
  201. return this._checkSessions.restore()
  202. })
  203. it('should not produce an error', function (done) {
  204. return this.call(err => {
  205. expect(err).to.not.exist
  206. return done()
  207. })
  208. })
  209. it('should call the appropriate redis methods', function (done) {
  210. return this.call(err => {
  211. this.rclient.multi.callCount.should.equal(1)
  212. this.rclient.srem.callCount.should.equal(1)
  213. this.rclient.pexpire.callCount.should.equal(1)
  214. this.rclient.exec.callCount.should.equal(1)
  215. return done()
  216. })
  217. })
  218. it('should call _checkSessions', function (done) {
  219. return this.call(err => {
  220. this._checkSessions.callCount.should.equal(1)
  221. return done()
  222. })
  223. })
  224. describe('when rclient produces an error', function () {
  225. beforeEach(function () {
  226. return this.rclient.exec.callsArgWith(0, new Error('woops'))
  227. })
  228. it('should produce an error', function (done) {
  229. return this.call(err => {
  230. expect(err).to.be.instanceof(Error)
  231. return done()
  232. })
  233. })
  234. it('should not call _checkSessions', function (done) {
  235. return this.call(err => {
  236. this._checkSessions.callCount.should.equal(0)
  237. return done()
  238. })
  239. })
  240. })
  241. describe('when no user is supplied', function () {
  242. beforeEach(function () {
  243. return (this.call = callback => {
  244. return this.UserSessionsManager.untrackSession(
  245. null,
  246. this.sessionId,
  247. callback
  248. )
  249. })
  250. })
  251. it('should not produce an error', function (done) {
  252. return this.call(err => {
  253. expect(err).to.not.exist
  254. return done()
  255. })
  256. })
  257. it('should not call the appropriate redis methods', function (done) {
  258. return this.call(err => {
  259. this.rclient.multi.callCount.should.equal(0)
  260. this.rclient.srem.callCount.should.equal(0)
  261. this.rclient.pexpire.callCount.should.equal(0)
  262. this.rclient.exec.callCount.should.equal(0)
  263. return done()
  264. })
  265. })
  266. it('should not call _checkSessions', function (done) {
  267. return this.call(err => {
  268. this._checkSessions.callCount.should.equal(0)
  269. return done()
  270. })
  271. })
  272. })
  273. describe('when no sessionId is supplied', function () {
  274. beforeEach(function () {
  275. return (this.call = callback => {
  276. return this.UserSessionsManager.untrackSession(
  277. this.user,
  278. null,
  279. callback
  280. )
  281. })
  282. })
  283. it('should not produce an error', function (done) {
  284. return this.call(err => {
  285. expect(err).to.not.exist
  286. return done()
  287. })
  288. })
  289. it('should not call the appropriate redis methods', function (done) {
  290. return this.call(err => {
  291. this.rclient.multi.callCount.should.equal(0)
  292. this.rclient.srem.callCount.should.equal(0)
  293. this.rclient.pexpire.callCount.should.equal(0)
  294. this.rclient.exec.callCount.should.equal(0)
  295. return done()
  296. })
  297. })
  298. it('should not call _checkSessions', function (done) {
  299. return this.call(err => {
  300. this._checkSessions.callCount.should.equal(0)
  301. return done()
  302. })
  303. })
  304. })
  305. })
  306. describe('removeSessionsFromRedis', function () {
  307. beforeEach(function () {
  308. this.sessionKeys = ['sess:one', 'sess:two']
  309. this.currentSessionID = undefined
  310. this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
  311. this.rclient.del = sinon.stub().callsArgWith(1, null)
  312. this.rclient.srem = sinon.stub().callsArgWith(2, null)
  313. return (this.call = callback => {
  314. return this.UserSessionsManager.removeSessionsFromRedis(
  315. this.user,
  316. this.currentSessionID,
  317. callback
  318. )
  319. })
  320. })
  321. it('should not produce an error', function (done) {
  322. return this.call(err => {
  323. expect(err).to.not.exist
  324. return done()
  325. })
  326. })
  327. it('should yield the number of purged sessions', function (done) {
  328. return this.call((err, n) => {
  329. expect(err).to.not.exist
  330. expect(n).to.equal(this.sessionKeys.length)
  331. return done()
  332. })
  333. })
  334. it('should call the appropriate redis methods', function (done) {
  335. return this.call(err => {
  336. this.rclient.smembers.callCount.should.equal(1)
  337. this.rclient.del.callCount.should.equal(2)
  338. expect(this.rclient.del.firstCall.args[0]).to.deep.equal(
  339. this.sessionKeys[0]
  340. )
  341. expect(this.rclient.del.secondCall.args[0]).to.deep.equal(
  342. this.sessionKeys[1]
  343. )
  344. this.rclient.srem.callCount.should.equal(1)
  345. expect(this.rclient.srem.firstCall.args[1]).to.deep.equal(
  346. this.sessionKeys
  347. )
  348. return done()
  349. })
  350. })
  351. describe('when a session is retained', function () {
  352. beforeEach(function () {
  353. this.sessionKeys = ['sess:one', 'sess:two', 'sess:three', 'sess:four']
  354. this.currentSessionID = 'two'
  355. this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
  356. this.rclient.del = sinon.stub().callsArgWith(1, null)
  357. return (this.call = callback => {
  358. return this.UserSessionsManager.removeSessionsFromRedis(
  359. this.user,
  360. this.currentSessionID,
  361. callback
  362. )
  363. })
  364. })
  365. it('should not produce an error', function (done) {
  366. return this.call(err => {
  367. expect(err).to.not.exist
  368. return done()
  369. })
  370. })
  371. it('should call the appropriate redis methods', function (done) {
  372. return this.call(err => {
  373. this.rclient.smembers.callCount.should.equal(1)
  374. this.rclient.del.callCount.should.equal(this.sessionKeys.length - 1)
  375. this.rclient.srem.callCount.should.equal(1)
  376. return done()
  377. })
  378. })
  379. it('should remove all sessions except for the retained one', function (done) {
  380. return this.call(err => {
  381. expect(this.rclient.del.firstCall.args[0]).to.deep.equal('sess:one')
  382. expect(this.rclient.del.secondCall.args[0]).to.deep.equal(
  383. 'sess:three'
  384. )
  385. expect(this.rclient.del.thirdCall.args[0]).to.deep.equal('sess:four')
  386. expect(this.rclient.srem.firstCall.args[1]).to.deep.equal([
  387. 'sess:one',
  388. 'sess:three',
  389. 'sess:four',
  390. ])
  391. return done()
  392. })
  393. })
  394. })
  395. describe('when rclient produces an error', function () {
  396. beforeEach(function () {
  397. return (this.rclient.del = sinon
  398. .stub()
  399. .callsArgWith(1, new Error('woops')))
  400. })
  401. it('should produce an error', function (done) {
  402. return this.call(err => {
  403. expect(err).to.be.instanceof(Error)
  404. return done()
  405. })
  406. })
  407. it('should not call rclient.srem', function (done) {
  408. return this.call(err => {
  409. this.rclient.srem.callCount.should.equal(0)
  410. return done()
  411. })
  412. })
  413. })
  414. describe('when no user is supplied', function () {
  415. beforeEach(function () {
  416. return (this.call = callback => {
  417. return this.UserSessionsManager.removeSessionsFromRedis(
  418. null,
  419. this.currentSessionID,
  420. callback
  421. )
  422. })
  423. })
  424. it('should produce an error', function (done) {
  425. return this.call(err => {
  426. expect(err).to.match(
  427. /bug: user not passed to removeSessionsFromRedis/
  428. )
  429. return done()
  430. })
  431. })
  432. it('should not call the appropriate redis methods', function (done) {
  433. return this.call(err => {
  434. this.rclient.smembers.callCount.should.equal(0)
  435. this.rclient.del.callCount.should.equal(0)
  436. this.rclient.srem.callCount.should.equal(0)
  437. return done()
  438. })
  439. })
  440. })
  441. describe('when there are no keys to delete', function () {
  442. beforeEach(function () {
  443. return this.rclient.smembers.callsArgWith(1, null, [])
  444. })
  445. it('should not produce an error', function (done) {
  446. return this.call(err => {
  447. expect(err).to.not.exist
  448. return done()
  449. })
  450. })
  451. it('should not do the delete operation', function (done) {
  452. return this.call(err => {
  453. this.rclient.smembers.callCount.should.equal(1)
  454. this.rclient.del.callCount.should.equal(0)
  455. this.rclient.srem.callCount.should.equal(0)
  456. return done()
  457. })
  458. })
  459. })
  460. })
  461. describe('touch', function () {
  462. beforeEach(function () {
  463. this.rclient.pexpire.callsArgWith(2, null)
  464. return (this.call = callback => {
  465. return this.UserSessionsManager.touch(this.user, callback)
  466. })
  467. })
  468. it('should not produce an error', function (done) {
  469. return this.call(err => {
  470. expect(err).to.not.exist
  471. return done()
  472. })
  473. })
  474. it('should call rclient.pexpire', function (done) {
  475. return this.call(err => {
  476. this.rclient.pexpire.callCount.should.equal(1)
  477. return done()
  478. })
  479. })
  480. describe('when rclient produces an error', function () {
  481. beforeEach(function () {
  482. return this.rclient.pexpire.callsArgWith(2, new Error('woops'))
  483. })
  484. it('should produce an error', function (done) {
  485. return this.call(err => {
  486. expect(err).to.be.instanceof(Error)
  487. return done()
  488. })
  489. })
  490. })
  491. describe('when no user is supplied', function () {
  492. beforeEach(function () {
  493. return (this.call = callback => {
  494. return this.UserSessionsManager.touch(null, callback)
  495. })
  496. })
  497. it('should not produce an error', function (done) {
  498. return this.call(err => {
  499. expect(err).to.not.exist
  500. return done()
  501. })
  502. })
  503. it('should not call pexpire', function (done) {
  504. return this.call(err => {
  505. this.rclient.pexpire.callCount.should.equal(0)
  506. return done()
  507. })
  508. })
  509. })
  510. })
  511. describe('getAllUserSessions', function () {
  512. beforeEach(function () {
  513. this.sessionKeys = ['sess:one', 'sess:two', 'sess:three']
  514. this.sessions = [
  515. '{"user": {"ip_address": "a", "session_created": "b"}}',
  516. '{"passport": {"user": {"ip_address": "c", "session_created": "d"}}}',
  517. ]
  518. this.exclude = ['two']
  519. this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
  520. this.rclient.get = sinon.stub()
  521. this.rclient.get.onCall(0).callsArgWith(1, null, this.sessions[0])
  522. this.rclient.get.onCall(1).callsArgWith(1, null, this.sessions[1])
  523. return (this.call = callback => {
  524. return this.UserSessionsManager.getAllUserSessions(
  525. this.user,
  526. this.exclude,
  527. callback
  528. )
  529. })
  530. })
  531. it('should not produce an error', function (done) {
  532. return this.call((err, sessions) => {
  533. expect(err).to.not.exist
  534. return done()
  535. })
  536. })
  537. it('should get sessions', function (done) {
  538. return this.call((err, sessions) => {
  539. expect(sessions).to.deep.equal([
  540. { ip_address: 'a', session_created: 'b' },
  541. { ip_address: 'c', session_created: 'd' },
  542. ])
  543. return done()
  544. })
  545. })
  546. it('should have called rclient.smembers', function (done) {
  547. return this.call((err, sessions) => {
  548. this.rclient.smembers.callCount.should.equal(1)
  549. return done()
  550. })
  551. })
  552. it('should have called rclient.get', function (done) {
  553. return this.call((err, sessions) => {
  554. this.rclient.get.callCount.should.equal(this.sessionKeys.length - 1)
  555. return done()
  556. })
  557. })
  558. describe('when there are no other sessions', function () {
  559. beforeEach(function () {
  560. this.sessionKeys = ['sess:two']
  561. return this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
  562. })
  563. it('should not produce an error', function (done) {
  564. return this.call((err, sessions) => {
  565. expect(err).to.not.exist
  566. return done()
  567. })
  568. })
  569. it('should produce an empty list of sessions', function (done) {
  570. return this.call((err, sessions) => {
  571. expect(sessions).to.deep.equal([])
  572. return done()
  573. })
  574. })
  575. it('should have called rclient.smembers', function (done) {
  576. return this.call((err, sessions) => {
  577. this.rclient.smembers.callCount.should.equal(1)
  578. return done()
  579. })
  580. })
  581. it('should not have called rclient.mget', function (done) {
  582. return this.call((err, sessions) => {
  583. this.rclient.mget.callCount.should.equal(0)
  584. return done()
  585. })
  586. })
  587. })
  588. describe('when smembers produces an error', function () {
  589. beforeEach(function () {
  590. return this.rclient.smembers.callsArgWith(1, new Error('woops'))
  591. })
  592. it('should produce an error', function (done) {
  593. return this.call((err, sessions) => {
  594. expect(err).to.not.equal(null)
  595. expect(err).to.be.instanceof(Error)
  596. return done()
  597. })
  598. })
  599. it('should not have called rclient.mget', function (done) {
  600. return this.call((err, sessions) => {
  601. this.rclient.mget.callCount.should.equal(0)
  602. return done()
  603. })
  604. })
  605. })
  606. describe('when get produces an error', function () {
  607. beforeEach(function () {
  608. return (this.rclient.get = sinon
  609. .stub()
  610. .callsArgWith(1, new Error('woops')))
  611. })
  612. it('should produce an error', function (done) {
  613. return this.call((err, sessions) => {
  614. expect(err).to.not.equal(null)
  615. expect(err).to.be.instanceof(Error)
  616. return done()
  617. })
  618. })
  619. })
  620. })
  621. describe('_checkSessions', function () {
  622. beforeEach(function () {
  623. this.call = callback => {
  624. return this.UserSessionsManager._checkSessions(this.user, callback)
  625. }
  626. this.sessionKeys = ['one', 'two']
  627. this.rclient.smembers.callsArgWith(1, null, this.sessionKeys)
  628. this.rclient.get.callsArgWith(1, null, 'some-value')
  629. return this.rclient.srem.callsArgWith(2, null, {})
  630. })
  631. it('should not produce an error', function (done) {
  632. return this.call(err => {
  633. expect(err).to.not.exist
  634. return done()
  635. })
  636. })
  637. it('should call the appropriate redis methods', function (done) {
  638. return this.call(err => {
  639. this.rclient.smembers.callCount.should.equal(1)
  640. this.rclient.get.callCount.should.equal(2)
  641. this.rclient.srem.callCount.should.equal(0)
  642. return done()
  643. })
  644. })
  645. describe('when one of the keys is not present in redis', function () {
  646. beforeEach(function () {
  647. this.rclient.get.onCall(0).callsArgWith(1, null, 'some-val')
  648. return this.rclient.get.onCall(1).callsArgWith(1, null, null)
  649. })
  650. it('should not produce an error', function (done) {
  651. return this.call(err => {
  652. expect(err).to.not.exist
  653. return done()
  654. })
  655. })
  656. it('should remove that key from the set', function (done) {
  657. return this.call(err => {
  658. this.rclient.smembers.callCount.should.equal(1)
  659. this.rclient.get.callCount.should.equal(2)
  660. this.rclient.srem.callCount.should.equal(1)
  661. this.rclient.srem.firstCall.args[1].should.equal('two')
  662. return done()
  663. })
  664. })
  665. })
  666. describe('when no user is supplied', function () {
  667. beforeEach(function () {
  668. return (this.call = callback => {
  669. return this.UserSessionsManager._checkSessions(null, callback)
  670. })
  671. })
  672. it('should not produce an error', function (done) {
  673. return this.call(err => {
  674. expect(err).to.not.exist
  675. return done()
  676. })
  677. })
  678. it('should not call redis methods', function (done) {
  679. return this.call(err => {
  680. this.rclient.smembers.callCount.should.equal(0)
  681. this.rclient.get.callCount.should.equal(0)
  682. return done()
  683. })
  684. })
  685. })
  686. describe('when one of the get operations produces an error', function () {
  687. beforeEach(function () {
  688. this.rclient.get.onCall(0).callsArgWith(1, new Error('woops'), null)
  689. return this.rclient.get.onCall(1).callsArgWith(1, null, null)
  690. })
  691. it('should produce an error', function (done) {
  692. return this.call(err => {
  693. expect(err).to.be.instanceof(Error)
  694. return done()
  695. })
  696. })
  697. it('should call the right redis methods, bailing out early', function (done) {
  698. return this.call(err => {
  699. this.rclient.smembers.callCount.should.equal(1)
  700. this.rclient.get.callCount.should.equal(1)
  701. this.rclient.srem.callCount.should.equal(0)
  702. return done()
  703. })
  704. })
  705. })
  706. })
  707. })