Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bucket/delta.ts90
-rw-r--r--test/server/dapi/TokenedDataApiTest.ts2
-rw-r--r--test/server/db/MongoServerDaoTest.js275
-rw-r--r--test/server/db/MongoServerDaoTest.ts227
-rw-r--r--test/server/request/DataProcessorTest.ts39
-rw-r--r--test/server/service/RatingServiceTest.ts35
-rw-r--r--test/server/token/MongoTokenDaoTest.ts14
7 files changed, 422 insertions, 260 deletions
diff --git a/test/bucket/delta.ts b/test/bucket/delta.ts
index a729f29..ba1d192 100644
--- a/test/bucket/delta.ts
+++ b/test/bucket/delta.ts
@@ -89,96 +89,6 @@ describe( 'Delta', () =>
dest_data: { foo: [ '' ] },
expected: {},
},
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ 'change', 'baz' ] },
- data: { foo: [ 'change', 'baz' ] },
- diff: { foo: [ 'change' ] },
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ 'bar', 'change' ] },
- data: { foo: [ 'bar', 'change' ] },
- diff: { foo: [ , 'change' ] },
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ undefined, 'change' ] },
- data: { foo: [ 'bar', 'change' ] },
- diff: { foo: [ , 'change' ] },
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ undefined, 'baz' ] },
- data: { foo: [ 'bar', 'baz' ] },
- diff: {},
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ 'bar', undefined ] },
- data: { foo: [ 'bar', 'baz' ] },
- diff: {},
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ 'bar', null ] },
- data: { foo: [ 'bar' ] },
- diff: { foo: [ , null ] },
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ 'bar', 'baz', null ] },
- data: { foo: [ 'bar', 'baz' ] },
- diff: {},
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [ 'bar', 'baz', 'quux' ] },
- data: { foo: [ 'bar', 'baz', 'quux' ] },
- diff: { foo: [ , , 'quux' ]},
- },
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz' ] },
- dest_data: { foo: [] },
- data: { foo: [ 'bar', 'baz' ] },
- diff: {},
- },
-
- // null not at end of set means unchanged
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz', 'quux' ] },
- dest_data: { foo: [ null, null, 'quux' ] },
- data: { foo: [ 'bar', 'baz', 'quux' ] },
- diff: {},
- },
- // but the last one is
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz', 'quux' ] },
- dest_data: { foo: [ null, 'baz', null ] },
- data: { foo: [ 'bar', 'baz' ] },
- diff: { foo: [ , , null ] },
- },
- // given a string of nulls, only the last one is terminating; the
- // rest are interpreted as undefined (because JSON serializes
- // undefined values to `null' -_-)
- {
- label: "",
- src_data: { foo: [ 'bar', 'baz', 'quux' ] },
- dest_data: { foo: [ null, null, null ] },
- data: { foo: [ 'bar', 'baz' ] },
- diff: { foo: [ , , null ] },
- },
] ).forEach( ( { label, src_data, dest_data, expected } ) =>
{
it( label, () =>
diff --git a/test/server/dapi/TokenedDataApiTest.ts b/test/server/dapi/TokenedDataApiTest.ts
index 27375fa..0d0a3ad 100644
--- a/test/server/dapi/TokenedDataApiTest.ts
+++ b/test/server/dapi/TokenedDataApiTest.ts
@@ -40,7 +40,7 @@ describe( 'TokenedDataApi', () =>
const expected_ns = 'foo_ns';
- ( <[string, boolean, ( e: Error|null ) => void][]>[
+ ( <[string, boolean, ( e: NullableError ) => void][]>[
[
"creates token and returns data if last_created",
true,
diff --git a/test/server/db/MongoServerDaoTest.js b/test/server/db/MongoServerDaoTest.js
index 0fa5d30..d6c8bf1 100644
--- a/test/server/db/MongoServerDaoTest.js
+++ b/test/server/db/MongoServerDaoTest.js
@@ -18,173 +18,140 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
'use strict';
-
-const chai = require( 'chai' );
-const expect = chai.expect;
-const { MongoServerDao: Sut } = require( '../../../' ).server.db;
-
-
-describe( 'MongoServerDao', () =>
-{
- describe( '#saveQuote', () =>
- {
- describe( "with no save data or push data", () =>
- {
- it( "saves entire metabucket record individually", done =>
- {
- const metadata = {
- foo: [ 'bar', 'baz' ],
- bar: [ { quux: 'quuux' } ],
+Object.defineProperty(exports, "__esModule", { value: true });
+var MongoServerDao_1 = require("../../../src/server/db/MongoServerDao");
+var chai_1 = require("chai");
+chai_1.use(require('chai-as-promised'));
+describe('MongoServerDao', function () {
+ describe('#saveQuote', function () {
+ describe("with no save data or push data", function () {
+ it("saves entire metabucket record individually", function (done) {
+ var metadata = {
+ foo: ['bar', 'baz'],
+ bar: [{ quux: 'quuux' }],
};
-
- const quote = createStubQuote( metadata );
-
- const sut = Sut( createMockDb(
- // update
- ( selector, data ) =>
- {
- expect( data.$set[ 'meta.foo' ] )
- .to.deep.equal( metadata.foo );
-
- expect( data.$set[ 'meta.bar' ] )
- .to.deep.equal( metadata.bar );
-
-
- expect( data.$push ).to.equal( undefined );
-
- done();
- }
- ) );
-
- sut.init( () =>
- sut.saveQuote( quote, () => {}, () => {} )
- );
- } );
- } );
-
- describe( "with push data", () =>
- {
- it( "adds push data to the collection", done =>
- {
- const push_data = {
- foo: [ 'bar', 'baz' ],
- bar: [ { quux: 'quuux' } ],
+ var quote = createStubQuote(metadata);
+ var sut = new MongoServerDao_1.MongoServerDao(createMockDb(
+ // update
+ function (_selector, data) {
+ chai_1.expect(data.$set['meta.foo'])
+ .to.deep.equal(metadata.foo);
+ chai_1.expect(data.$set['meta.bar'])
+ .to.deep.equal(metadata.bar);
+ chai_1.expect(data.$push).to.equal(undefined);
+ done();
+ }));
+ sut.init(function () {
+ return sut.saveQuote(quote, function () { }, function () { });
+ });
+ });
+ });
+ describe("with push data", function () {
+ it("adds push data to the collection", function (done) {
+ var push_data = {
+ foo: ['bar', 'baz'],
+ bar: [{ quux: 'quuux' }],
};
-
- const quote = createStubQuote( {} );
-
- const sut = Sut( createMockDb(
- // update
- ( selector, data ) =>
- {
- expect( data.$push[ 'foo' ] )
- .to.deep.equal( push_data.foo );
-
- expect( data.$push[ 'bar' ] )
- .to.deep.equal( push_data.bar );
-
- done();
- }
- ) );
-
- sut.init( () =>
- sut.saveQuote(
- quote,
- () => {},
- () => {},
- undefined,
- push_data
- )
- );
- } );
-
- it( "skips push data when it is an empty object", done =>
- {
- const push_data = {};
-
- const quote = createStubQuote( {} );
-
- const sut = Sut( createMockDb(
- // update
- ( selector, data ) =>
- {
- expect( data.$push ).to.equal( undefined );
-
- done();
- }
- ) );
-
- sut.init( () =>
- sut.saveQuote(
- quote,
- () => {},
- () => {},
- undefined,
- push_data
- )
- );
- } );
- } );
- } );
-} );
-
-
-function createMockDb( on_update )
-{
- const collection_quotes = {
+ var quote = createStubQuote({});
+ var sut = new MongoServerDao_1.MongoServerDao(createMockDb(
+ // update
+ function (_selector, data) {
+ chai_1.expect(data.$push['foo'])
+ .to.deep.equal(push_data.foo);
+ chai_1.expect(data.$push['bar'])
+ .to.deep.equal(push_data.bar);
+ done();
+ }));
+ sut.init(function () {
+ return sut.saveQuote(quote, function () { }, function () { }, undefined, push_data);
+ });
+ });
+ it("skips push data when it is an empty object", function (done) {
+ var push_data = {};
+ var quote = createStubQuote({});
+ var sut = new MongoServerDao_1.MongoServerDao(createMockDb(
+ // update
+ function (_selector, data) {
+ chai_1.expect(data.$push).to.equal(undefined);
+ done();
+ }));
+ sut.init(function () {
+ return sut.saveQuote(quote, function () { }, function () { }, undefined, push_data);
+ });
+ });
+ });
+ });
+});
+function createMockDb(on_update) {
+ var collection_quotes = {
update: on_update,
- createIndex: ( _, __, c ) => c(),
+ createIndex: function (_, __, c) { return c(); },
};
-
- const collection_seq = {
- find( _, __, c )
- {
- c( null, {
- toArray: c => c( null, { length: 5 } ),
- } );
+ var collection_seq = {
+ find: function (_, __, c) {
+ c(null, {
+ toArray: function (c) { return c(null, { length: 5 }); },
+ });
},
};
-
- const db = {
- collection( id, c )
- {
- const coll = ( id === 'quotes' )
+ var db = {
+ collection: function (id, c) {
+ var coll = (id === 'quotes')
? collection_quotes
: collection_seq;
-
- c( null, coll );
+ c(null, coll);
},
};
-
- const driver = {
- open: c => c( null, db ),
- on: () => {},
+ var driver = {
+ open: function (c) { return c(null, db); },
+ on: function () { },
};
-
return driver;
}
-
-
-function createStubQuote( metadata )
-{
- return {
- getBucket: () => ( {
- getData: () => {},
- } ),
-
- getMetabucket: () => ( {
- getData: () => metadata,
- } ),
-
- getId: () => 1,
- getProgramVersion: () => 0,
- getLastPremiumDate: () => 0,
- getRatedDate: () => 0,
- getExplicitLockReason: () => "",
- getExplicitLockStep: () => 0,
- isImported: () => false,
- isBound: () => false,
+function createStubQuote(metadata) {
+ var program = {
+ getId: function () { return '1'; },
+ ineligibleLockCount: 0,
+ apis: {},
+ internal: {},
+ meta: {
+ arefs: {},
+ fields: {},
+ groups: {},
+ qdata: {},
+ qtypes: {},
+ },
+ mapis: {},
+ initQuote: function () { },
+ };
+ var quote = {
+ getBucket: function () { return ({
+ getData: function () { },
+ }); },
+ getMetabucket: function () { return ({
+ getData: function () { return metadata; },
+ }); },
+ getId: function () { return 123; },
+ getProgramVersion: function () { return 'Foo'; },
+ getLastPremiumDate: function () { return 0; },
+ getRatedDate: function () { return 0; },
+ getExplicitLockReason: function () { return ""; },
+ getExplicitLockStep: function () { return 1; },
+ isImported: function () { return false; },
+ isBound: function () { return false; },
+ getTopVisitedStepId: function () { return 1; },
+ getTopSavedStepId: function () { return 1; },
+ setRatedDate: function () { return quote; },
+ setRateBucket: function () { return quote; },
+ setRatingData: function () { return quote; },
+ getRatingData: function () { return ({ _unavailable_all: '0' }); },
+ getProgram: function () { return program; },
+ setExplicitLock: function () { return quote; },
+ getProgramId: function () { return 'Foo'; },
+ getCurrentStepId: function () { return 0; },
+ setLastPremiumDate: function () { return quote; },
};
+ return quote;
}
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTW9uZ29TZXJ2ZXJEYW9UZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiTW9uZ29TZXJ2ZXJEYW9UZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBbUJHO0FBRUgsWUFBWSxDQUFDOztBQUViLHdFQUE4RTtBQUU5RSw2QkFBK0M7QUFRL0MsVUFBUSxDQUFFLE9BQU8sQ0FBRSxrQkFBa0IsQ0FBRSxDQUFFLENBQUM7QUFHMUMsUUFBUSxDQUFFLGdCQUFnQixFQUFFO0lBRXhCLFFBQVEsQ0FBRSxZQUFZLEVBQUU7UUFFcEIsUUFBUSxDQUFFLGdDQUFnQyxFQUFFO1lBRXhDLEVBQUUsQ0FBRSw2Q0FBNkMsRUFBRSxVQUFBLElBQUk7Z0JBRW5ELElBQU0sUUFBUSxHQUFHO29CQUNiLEdBQUcsRUFBRSxDQUFFLEtBQUssRUFBRSxLQUFLLENBQUU7b0JBQ3JCLEdBQUcsRUFBRSxDQUFFLEVBQUUsSUFBSSxFQUFFLE9BQU8sRUFBRSxDQUFFO2lCQUM3QixDQUFDO2dCQUVGLElBQU0sS0FBSyxHQUFHLGVBQWUsQ0FBRSxRQUFRLENBQUUsQ0FBQztnQkFFMUMsSUFBTSxHQUFHLEdBQUcsSUFBSSwrQkFBRyxDQUFFLFlBQVk7Z0JBQzdCLFNBQVM7Z0JBQ1QsVUFBRSxTQUF3QixFQUFFLElBQWlCO29CQUV6QyxhQUFNLENBQUUsSUFBSSxDQUFDLElBQUksQ0FBRSxVQUFVLENBQUUsQ0FBRTt5QkFDNUIsRUFBRSxDQUFDLElBQUksQ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== \ No newline at end of file
diff --git a/test/server/db/MongoServerDaoTest.ts b/test/server/db/MongoServerDaoTest.ts
new file mode 100644
index 0000000..b0a83bb
--- /dev/null
+++ b/test/server/db/MongoServerDaoTest.ts
@@ -0,0 +1,227 @@
+/**
+ * Tests MongoServerDao
+ *
+ * Copyright (C) 2010-2019 R-T Specialty, LLC.
+ *
+ * This file is part of the Liza Data Collection Framework.
+ *
+ * liza is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+'use strict';
+
+import { MongoServerDao as Sut } from "../../../src/server/db/MongoServerDao";
+import { MongoSelector, MongoUpdate } from "mongodb";
+import { expect, use as chai_use } from 'chai';
+import { ServerSideQuote } from "../../../src/server/quote/ServerSideQuote";
+import { PositiveInteger } from "../../../src/numeric";
+import { Program } from "../../../src/program/Program";
+import { RateResult } from "../../../src/server/rater/Rater";
+import { QuoteDataBucket } from "../../../src/bucket/QuoteDataBucket";
+import { QuoteId } from "../../../src/quote/Quote";
+
+chai_use( require( 'chai-as-promised' ) );
+
+
+describe( 'MongoServerDao', () =>
+{
+ describe( '#saveQuote', () =>
+ {
+ describe( "with no save data or push data", () =>
+ {
+ it( "saves entire metabucket record individually", done =>
+ {
+ const metadata = {
+ foo: [ 'bar', 'baz' ],
+ bar: [ { quux: 'quuux' } ],
+ };
+
+ const quote = createStubQuote( metadata );
+
+ const sut = new Sut( createMockDb(
+ // update
+ ( _selector: MongoSelector, data: MongoUpdate ) =>
+ {
+ expect( data.$set[ 'meta.foo' ] )
+ .to.deep.equal( metadata.foo );
+
+ expect( data.$set[ 'meta.bar' ] )
+ .to.deep.equal( metadata.bar );
+
+
+ expect( data.$push ).to.equal( undefined );
+
+ done();
+ }
+ ) );
+
+ sut.init( () =>
+ sut.saveQuote( quote, () => {}, () => {} )
+ );
+ } );
+ } );
+
+ describe( "with push data", () =>
+ {
+ it( "adds push data to the collection", done =>
+ {
+ const push_data = {
+ foo: [ 'bar', 'baz' ],
+ bar: [ { quux: 'quuux' } ],
+ };
+
+ const quote = createStubQuote( {} );
+
+ const sut = new Sut( createMockDb(
+ // update
+ (_selector: MongoSelector, data: MongoUpdate ) =>
+ {
+ expect( data.$push[ 'foo' ] )
+ .to.deep.equal( push_data.foo );
+
+ expect( data.$push[ 'bar' ] )
+ .to.deep.equal( push_data.bar );
+
+ done();
+ }
+ ) );
+
+ sut.init( () =>
+ sut.saveQuote(
+ quote,
+ () => {},
+ () => {},
+ undefined,
+ push_data
+ )
+ );
+ } );
+
+ it( "skips push data when it is an empty object", done =>
+ {
+ const push_data = {};
+
+ const quote = createStubQuote( {} );
+
+ const sut = new Sut( createMockDb(
+ // update
+ ( _selector: MongoSelector, data: MongoUpdate ) =>
+ {
+ expect( data.$push ).to.equal( undefined );
+
+ done();
+ }
+ ) );
+
+ sut.init( () =>
+ sut.saveQuote(
+ quote,
+ () => {},
+ () => {},
+ undefined,
+ push_data
+ )
+ );
+ } );
+ } );
+ } );
+} );
+
+
+function createMockDb( on_update: any )
+{
+ const collection_quotes = {
+ update: on_update,
+ createIndex: ( _: any, __: any, c: any ) => c(),
+ };
+
+ const collection_seq = {
+ find( _: any, __: any, c: any )
+ {
+ c( null, {
+ toArray: ( c: any ) => c( null, { length: 5 } ),
+ } );
+ },
+ };
+
+ const db = {
+ collection( id: any, c: any )
+ {
+ const coll = ( id === 'quotes' )
+ ? collection_quotes
+ : collection_seq;
+
+ c( null, coll );
+ },
+ };
+
+ const driver = {
+ open: ( c: any ) => c( null, db ),
+ on: () => {},
+ };
+
+ return driver;
+}
+
+
+function createStubQuote( metadata: Record<string, any> )
+{
+ const program = <Program>{
+ getId: () => '1',
+ ineligibleLockCount: 0,
+ apis: {},
+ internal: {},
+ meta: {
+ arefs: {},
+ fields: {},
+ groups: {},
+ qdata: {},
+ qtypes: {},
+ },
+ mapis: {},
+ initQuote: () => {},
+ };
+
+ const quote = <ServerSideQuote>{
+ getBucket: () => <QuoteDataBucket>( {
+ getData: () => {},
+ } ),
+
+ getMetabucket: () => <QuoteDataBucket>( {
+ getData: () => metadata,
+ } ),
+
+ getId: () => <QuoteId>123,
+ getProgramVersion: () => 'Foo',
+ getLastPremiumDate: () => <UnixTimestamp>0,
+ getRatedDate: () => <UnixTimestamp>0,
+ getExplicitLockReason: () => "",
+ getExplicitLockStep: () => <PositiveInteger>1,
+ isImported: () => false,
+ isBound: () => false,
+ getTopVisitedStepId: () => <PositiveInteger>1,
+ getTopSavedStepId: () => <PositiveInteger>1,
+ setRatedDate: () => quote,
+ setRateBucket: () => quote,
+ setRatingData: () => quote,
+ getRatingData: () => <RateResult>{ _unavailable_all: '0' },
+ getProgram: () => program,
+ setExplicitLock: () => quote,
+ getProgramId: () => 'Foo',
+ getCurrentStepId: () => 0,
+ setLastPremiumDate: () => quote,
+ };
+
+ return quote;
+}
diff --git a/test/server/request/DataProcessorTest.ts b/test/server/request/DataProcessorTest.ts
index a3a4d0e..2be9d61 100644
--- a/test/server/request/DataProcessorTest.ts
+++ b/test/server/request/DataProcessorTest.ts
@@ -713,7 +713,44 @@ function createStubQuote()
getBucket()
{
return new QuoteDataBucket();
- }
+ },
+
+ getMetabucket(){
+ return new QuoteDataBucket();
+ },
+
+ getProgramVersion(){
+ return 'Foo';
+ },
+
+ getExplicitLockReason(){
+ return 'Reason';
+ },
+
+ getExplicitLockStep()
+ {
+ return <PositiveInteger>1;
+ },
+
+ isImported()
+ {
+ return true;
+ },
+
+ isBound()
+ {
+ return true;
+ },
+
+ getTopVisitedStepId()
+ {
+ return <PositiveInteger>1;
+ },
+
+ getTopSavedStepId()
+ {
+ return <PositiveInteger>1;
+ },
};
}
diff --git a/test/server/service/RatingServiceTest.ts b/test/server/service/RatingServiceTest.ts
index 8896c49..546118c 100644
--- a/test/server/service/RatingServiceTest.ts
+++ b/test/server/service/RatingServiceTest.ts
@@ -36,6 +36,7 @@ import { UserRequest } from "../../../src/server/request/UserRequest";
import { UserResponse } from "../../../src/server/request/UserResponse";
import { UserSession } from "../../../src/server/request/UserSession";
import { QuoteDataBucket } from "../../../src/bucket/QuoteDataBucket";
+import { PositiveInteger } from "../../../src/numeric";
import { Kv } from "../../../src/bucket/delta";
import {
@@ -573,19 +574,27 @@ function getStubs()
const response = <UserResponse>{};
const quote = <ServerSideQuote>{
- getProgramId: () => program_id,
- getProgram: () => program,
- getId: () => <QuoteId>0,
- setLastPremiumDate: () => quote,
- setRatedDate: () => quote,
- getRatedDate: () => <UnixTimestamp>0,
- getLastPremiumDate: () => <UnixTimestamp>0,
- getCurrentStepId: () => 0,
- setExplicitLock: () => quote,
- setRateBucket: () => quote,
- setRatingData: () => quote,
- getRatingData: () => stub_rate_data,
- getBucket: () => new QuoteDataBucket(),
+ getProgramId: () => program_id,
+ getProgram: () => program,
+ getId: () => <QuoteId>0,
+ setLastPremiumDate: () => quote,
+ setRatedDate: () => quote,
+ getRatedDate: () => <UnixTimestamp>0,
+ getLastPremiumDate: () => <UnixTimestamp>0,
+ getCurrentStepId: () => 0,
+ setExplicitLock: () => quote,
+ setRateBucket: () => quote,
+ setRatingData: () => quote,
+ getRatingData: () => stub_rate_data,
+ getBucket: () => new QuoteDataBucket(),
+ getMetabucket: () => new QuoteDataBucket(),
+ getProgramVersion: () => 'Foo',
+ getExplicitLockReason: () => 'Reason',
+ getExplicitLockStep: () => <PositiveInteger>1,
+ isImported: () => true,
+ isBound: () => true,
+ getTopVisitedStepId: () => <PositiveInteger>1,
+ getTopSavedStepId: () => <PositiveInteger>1,
};
return {
diff --git a/test/server/token/MongoTokenDaoTest.ts b/test/server/token/MongoTokenDaoTest.ts
index 167685a..23e403e 100644
--- a/test/server/token/MongoTokenDaoTest.ts
+++ b/test/server/token/MongoTokenDaoTest.ts
@@ -26,7 +26,7 @@ import {
} from "../../../src/server/token/TokenDao";
import { MongoTokenDao as Sut } from "../../../src/server/token/MongoTokenDao";
-
+import { MongoCollection } from "mongodb";
import {
TokenId,
TokenNamespace,
@@ -248,6 +248,9 @@ describe( 'server.token.TokenDao', () =>
update() {},
findOne() {},
+ find() {},
+ createIndex() {},
+ insert() {},
};
return expect(
@@ -269,6 +272,9 @@ describe( 'server.token.TokenDao', () =>
update() {},
findOne() {},
+ find() {},
+ createIndex() {},
+ insert() {},
};
return expect(
@@ -477,6 +483,9 @@ describe( 'server.token.TokenDao', () =>
update() {},
findAndModify() {},
+ find() {},
+ createIndex() {},
+ insert() {},
};
const result = new Sut( coll, field, () => <UnixTimestamp>0 )
@@ -520,6 +529,9 @@ describe( 'server.token.TokenDao', () =>
update() {},
findAndModify() {},
+ find() {},
+ createIndex() {},
+ insert() {},
};
return expect(