Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-24 12:07:23 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-10-29 13:36:55 -0400
commitcffd9ddeb0143d027ed7407a819552881b0fefb3 (patch)
tree47fd00b7178ef851f67887048bbfdbb0d562bab6 /test
parent312142b3e8072771fba6f617cec04b5d62614152 (diff)
downloadliza-cffd9ddeb0143d027ed7407a819552881b0fefb3.tar.gz
liza-cffd9ddeb0143d027ed7407a819552881b0fefb3.tar.bz2
liza-cffd9ddeb0143d027ed7407a819552881b0fefb3.zip
RatingServiceTest: Add type information for stubs
This also gets rid of the RatingServiceStub module, which is not used by anything else. I suspect that I originally added it to be shared by traits, but that's no longer going to be the case (and the only remaining trait is unfortunately untested atm, and will be going away).
Diffstat (limited to 'test')
-rw-r--r--test/server/service/RatingServiceTest.ts154
1 files changed, 149 insertions, 5 deletions
diff --git a/test/server/service/RatingServiceTest.ts b/test/server/service/RatingServiceTest.ts
index 8330bea..dfee767 100644
--- a/test/server/service/RatingServiceTest.ts
+++ b/test/server/service/RatingServiceTest.ts
@@ -22,7 +22,19 @@
import { expect } from 'chai';
import { RatingService as Sut } from "../../../src/server/service/RatingService";
-const RatingServiceStub = require( '../../../' ).test.server.service.RatingServiceStub;
+import { ClientActions } from "../../../src/client/action/ClientAction";
+import { PriorityLog } from "../../../src/server/log/PriorityLog";
+import { ProcessManager } from "../../../src/server/rater/ProcessManager";
+import { Program } from "../../../src/program/Program";
+import { QuoteId } from "../../../src/quote/Quote";
+import { Rater, RateResult } from "../../../src/server/rater/Rater";
+import { Server } from "../../../src/server/Server";
+import { ServerDao } from "../../../src/server/db/ServerDao";
+import { ServerSideQuote } from "../../../src/server/quote/ServerSideQuote";
+import { UserRequest } from "../../../src/server/request/UserRequest";
+import { UserResponse } from "../../../src/server/request/UserResponse";
+import { UserSession } from "../../../src/server/request/UserSession";
+
describe( 'RatingService', () =>
{
@@ -40,12 +52,14 @@ describe( 'RatingService', () =>
request,
response,
quote,
- } = RatingServiceStub.getStubs();
+ } = getStubs();
dao.mergeBucket = () =>
{
expect( processed ).to.equal( true );
done();
+
+ return dao;
};
const sut = new class extends Sut
@@ -63,8 +77,8 @@ describe( 'RatingService', () =>
{
let getLastPremiumDateCallCount = 0;
- const last_date = 1234;
- const initial_date = 2345;
+ const last_date = <UnixTimestamp>1234;
+ const initial_date = <UnixTimestamp>2345;
const {
logger,
@@ -74,7 +88,7 @@ describe( 'RatingService', () =>
request,
response,
quote,
- } = RatingServiceStub.getStubs();
+ } = getStubs();
quote.getLastPremiumDate = () =>
{
@@ -93,6 +107,8 @@ describe( 'RatingService', () =>
expect( resp.lastRatedDate ).to.equal( last_date );
done();
+
+ return server;
};
sut.request( request, response, quote, "", () => {} );
@@ -100,3 +116,131 @@ describe( 'RatingService', () =>
} );
} );
+
+
+function getStubs()
+{
+ const program_id = 'foo';
+
+ const program = <Program>{
+ getId: () => program_id,
+ ineligibleLockCount: 0,
+ };
+
+ // rate reply
+ const stub_rate_data: RateResult = {
+ _unavailable_all: '0',
+ };
+
+ const rater = new class implements Rater
+ {
+ rate(
+ _quote: ServerSideQuote,
+ _session: UserSession,
+ _indv: string,
+ success: ( data: RateResult, actions: ClientActions ) => void,
+ )
+ {
+ success( stub_rate_data, [] );
+ return this;
+ }
+ };
+
+ const raters = <ProcessManager>{
+ byId: () => rater,
+ };
+
+ const logger = new class implements PriorityLog
+ {
+ readonly PRIORITY_ERROR: number = 0;
+ readonly PRIORITY_IMPORTANT: number = 1;
+ readonly PRIORITY_DB: number = 2;
+ readonly PRIORITY_INFO: number = 3;
+ readonly PRIORITY_SOCKET: number = 4;
+
+ log(): this
+ {
+ return this;
+ }
+ };
+
+ const server = <Server>{
+ sendResponse: () => server,
+ sendError: () => server,
+ };
+
+ const dao = new class implements ServerDao
+ {
+ saveQuote(): this
+ {
+ return this;
+ }
+
+ mergeBucket(): this
+ {
+ return this;
+ }
+
+ saveQuoteClasses(): this
+ {
+ return this;
+ }
+
+ setWorksheets(): this
+ {
+ return this;
+ }
+
+ saveQuoteState(): this
+ {
+ throw new Error( "Unused method" );
+ }
+
+ saveQuoteLockState(): this
+ {
+ throw new Error( "Unused method" );
+ }
+
+ getWorksheet(): this
+ {
+ throw new Error( "Unused method" );
+ }
+ };
+
+ const session = <UserSession>{
+ isInternal: () => false,
+ };
+
+ const request = <UserRequest>{
+ getSession: () => session,
+ getSessionIdName: () => {},
+ };
+
+ 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,
+ };
+
+ return {
+ program: program,
+ stub_rate_data: stub_rate_data,
+ rater: rater,
+ raters: raters,
+ logger: logger,
+ server: server,
+ dao: dao,
+ session: session,
+ request: request,
+ response: response,
+ quote: quote,
+ };
+};