1
0
Fork 0

TokenDao (#updateToken): Return updated data

Since some of these data are generated within TokenDao (e.g. the timestamp),
the caller cannot infer all values.

* src/server/token/MongoTokenDao.ts (updateToken): Return
  Promise<{void=>TokenData}>.
* src/server/token/TokenDao.ts (TokenDao)[#updateToken]: Update interface
  accordingly.
* test/server/token/MongoTokenDaoTest.ts: Update test accordingly.
master
Mike Gerwitz 2019-09-18 11:18:16 -04:00
parent 4454e40e19
commit 5b279f77cb
3 changed files with 19 additions and 5 deletions

View File

@ -91,6 +91,8 @@ export class MongoTokenDao implements TokenDao
* @param token token value
* @param data token data, if any
* @param status arbitrary token type
*
* @return token data
*/
updateToken(
doc_id: DocumentId,
@ -98,7 +100,7 @@ export class MongoTokenDao implements TokenDao
token_id: TokenId,
type: TokenType,
data: string | null,
): Promise<void>
): Promise<TokenData>
{
const root = this._genRoot( ns ) + '.';
@ -136,7 +138,10 @@ export class MongoTokenDao implements TokenDao
return;
}
resolve();
resolve( {
id: token_id,
status: token_entry,
} );
}
);
} );

View File

@ -40,7 +40,7 @@ export interface TokenDao
token_id: TokenId,
type: TokenType,
data: string | null,
): Promise<void>;
): Promise<TokenData>;
getToken(

View File

@ -88,8 +88,17 @@ describe( 'server.token.TokenDao', () =>
findOne() {},
};
return new Sut( coll, field, () => timestamp )
.updateToken( did, ns, tok_id, tok_type, data );
return expect(
new Sut( coll, field, () => timestamp )
.updateToken( did, ns, tok_id, tok_type, data )
).to.eventually.deep.equal( {
id: tok_id,
status: {
type: tok_type,
timestamp: timestamp,
data: data,
},
} );
} );