1
0
Fork 0

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).
master
Mike Gerwitz 2019-10-24 12:07:23 -04:00
parent 312142b3e8
commit cffd9ddeb0
2 changed files with 149 additions and 97 deletions

View File

@ -1,92 +0,0 @@
/**
* Tests RatingService
*
* 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/>.
*/
'use strict'
exports.getStubs = function()
{
const program_id = 'foo';
const program = {
getId: () => program_id,
};
// rate reply
const stub_rate_data = {};
const rater = {
rate: ( quote, session, indv, callback ) => callback( stub_rate_data ),
};
const raters = {
byId: () => rater,
};
const logger = {
log: () => {},
};
const server = {
sendResponse: () => {},
sendError: () => {},
};
const dao = {
mergeBucket: () => {},
saveQuoteClasses: () => {},
setWorksheets: () => {},
saveQuote: () => {},
};
const session = {
isInternal: () => false,
};
const request = {
getSession: () => session,
getSessionIdName: () => {},
};
const response = {};
const quote = {
getProgramId: () => program_id,
getProgram: () => program,
getId: () => 0,
setLastPremiumDate: () => {},
setRatedDate: () => {},
getRatedDate: () => 0,
getLastPremiumDate: () => 0
};
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,
};
};

View File

@ -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,
};
};