Skip to content

Commit

Permalink
refactor: combine messages and messageDelivery
Browse files Browse the repository at this point in the history
Makes for a simpler interface in the targets, reduces duplication between the different targets.

Might be able to move the deliveryDestination selection logic later?
  • Loading branch information
jagregory committed Dec 9, 2021
1 parent 3deca80 commit 635c527
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 329 deletions.
6 changes: 2 additions & 4 deletions integration-tests/aws-sdk/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Logger } from "pino";
import { promisify } from "util";
import { createServer } from "../../src";
import { MockLogger } from "../../src/__tests__/mockLogger";
import { newMockMessageDelivery } from "../../src/__tests__/mockMessageDelivery";
import { DefaultConfig } from "../../src/server/config";
import {
Clock,
Expand Down Expand Up @@ -59,10 +60,7 @@ export const withCognitoSdk =
clock,
cognito: cognitoClient,
config: DefaultConfig,
messageDelivery: {
deliver: jest.fn(),
},
messages: new MessagesService(triggers),
messages: new MessagesService(triggers, newMockMessageDelivery()),
otp,
triggers,
tokenGenerator: new JwtTokenGenerator(
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/mockMessageDelivery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageDelivery } from "../services";
import { MessageDelivery } from "../services/messageDelivery/messageDelivery";

export const newMockMessageDelivery = (): jest.Mocked<MessageDelivery> => ({
deliver: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/mockMessages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Messages } from "../services";

export const newMockMessages = (): jest.Mocked<Messages> => ({
create: jest.fn(),
deliver: jest.fn(),
});
6 changes: 4 additions & 2 deletions src/server/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ export const createDefaultServer = async (
clock,
cognito: cognitoClient,
config,
messageDelivery: new MessageDeliveryService(new ConsoleMessageSender()),
messages: new MessagesService(triggers),
messages: new MessagesService(
triggers,
new MessageDeliveryService(new ConsoleMessageSender())
),
otp,
tokenGenerator: new JwtTokenGenerator(
clock,
Expand Down
3 changes: 0 additions & 3 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import { Clock } from "./clock";
import { Messages } from "./messages";
import { TokenGenerator } from "./tokenGenerator";
import { Triggers } from "./triggers";
import { MessageDelivery } from "./messageDelivery/messageDelivery";
import { CognitoService } from "./cognitoService";

export { Clock, DateClock } from "./clock";
export { CognitoService, CognitoServiceImpl } from "./cognitoService";
export { UserPoolService, UserPoolServiceImpl } from "./userPoolService";
export { Triggers, TriggersService } from "./triggers";
export { Lambda, LambdaService } from "./lambda";
export { MessageDelivery } from "./messageDelivery/messageDelivery";
export { Messages, MessagesService } from "./messages";

export interface Services {
clock: Clock;
cognito: CognitoService;
config: Config;
messageDelivery: MessageDelivery;
messages: Messages;
otp: () => string;
tokenGenerator: TokenGenerator;
Expand Down
Loading

0 comments on commit 635c527

Please sign in to comment.