From 5b279f77cb28dd68150d56f3445a576e838d8fa0 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 18 Sep 2019 11:18:16 -0400 Subject: [PATCH] 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. --- src/server/token/MongoTokenDao.ts | 9 +++++++-- src/server/token/TokenDao.ts | 2 +- test/server/token/MongoTokenDaoTest.ts | 13 +++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/server/token/MongoTokenDao.ts b/src/server/token/MongoTokenDao.ts index 66c3c96..5e0debc 100644 --- a/src/server/token/MongoTokenDao.ts +++ b/src/server/token/MongoTokenDao.ts @@ -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 + ): Promise { const root = this._genRoot( ns ) + '.'; @@ -136,7 +138,10 @@ export class MongoTokenDao implements TokenDao return; } - resolve(); + resolve( { + id: token_id, + status: token_entry, + } ); } ); } ); diff --git a/src/server/token/TokenDao.ts b/src/server/token/TokenDao.ts index b942b2c..ebe02b0 100644 --- a/src/server/token/TokenDao.ts +++ b/src/server/token/TokenDao.ts @@ -40,7 +40,7 @@ export interface TokenDao token_id: TokenId, type: TokenType, data: string | null, - ): Promise; + ): Promise; getToken( diff --git a/test/server/token/MongoTokenDaoTest.ts b/test/server/token/MongoTokenDaoTest.ts index 8fe0dff..5af032c 100644 --- a/test/server/token/MongoTokenDaoTest.ts +++ b/test/server/token/MongoTokenDaoTest.ts @@ -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, + }, + } ); } );