Skip to content

Commit 65f9987

Browse files
committed
Move adaptors into infrastructure directories
1 parent 86df671 commit 65f9987

File tree

14 files changed

+69
-52
lines changed

14 files changed

+69
-52
lines changed

__tests__/domain/closeAccount.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FuelType, Meter, Unit } from "../../app/domain/models/Meter";
2-
import { AccountManager } from "../../app/accountClients/AccountManager";
2+
import { AccountManager } from "../../app/instrastructure/driven/accountManager/AccountManager";
33
import { closeAccount } from "../../app/domain/closeAccount";
4-
import { Instrumentation } from "../../app/instrumentation/Instrumentation";
4+
import { Instrumentation } from "../../app/instrastructure/driven/instrumentation/Instrumentation";
55

66
describe("Close Account", () => {
77
let instrumentation: Instrumentation;

__tests__/handlerHttp.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { APIGatewayProxyEvent } from "aws-lambda";
2+
import { AccountManager } from "../app/instrastructure/driven/accountManager/AccountManager";
3+
import { Instrumentation } from "../app/instrastructure/driven/instrumentation/Instrumentation";
4+
import { apiGatewayAdapter } from "../app/instrastructure/driving/apiGatewayAdapter";
5+
import { closeAccount } from "../app/domain/closeAccount";
6+
7+
describe("Close Accounts via API Gateway", () => {
8+
const instrumentation: Instrumentation = {
9+
closedAccount: () => Promise.resolve(),
10+
removedMeters: () => Promise.resolve(),
11+
};
12+
13+
let accountWithNoMeters: AccountManager;
14+
15+
beforeEach(() => {
16+
accountWithNoMeters = {
17+
closeAccount: jest.fn().mockResolvedValue(undefined),
18+
getActiveMeters: jest.fn().mockResolvedValue([]),
19+
removeMeter: jest.fn().mockResolvedValue(undefined),
20+
};
21+
});
22+
23+
test("Account ID from HTTP passed account closer", async () => {
24+
const handler = apiGatewayAdapter(closeAccount({
25+
accountManager: accountWithNoMeters,
26+
instrumentation,
27+
}));
28+
29+
const deleteEvent: Partial<APIGatewayProxyEvent> = {
30+
path: `/account`,
31+
httpMethod: "DELETE",
32+
pathParameters: { id: "test-id-1" },
33+
};
34+
const result = await handler(deleteEvent as any, {} as any, undefined as any);
35+
36+
expect(result).toMatchObject({
37+
body: "Successfully closed account",
38+
headers: { "Content-Type": "text/plain" },
39+
statusCode: 200,
40+
});
41+
expect(accountWithNoMeters.closeAccount).toBeCalledWith("test-id-1");
42+
});
43+
});
Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { APIGatewayProxyEvent, S3Event } from "aws-lambda";
2-
import { AccountManager } from "../app/accountClients/AccountManager";
3-
import { Instrumentation } from "../app/instrumentation/Instrumentation";
1+
import { S3Event } from "aws-lambda";
2+
import { AccountManager } from "../app/instrastructure/driven/accountManager/AccountManager";
3+
import { Instrumentation } from "../app/instrastructure/driven/instrumentation/Instrumentation";
44
import { S3 } from "aws-sdk";
5-
import { apiGatewayAdapter } from "../app/sources/apiGatewayAdapter";
65
import { closeAccount } from "../app/domain/closeAccount";
7-
import { s3Adaptor } from "../app/sources/s3Adaptor";
6+
import { s3Adaptor } from "../app/instrastructure/driving/s3Adaptor";
87

9-
describe("Close Accounts", () => {
8+
describe("Close Accounts via S3", () => {
109
const instrumentation: Instrumentation = {
1110
closedAccount: () => Promise.resolve(),
1211
removedMeters: () => Promise.resolve(),
@@ -22,38 +21,13 @@ describe("Close Accounts", () => {
2221
};
2322
});
2423

25-
test("Account ID from HTTP passed account closer", async () => {
26-
const deps = {
27-
accountManager: accountWithNoMeters,
28-
instrumentation,
29-
};
30-
31-
const handler = apiGatewayAdapter(closeAccount(deps));
32-
33-
const deleteEvent: Partial<APIGatewayProxyEvent> = {
34-
path: `/account`,
35-
httpMethod: "DELETE",
36-
pathParameters: { id: "test-id-1" },
37-
};
38-
39-
const result = await handler(deleteEvent as any, {} as any, undefined as any);
40-
expect(result).toMatchObject({
41-
body: "Successfully closed account",
42-
headers: { "Content-Type": "text/plain" },
43-
statusCode: 200,
44-
});
45-
46-
expect(accountWithNoMeters.closeAccount).toBeCalledWith("test-id-1");
47-
});
48-
4924
test("Account ID from S3 passed account closer", async () => {
5025
const mocks3 = createMockS3Client(JSON.stringify({ id: "test-id-2" })) as any;
51-
const closeAccountDeps = {
26+
27+
const handler = s3Adaptor(closeAccount({
5228
accountManager: accountWithNoMeters,
5329
instrumentation,
54-
};
55-
56-
const handler = s3Adaptor(closeAccount(closeAccountDeps), mocks3);
30+
}), mocks3);
5731

5832
const s3PutEvent = createS3Event("test-bucket-name", "test-object-key");
5933

__tests__/source/apiGatewayAdapter.test.ts renamed to __tests__/infrastructure/driving/apiGatewayAdapter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { APIGatewayProxyEvent } from "aws-lambda";
2-
import { apiGatewayAdapter } from "../../app/sources/apiGatewayAdapter";
2+
import { apiGatewayAdapter } from "../../../app/instrastructure/driving/apiGatewayAdapter";
33

44
describe("API Gateway Adaptor", () => {
55
test("Next function invoked with Account ID from proxy event", async () => {

__tests__/source/s3Adaptor.test.ts renamed to __tests__/infrastructure/driving/s3Adaptor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { S3Event } from "aws-lambda";
2-
import { s3Adaptor } from "../../app/sources/s3Adaptor";
2+
import { s3Adaptor } from "../../../app/instrastructure/driving/s3Adaptor";
33
import { S3 } from "aws-sdk";
44

55
describe("S3 Adaptor", () => {

app/domain/closeAccount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Instrumentation } from "../instrumentation/Instrumentation";
2-
import { AccountManager } from "../accountClients/AccountManager";
1+
import { Instrumentation } from "../instrastructure/driven/instrumentation/Instrumentation";
2+
import { AccountManager } from "../instrastructure/driven/accountManager/AccountManager";
33

44
export type CloseAccount = (accountId: string) => Promise<void>;
55

app/accountClients/AccountManager.ts renamed to app/instrastructure/driven/accountManager/AccountManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meter } from "../domain/models/Meter";
1+
import { Meter } from "../../../domain/models/Meter";
22

33
export interface AccountManager {
44
closeAccount(accountId: string): Promise<void>;

app/accountClients/StubAmazingEnergyClient.ts renamed to app/instrastructure/driven/accountManager/StubAmazingEnergyClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AccountManager } from "./AccountManager";
2-
import { FuelType, Meter, Unit } from "../domain/models/Meter";
1+
import { AccountManager } from "./";
2+
import { FuelType, Meter, Unit } from "../../../domain/models/Meter";
33

44
export class StubAmazingEnergyClient implements AccountManager {
55
private static readonly ELECTRICITY_METER: Readonly<Meter> = {

app/instrumentation/Instrumentation.ts renamed to app/instrastructure/driven/instrumentation/Instrumentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meter } from "../domain/models/Meter";
1+
import { Meter } from "../../../domain/models/Meter";
22

33
export interface Instrumentation {
44
removedMeters(meters: Meter[]): Promise<void>;

app/instrumentation/StubInstrumentation.ts renamed to app/instrastructure/driven/instrumentation/StubInstrumentation.ts

File renamed without changes.

0 commit comments

Comments
 (0)