Skip to content

Commit

Permalink
refactor: refactor in memory transaction mngr proxy & transaction mnr…
Browse files Browse the repository at this point in the history
… interface (#48)
  • Loading branch information
haroldcohen authored Nov 16, 2023
1 parent f57616e commit 7a77a1b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/configuration/injection/containers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const useAppDataSources = (): void => {
const AppDataSource = new DataSource({
type: "postgres",
synchronize: true,
logging: true,
logging: false,
entities: ['src/driven/repositories/typeorm/entities/*.{ts,js}'],
subscribers: [],
migrations: ['src/driven/repositories/typeorm/migrations/*.{ts,js}'],
Expand Down
8 changes: 0 additions & 8 deletions src/core/domain/common/interfaces/transactionManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import TransactionInterface from './transaction';

/**
* Interface to manage commits and rollbacks within the system's core.
*
Expand All @@ -11,12 +9,6 @@ export default interface TransactionManagerInterface {
*/
startTransaction(): Promise<void>;

/**
* Creates and returns a new transaction
* that can be used to commit without the need of the method startTransaction().
*/
newTransaction(): TransactionInterface;

/**
* Commits a change of state in the system.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default class InMemoryTransactionManager {
}

/**
* Returns a new in memory transaction.
* Creates and returns a new transaction
* that can be used to commit without the need of the method startTransaction().
*/
newTransaction(): InMemoryTransaction {
return new InMemoryTransaction(this.unitOfWork);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import PermissionsDenyStubGateway from "tests/common/stubs/gateways/permissions/
import {buildExpectedCarsPlanning} from "tests/unit/car/query/retrieveCarsPlanning/beforeEach";
import {buildCarTestCases} from "tests/unit/car/query/retrieveCarsPlanning/each";
import UserPermissionsProfile from "src/core/useCases/common/permissions/types/userPermissionsProfile";
import InMemoryTransactionManager from "src/driven/repositories/inMemory/common/transactions/manager";

describe.each([
{
Expand Down Expand Up @@ -324,7 +325,7 @@ describe.each([

beforeEach(async () => {
useInMemoryRepositories();
const transactionManager: TransactionManagerInterface = container.resolve("TransactionManagerInterface");
const transactionManager: InMemoryTransactionManager = container.resolve("TransactionManagerInterface");
const transaction: TransactionInterface = transactionManager.newTransaction();
const unitOfWork: UnitOfWork = container.resolve("UnitOfWork");
await populateCarModel({
Expand Down Expand Up @@ -494,7 +495,7 @@ describe.each([

beforeEach(async () => {
useInMemoryRepositories();
const transactionManager: TransactionManagerInterface = container.resolve("TransactionManagerInterface");
const transactionManager: InMemoryTransactionManager = container.resolve("TransactionManagerInterface");
const transaction: TransactionInterface = transactionManager.newTransaction();
const unitOfWork: UnitOfWork = container.resolve("UnitOfWork");
await populateCarModel({
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/carRental/command/rentACar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import InMemoryCarRentalReadRepository from 'src/driven/repositories/inMemory/ca
import TransactionInterface from 'src/core/domain/common/interfaces/transaction';
import TransactionManagerInterface from 'src/core/domain/common/interfaces/transactionManager';
import UnavailableCarError from 'src/core/domain/car/errors/unavailable';
import InMemoryTransactionManager from "src/driven/repositories/inMemory/common/transactions/manager";

describe.each([
{
Expand Down Expand Up @@ -129,7 +130,7 @@ describe.each([

beforeEach(async () => {
useInMemoryRepositories();
const transactionManager: TransactionManagerInterface = container.resolve("TransactionManagerInterface");
const transactionManager: InMemoryTransactionManager = container.resolve("TransactionManagerInterface");
const transaction: TransactionInterface = transactionManager.newTransaction();
await populateCarsAndCarRentalsFromTestCase(testCase.cars);
await populateAvailableCarFromTestCase(testCase.availableCar as CarTestCaseEntry);
Expand Down Expand Up @@ -215,7 +216,7 @@ describe.each([

beforeEach(async () => {
useInMemoryRepositories();
const transactionManager: TransactionManagerInterface = container.resolve("TransactionManagerInterface");
const transactionManager: InMemoryTransactionManager = container.resolve("TransactionManagerInterface");
const transaction: TransactionInterface = transactionManager.newTransaction();
await populateAvailableCarFromTestCase(testCase.availableCar as CarTestCaseEntry);
await transaction.commit();
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/carRental/query/retrieveACarRental.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import RetrieveACarRentalQuery from 'src/core/useCases/carRental/query/retrieveA
import {populateCarModel, populateCarRental} from '../../utils/populate';
import UnitOfWork from 'src/driven/repositories/inMemory/common/unitOfWork';
import InMemoryCarRentalReadRepository from 'src/driven/repositories/inMemory/carRental/read';
import InMemoryTransactionManager from "src/driven/repositories/inMemory/common/transactions/manager";

describe.each([
{
Expand Down Expand Up @@ -76,7 +77,7 @@ describe.each([
beforeEach(async () => {
useInMemoryRepositories();
const unitOfWork: UnitOfWork = container.resolve("UnitOfWork");
const transactionManager: TransactionManagerInterface = container.resolve("TransactionManagerInterface");
const transactionManager: InMemoryTransactionManager = container.resolve("TransactionManagerInterface");
const transaction: TransactionInterface = transactionManager.newTransaction();
const totalPrice = convertToNumericPrice(testCase.carRental.totalPrice);
await populateCarRental({
Expand Down

0 comments on commit 7a77a1b

Please sign in to comment.