Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-24 15:10:16 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-29 13:36:55 -0400
commit1ed8ad1cd716531a0ab573b61599a7baf8a96a9a (patch)
treead7618372a769eca1b75e41363a8ed92d3ee21cd /test
parent1aa69c2a56fe2ad46dfdf10061b9726c18f0e8d8 (diff)
downloadliza-1ed8ad1cd716531a0ab573b61599a7baf8a96a9a.tar.gz
liza-1ed8ad1cd716531a0ab573b61599a7baf8a96a9a.tar.bz2
liza-1ed8ad1cd716531a0ab573b61599a7baf8a96a9a.zip
RatingService: Return promise
This only replaces the callbacks at the highest level and starts to move toward proper error handling. The private methods do not yet properly propagate errors.
Diffstat (limited to 'test')
-rw-r--r--test/server/service/RatingServiceTest.ts44
1 files changed, 35 insertions, 9 deletions
diff --git a/test/server/service/RatingServiceTest.ts b/test/server/service/RatingServiceTest.ts
index c40ea06..c9bb108 100644
--- a/test/server/service/RatingServiceTest.ts
+++ b/test/server/service/RatingServiceTest.ts
@@ -19,7 +19,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { expect } from 'chai';
import { RatingService as Sut } from "../../../src/server/service/RatingService";
import { ClientActions } from "../../../src/client/action/ClientAction";
@@ -39,10 +38,13 @@ import {
Callback as ServerDaoCallback
} from "../../../src/server/db/ServerDao";
+import { expect, use as chai_use } from 'chai';
+chai_use( require( 'chai-as-promised' ) );
+
describe( 'RatingService', () =>
{
- it( "saves rate data to own field", done =>
+ it( "saves rate data to own field", () =>
{
const {
logger,
@@ -76,11 +78,35 @@ describe( 'RatingService', () =>
const sut = new Sut( logger, dao, server, raters );
- sut.request( request, response, quote, "", () =>
- {
- expect( saved_rates ).to.be.true;
- done();
- } );
+ return sut.request( request, response, quote, "" )
+ .then( () =>
+ {
+ expect( saved_rates ).to.be.true;
+ } );
+ } );
+
+
+ it( "rejects with error", () =>
+ {
+ const {
+ logger,
+ server,
+ raters,
+ dao,
+ request,
+ response,
+ quote,
+ rater,
+ } = getStubs();
+
+ const expected_error = new Error( "expected error" );
+
+ rater.rate = () => { throw expected_error; };
+
+ const sut = new Sut( logger, dao, server, raters );
+
+ return expect( sut.request( request, response, quote, "" ) )
+ .to.eventually.rejectedWith( expected_error );
} );
@@ -116,7 +142,7 @@ describe( 'RatingService', () =>
}
}( logger, dao, server, raters );
- sut.request( request, response, quote, 'something', () => {} );
+ return sut.request( request, response, quote, 'something' );
} );
it( "calls getLastPremiumDate during #_performRating", done =>
@@ -157,7 +183,7 @@ describe( 'RatingService', () =>
return server;
};
- sut.request( request, response, quote, "", () => {} );
+ return sut.request( request, response, quote, "" );
} );
} );