2019-09-09 13:52:15 -04:00
|
|
|
/**
|
|
|
|
* Token state management test
|
|
|
|
*
|
|
|
|
* 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 Affero 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 Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
2019-09-16 13:38:13 -04:00
|
|
|
TokenData,
|
2019-09-09 13:52:15 -04:00
|
|
|
TokenQueryResult,
|
|
|
|
TokenStatus,
|
2019-09-09 15:41:29 -04:00
|
|
|
} from "../../../src/server/token/TokenDao";
|
2019-09-09 13:52:15 -04:00
|
|
|
|
2019-09-16 13:38:13 -04:00
|
|
|
import { MongoTokenDao as Sut } from "../../../src/server/token/MongoTokenDao";
|
2019-11-07 17:38:47 -05:00
|
|
|
import { MongoCollection } from "mongodb";
|
2019-09-10 12:09:08 -04:00
|
|
|
import {
|
|
|
|
TokenId,
|
|
|
|
TokenNamespace,
|
2019-09-23 14:11:26 -04:00
|
|
|
TokenState,
|
2019-09-10 12:09:08 -04:00
|
|
|
} from "../../../src/server/token/Token";
|
|
|
|
|
2019-09-10 12:18:51 -04:00
|
|
|
import { DocumentId } from "../../../src/document/Document";
|
2019-09-17 09:44:13 -04:00
|
|
|
import { UnknownTokenError } from "../../../src/server/token/UnknownTokenError";
|
2019-09-17 15:53:29 -04:00
|
|
|
import { hasContext } from "../../../src/error/ContextError";
|
2019-09-10 12:18:51 -04:00
|
|
|
|
2019-09-10 12:09:08 -04:00
|
|
|
|
2019-09-09 15:41:29 -04:00
|
|
|
import { expect, use as chai_use } from 'chai';
|
2019-09-09 15:28:35 -04:00
|
|
|
chai_use( require( 'chai-as-promised' ) );
|
|
|
|
|
2019-09-09 13:52:15 -04:00
|
|
|
|
|
|
|
describe( 'server.token.TokenDao', () =>
|
|
|
|
{
|
|
|
|
describe( '#updateToken', () =>
|
|
|
|
{
|
2019-09-23 14:11:26 -04:00
|
|
|
const field = 'foo_field';
|
|
|
|
const did = <DocumentId>12345;
|
|
|
|
const ns = <TokenNamespace>'namespace';
|
|
|
|
const tok_id = <TokenId>'tok123';
|
|
|
|
const tok_type = TokenState.DONE;
|
|
|
|
const data = "some data";
|
|
|
|
const timestamp = <UnixTimestamp>12345;
|
|
|
|
|
|
|
|
const root = field + '.' + ns;
|
|
|
|
|
|
|
|
const last_tok_id = <TokenId>'last-tok';
|
|
|
|
|
|
|
|
const last: TokenStatus = {
|
|
|
|
type: TokenState.DEAD,
|
|
|
|
timestamp: <UnixTimestamp>4567,
|
|
|
|
data: "last token",
|
|
|
|
};
|
|
|
|
|
|
|
|
const prev: TokenStatus = {
|
|
|
|
type: TokenState.ACTIVE,
|
|
|
|
timestamp: <UnixTimestamp>11111,
|
|
|
|
data: "prev status",
|
|
|
|
};
|
|
|
|
|
|
|
|
( <{ label: string, given: TokenQueryResult, expected: TokenData }[]>[
|
|
|
|
{
|
|
|
|
label: "updates token and returns previous data",
|
2019-09-09 13:52:15 -04:00
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
given: {
|
|
|
|
[field]: {
|
|
|
|
[ns]: {
|
|
|
|
last: last_tok_id,
|
2019-10-01 11:39:56 -04:00
|
|
|
lastState: {
|
|
|
|
[ prev.type ]: last_tok_id,
|
|
|
|
},
|
2019-09-23 14:11:26 -04:00
|
|
|
lastStatus: {
|
|
|
|
type: last.type,
|
|
|
|
timestamp: last.timestamp,
|
|
|
|
data: last.data,
|
|
|
|
},
|
|
|
|
[tok_id]: {
|
|
|
|
status: {
|
|
|
|
type: prev.type,
|
|
|
|
timestamp: prev.timestamp,
|
|
|
|
data: prev.data,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: tok_id,
|
|
|
|
status: {
|
|
|
|
type: tok_type,
|
|
|
|
timestamp: timestamp,
|
|
|
|
data: data,
|
|
|
|
},
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {
|
|
|
|
[ prev.type ]: last_tok_id,
|
|
|
|
},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_status: prev,
|
|
|
|
prev_last: {
|
|
|
|
id: last_tok_id,
|
|
|
|
status: last,
|
|
|
|
prev_status: null,
|
|
|
|
prev_last: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-09 13:52:15 -04:00
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
{
|
|
|
|
label: "returns null for prev status if missing data",
|
|
|
|
|
|
|
|
given: {
|
|
|
|
[field]: {
|
|
|
|
[ns]: {
|
|
|
|
last: last_tok_id,
|
|
|
|
lastStatus: {
|
|
|
|
type: last.type,
|
|
|
|
timestamp: last.timestamp,
|
|
|
|
data: last.data,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: tok_id,
|
|
|
|
status: {
|
|
|
|
type: tok_type,
|
|
|
|
timestamp: timestamp,
|
|
|
|
data: data,
|
|
|
|
},
|
|
|
|
prev_status: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_last: {
|
|
|
|
id: last_tok_id,
|
|
|
|
status: last,
|
|
|
|
prev_status: null,
|
|
|
|
prev_last: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: "returns null for missing namespace data",
|
|
|
|
|
|
|
|
given: {
|
|
|
|
[field]: {
|
|
|
|
[ns]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: tok_id,
|
|
|
|
status: {
|
|
|
|
type: tok_type,
|
|
|
|
timestamp: timestamp,
|
|
|
|
data: data,
|
|
|
|
},
|
|
|
|
prev_status: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_last: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: "returns null for missing namespace",
|
|
|
|
|
|
|
|
given: {
|
|
|
|
[field]: {},
|
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
id: tok_id,
|
|
|
|
status: {
|
|
|
|
type: tok_type,
|
|
|
|
timestamp: timestamp,
|
|
|
|
data: data,
|
|
|
|
},
|
|
|
|
prev_status: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_last: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: "returns null for missing root field",
|
|
|
|
|
|
|
|
given: {},
|
|
|
|
expected: {
|
|
|
|
id: tok_id,
|
|
|
|
status: {
|
|
|
|
type: tok_type,
|
|
|
|
timestamp: timestamp,
|
|
|
|
data: data,
|
|
|
|
},
|
|
|
|
prev_status: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_last: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
] ).forEach( ( { given, expected, label } ) => it( label, () =>
|
|
|
|
{
|
2019-09-09 13:52:15 -04:00
|
|
|
const coll: MongoCollection = {
|
2019-09-23 14:11:26 -04:00
|
|
|
findAndModify( selector, _sort, given_data, options, callback )
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
const expected_entry: TokenStatus = {
|
|
|
|
type: tok_type,
|
2019-09-09 16:23:15 -04:00
|
|
|
timestamp: timestamp,
|
2019-09-09 13:52:15 -04:00
|
|
|
data: data,
|
|
|
|
};
|
|
|
|
|
2019-09-10 12:18:51 -04:00
|
|
|
expect( selector.id ).to.equal( did );
|
2019-09-09 13:52:15 -04:00
|
|
|
|
|
|
|
expect( given_data ).to.deep.equal( {
|
|
|
|
$set: {
|
2019-10-01 11:39:56 -04:00
|
|
|
[ `${root}.last` ]: tok_id,
|
|
|
|
[ `${root}.lastState.${tok_type}` ]: tok_id,
|
|
|
|
[ `${root}.lastStatus` ]: expected_entry,
|
|
|
|
[ `${root}.${tok_id}.status` ]: expected_entry,
|
2019-09-09 13:52:15 -04:00
|
|
|
},
|
|
|
|
$push: {
|
2019-09-23 14:11:26 -04:00
|
|
|
[ `${root}.${tok_id}.statusLog` ]: expected_entry,
|
2019-09-09 13:52:15 -04:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
expect( options ).to.deep.equal( {
|
|
|
|
upsert: true,
|
|
|
|
new: false,
|
|
|
|
fields: {
|
|
|
|
[ `${root}.last` ]: 1,
|
2019-10-01 11:39:56 -04:00
|
|
|
[ `${root}.lastState` ]: 1,
|
2019-09-23 14:11:26 -04:00
|
|
|
[ `${root}.lastStatus` ]: 1,
|
|
|
|
[ `${root}.${tok_id}.status` ]: 1,
|
|
|
|
},
|
|
|
|
} );
|
2019-09-09 13:52:15 -04:00
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
callback( null, given );
|
2019-09-09 13:52:15 -04:00
|
|
|
},
|
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
update() {},
|
2019-09-09 13:52:15 -04:00
|
|
|
findOne() {},
|
2019-11-07 17:38:47 -05:00
|
|
|
find() {},
|
|
|
|
createIndex() {},
|
|
|
|
insert() {},
|
2019-09-09 13:52:15 -04:00
|
|
|
};
|
|
|
|
|
2019-09-18 11:18:16 -04:00
|
|
|
return expect(
|
|
|
|
new Sut( coll, field, () => timestamp )
|
|
|
|
.updateToken( did, ns, tok_id, tok_type, data )
|
2019-09-23 14:11:26 -04:00
|
|
|
).to.eventually.deep.equal( expected );
|
|
|
|
} ) );
|
2019-09-09 13:52:15 -04:00
|
|
|
|
|
|
|
|
2019-09-09 15:28:35 -04:00
|
|
|
it( 'proxies error to callback', () =>
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
const expected_error = Error( "expected error" );
|
|
|
|
|
|
|
|
const coll: MongoCollection = {
|
2019-09-23 14:11:26 -04:00
|
|
|
findAndModify( _selector, _sort, _update, _options, callback )
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
callback( expected_error, {} );
|
|
|
|
},
|
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
update() {},
|
2019-09-09 13:52:15 -04:00
|
|
|
findOne() {},
|
2019-11-07 17:38:47 -05:00
|
|
|
find() {},
|
|
|
|
createIndex() {},
|
|
|
|
insert() {},
|
2019-09-09 13:52:15 -04:00
|
|
|
};
|
|
|
|
|
2019-09-09 15:28:35 -04:00
|
|
|
return expect(
|
2019-09-10 12:09:08 -04:00
|
|
|
new Sut( coll, 'foo', () => <UnixTimestamp>0 ).updateToken(
|
2019-09-10 12:18:51 -04:00
|
|
|
<DocumentId>0,
|
|
|
|
<TokenNamespace>'ns',
|
|
|
|
<TokenId>'id',
|
2019-09-23 14:11:26 -04:00
|
|
|
TokenState.DONE,
|
2019-09-10 12:18:51 -04:00
|
|
|
null
|
2019-09-10 12:09:08 -04:00
|
|
|
)
|
2019-09-09 15:28:35 -04:00
|
|
|
).to.eventually.be.rejectedWith( expected_error );
|
2019-09-09 13:52:15 -04:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
describe( '#getToken', () =>
|
|
|
|
{
|
|
|
|
const field = 'get_field';
|
2019-09-10 12:18:51 -04:00
|
|
|
const did = <DocumentId>12345;
|
2019-09-10 12:09:08 -04:00
|
|
|
const ns = <TokenNamespace>'get_ns';
|
2019-09-09 13:52:15 -04:00
|
|
|
|
|
|
|
const expected_status: TokenStatus = {
|
2019-09-23 14:11:26 -04:00
|
|
|
type: TokenState.ACTIVE,
|
2019-09-10 12:09:08 -04:00
|
|
|
timestamp: <UnixTimestamp>0,
|
2019-09-09 13:52:15 -04:00
|
|
|
data: "",
|
|
|
|
};
|
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
const last_tok_id = <TokenId>'last-tok';
|
|
|
|
|
|
|
|
const last: TokenStatus = {
|
|
|
|
type: TokenState.DEAD,
|
|
|
|
timestamp: <UnixTimestamp>4567,
|
|
|
|
data: "last token",
|
|
|
|
};
|
|
|
|
|
2019-09-17 15:53:29 -04:00
|
|
|
( <[string, TokenId, TokenQueryResult, TokenData|null, any, any][]>[
|
2019-09-09 13:52:15 -04:00
|
|
|
[
|
|
|
|
'retrieves token by id',
|
2019-09-10 12:09:08 -04:00
|
|
|
<TokenId>'tok123',
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
[field]: {
|
|
|
|
[ns]: {
|
2019-09-23 14:11:26 -04:00
|
|
|
last: last_tok_id,
|
2019-10-01 11:39:56 -04:00
|
|
|
lastState: {
|
|
|
|
[ TokenState.ACTIVE ]: last_tok_id,
|
|
|
|
[ TokenState.DONE ]: last_tok_id,
|
|
|
|
},
|
2019-09-23 14:11:26 -04:00
|
|
|
lastStatus: last,
|
2019-09-09 13:52:15 -04:00
|
|
|
|
|
|
|
tok123: {
|
|
|
|
status: expected_status,
|
|
|
|
statusLog: [ expected_status ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-09-23 14:11:26 -04:00
|
|
|
id: <TokenId>'tok123',
|
|
|
|
status: expected_status,
|
|
|
|
prev_status: expected_status,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {
|
|
|
|
[ TokenState.ACTIVE ]: last_tok_id,
|
|
|
|
[ TokenState.DONE ]: last_tok_id,
|
|
|
|
},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_last: {
|
|
|
|
id: last_tok_id,
|
|
|
|
status: last,
|
|
|
|
prev_status: null,
|
|
|
|
prev_last: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
}
|
2019-09-09 13:52:15 -04:00
|
|
|
},
|
2019-09-17 09:44:13 -04:00
|
|
|
null,
|
2019-09-17 15:53:29 -04:00
|
|
|
null,
|
2019-09-09 13:52:15 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
[
|
2019-09-17 09:44:13 -04:00
|
|
|
'rejects for namespace if token is not found',
|
2019-09-10 12:09:08 -04:00
|
|
|
<TokenId>'tok123',
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
[field]: {
|
|
|
|
[ns]: {
|
2019-09-23 14:11:26 -04:00
|
|
|
last: last_tok_id,
|
|
|
|
lastStatus: last,
|
2019-09-09 13:52:15 -04:00
|
|
|
|
|
|
|
// just to make sure we don't grab another tok
|
|
|
|
othertok: {
|
|
|
|
status: expected_status,
|
|
|
|
statusLog: [ expected_status ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
null,
|
2019-09-17 09:44:13 -04:00
|
|
|
`${ns}.tok123`,
|
2019-09-17 15:53:29 -04:00
|
|
|
{
|
|
|
|
doc_id: did,
|
|
|
|
ns: ns,
|
|
|
|
token_id: 'tok123',
|
|
|
|
},
|
2019-09-09 13:52:15 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
[
|
2019-09-17 09:44:13 -04:00
|
|
|
'rejects if namespace is not found',
|
2019-09-10 12:09:08 -04:00
|
|
|
<TokenId>'tok123',
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
[field]: {},
|
|
|
|
},
|
|
|
|
null,
|
2019-09-17 09:44:13 -04:00
|
|
|
ns,
|
2019-09-17 15:53:29 -04:00
|
|
|
{
|
|
|
|
doc_id: did,
|
|
|
|
ns: ns,
|
|
|
|
},
|
2019-09-09 13:52:15 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
[
|
2019-09-17 09:44:13 -04:00
|
|
|
'returns last modified token given no token id',
|
2019-09-10 12:09:08 -04:00
|
|
|
<TokenId>'',
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
[field]: {
|
|
|
|
[ns]: {
|
2019-09-23 14:11:26 -04:00
|
|
|
last: last_tok_id,
|
2019-10-01 11:39:56 -04:00
|
|
|
lastState: {
|
|
|
|
[ TokenState.DEAD ]: last_tok_id,
|
|
|
|
},
|
2019-09-23 14:11:26 -04:00
|
|
|
lastStatus: last,
|
2019-09-09 13:52:15 -04:00
|
|
|
|
2019-09-23 14:11:26 -04:00
|
|
|
[ last_tok_id ]: {
|
2019-09-09 13:52:15 -04:00
|
|
|
status: expected_status,
|
|
|
|
statusLog: [ expected_status ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-09-23 14:11:26 -04:00
|
|
|
id: last_tok_id,
|
|
|
|
status: last,
|
|
|
|
prev_status: last,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {
|
|
|
|
[ TokenState.DEAD ]: last_tok_id,
|
|
|
|
},
|
2019-09-23 14:11:26 -04:00
|
|
|
prev_last: {
|
|
|
|
id: last_tok_id,
|
|
|
|
status: last,
|
|
|
|
prev_status: null,
|
|
|
|
prev_last: null,
|
2019-10-01 11:39:56 -04:00
|
|
|
prev_state: {},
|
2019-09-23 14:11:26 -04:00
|
|
|
}
|
2019-09-09 13:52:15 -04:00
|
|
|
},
|
2019-09-17 09:44:13 -04:00
|
|
|
null,
|
2019-09-17 15:53:29 -04:00
|
|
|
null,
|
2019-09-17 09:44:13 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
'rejects unknown last modified token given no token id',
|
|
|
|
<TokenId>'',
|
|
|
|
{
|
|
|
|
[field]: {
|
|
|
|
[ns]: {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
ns,
|
2019-09-17 15:53:29 -04:00
|
|
|
{
|
|
|
|
doc_id: did,
|
|
|
|
ns: ns,
|
|
|
|
},
|
2019-09-17 09:44:13 -04:00
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
'rejects unknown namespace token given no token id',
|
|
|
|
<TokenId>'',
|
|
|
|
{
|
|
|
|
[field]: {},
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
ns,
|
2019-09-17 15:53:29 -04:00
|
|
|
{
|
|
|
|
doc_id: did,
|
|
|
|
ns: ns,
|
|
|
|
},
|
2019-09-09 13:52:15 -04:00
|
|
|
],
|
2019-09-17 15:53:29 -04:00
|
|
|
] ).forEach( ( [ label, tok_id, dbresult, expected, fmsg, fcontext ] ) =>
|
2019-09-09 15:28:35 -04:00
|
|
|
it( label, () =>
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
const coll: MongoCollection = {
|
2019-09-23 14:11:26 -04:00
|
|
|
findOne( selector, { fields }, callback )
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
2019-09-23 14:11:26 -04:00
|
|
|
const expected_fields = {
|
|
|
|
[ `${field}.${ns}.last` ]: 1,
|
2019-10-01 11:39:56 -04:00
|
|
|
[ `${field}.${ns}.lastState` ]: 1,
|
2019-09-23 14:11:26 -04:00
|
|
|
[ `${field}.${ns}.lastStatus` ]: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( tok_id )
|
|
|
|
{
|
|
|
|
expected_fields[ `${field}.${ns}.${tok_id}` ] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect( fields ).to.deep.equal( expected_fields );
|
|
|
|
expect( selector ).to.deep.equal( { id: did } );
|
|
|
|
|
2019-09-17 09:44:13 -04:00
|
|
|
callback( null, dbresult );
|
2019-09-09 13:52:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
update() {},
|
2019-09-23 14:11:26 -04:00
|
|
|
findAndModify() {},
|
2019-11-07 17:38:47 -05:00
|
|
|
find() {},
|
|
|
|
createIndex() {},
|
|
|
|
insert() {},
|
2019-09-09 13:52:15 -04:00
|
|
|
};
|
|
|
|
|
2019-09-17 09:44:13 -04:00
|
|
|
const result = new Sut( coll, field, () => <UnixTimestamp>0 )
|
|
|
|
.getToken( did, ns, tok_id );
|
|
|
|
|
2019-09-17 15:53:29 -04:00
|
|
|
return ( fmsg !== null )
|
2019-09-17 09:44:13 -04:00
|
|
|
? Promise.all( [
|
|
|
|
expect( result ).to.eventually.be.rejectedWith(
|
2019-09-17 15:53:29 -04:00
|
|
|
UnknownTokenError, fmsg
|
2019-09-17 09:44:13 -04:00
|
|
|
),
|
|
|
|
expect( result ).to.eventually.be.rejectedWith(
|
|
|
|
UnknownTokenError, ''+did
|
|
|
|
),
|
2019-09-17 15:53:29 -04:00
|
|
|
result.catch( e =>
|
|
|
|
{
|
|
|
|
if ( !hasContext( e ) )
|
|
|
|
{
|
|
|
|
// TS will soon have type assertions and
|
|
|
|
// then this conditional and return can be
|
|
|
|
// removed
|
|
|
|
return expect.fail();
|
|
|
|
}
|
|
|
|
|
|
|
|
return expect( e.context ).to.deep.equal( fcontext );
|
|
|
|
} ),
|
2019-09-17 09:44:13 -04:00
|
|
|
] )
|
|
|
|
: expect( result ).to.eventually.deep.equal( expected );
|
2019-09-09 13:52:15 -04:00
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2019-09-09 15:28:35 -04:00
|
|
|
it( 'proxies error to callback', () =>
|
2019-09-09 13:52:15 -04:00
|
|
|
{
|
|
|
|
const expected_error = Error( "expected error" );
|
|
|
|
|
|
|
|
const coll: MongoCollection = {
|
|
|
|
findOne( _selector, _fields, callback )
|
|
|
|
{
|
|
|
|
callback( expected_error, {} );
|
|
|
|
},
|
|
|
|
|
|
|
|
update() {},
|
2019-09-23 14:11:26 -04:00
|
|
|
findAndModify() {},
|
2019-11-07 17:38:47 -05:00
|
|
|
find() {},
|
|
|
|
createIndex() {},
|
|
|
|
insert() {},
|
2019-09-09 13:52:15 -04:00
|
|
|
};
|
|
|
|
|
2019-09-09 15:28:35 -04:00
|
|
|
return expect(
|
2019-09-10 12:09:08 -04:00
|
|
|
new Sut( coll, 'foo', () => <UnixTimestamp>0 )
|
2019-09-10 12:18:51 -04:00
|
|
|
.getToken( <DocumentId>0, <TokenNamespace>'ns', <TokenId>'id' )
|
2019-09-09 15:28:35 -04:00
|
|
|
).to.eventually.be.rejectedWith( expected_error );
|
2019-09-09 13:52:15 -04:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|