From 9b6ed03af797fa7b3e8d670dfffc2df36ff94a70 Mon Sep 17 00:00:00 2001 From: John Brunton Date: Mon, 26 Aug 2024 13:49:11 +0100 Subject: [PATCH 1/4] refactor: repositories directory --- .../api/src/app/dispatcher/dispatcher.service.spec.ts | 4 ++-- services/api/src/app/messages/messages.controller.spec.ts | 6 +++--- services/api/src/data/data.module.ts | 8 ++++---- .../dynamodb.memberships.repository.e2e-spec.ts | 4 ++-- .../repositories/dynamodb.messages.repository.e2e-spec.ts | 4 ++-- .../repositories/dynamodb.rooms.repository.e2e-spec.ts | 4 ++-- .../repositories/dynamodb.users.repository.e2e-spec.ts | 4 ++-- .../{ => dynamodb}/dynamodb.memberships.repository.ts | 4 ++-- .../{ => dynamodb}/dynamodb.messages.repository.ts | 4 ++-- .../{ => dynamodb}/dynamodb.rooms.repository.ts | 4 ++-- .../{ => dynamodb}/dynamodb.users.repository.ts | 4 ++-- .../repositories/test}/test.memberships.repository.ts | 0 .../repositories/test}/test.messages.repository.ts | 0 .../repositories/test}/test.rooms.repository.ts | 0 .../repositories/test}/test.users.repository.ts | 0 .../domain/usecases/memberships/approve-request.spec.ts | 4 ++-- .../api/src/domain/usecases/memberships/invite.spec.ts | 4 ++-- services/api/src/domain/usecases/memberships/join.spec.ts | 2 +- .../api/src/domain/usecases/memberships/leave.spec.ts | 2 +- .../api/src/domain/usecases/messages/get-messages.spec.ts | 4 ++-- services/api/src/domain/usecases/messages/send.spec.ts | 2 +- services/api/src/domain/usecases/rooms/about-room.spec.ts | 4 ++-- .../domain/usecases/rooms/change-room-join-policy.spec.ts | 2 +- services/api/src/domain/usecases/rooms/create.spec.ts | 2 +- services/api/src/domain/usecases/rooms/get.spec.ts | 2 +- services/api/src/domain/usecases/rooms/rename.spec.ts | 2 +- services/api/src/domain/usecases/users/rename.spec.ts | 2 +- services/api/src/fixtures/data/test.data.module.ts | 8 ++++---- 28 files changed, 45 insertions(+), 45 deletions(-) rename services/api/src/data/repositories/{ => dynamodb}/dynamodb.memberships.repository.ts (92%) rename services/api/src/data/repositories/{ => dynamodb}/dynamodb.messages.repository.ts (92%) rename services/api/src/data/repositories/{ => dynamodb}/dynamodb.rooms.repository.ts (93%) rename services/api/src/data/repositories/{ => dynamodb}/dynamodb.users.repository.ts (94%) rename services/api/src/{fixtures/data => data/repositories/test}/test.memberships.repository.ts (100%) rename services/api/src/{fixtures/data => data/repositories/test}/test.messages.repository.ts (100%) rename services/api/src/{fixtures/data => data/repositories/test}/test.rooms.repository.ts (100%) rename services/api/src/{fixtures/data => data/repositories/test}/test.users.repository.ts (100%) diff --git a/services/api/src/app/dispatcher/dispatcher.service.spec.ts b/services/api/src/app/dispatcher/dispatcher.service.spec.ts index 87209d5b..4cd8a014 100644 --- a/services/api/src/app/dispatcher/dispatcher.service.spec.ts +++ b/services/api/src/app/dispatcher/dispatcher.service.spec.ts @@ -1,6 +1,6 @@ -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { DispatcherService } from './dispatcher.service'; -import { TestMessagesRepository } from '@fixtures/data/test.messages.repository'; +import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; import { DraftMessage, SentMessage } from '@entities/messages'; import { RoomFactory } from '@fixtures/messages/room.factory'; diff --git a/services/api/src/app/messages/messages.controller.spec.ts b/services/api/src/app/messages/messages.controller.spec.ts index 72a31cda..2384f1f7 100644 --- a/services/api/src/app/messages/messages.controller.spec.ts +++ b/services/api/src/app/messages/messages.controller.spec.ts @@ -12,11 +12,11 @@ import { MessageFactory } from '@fixtures/messages/message.factory'; import { UsersRepository } from '@entities/users'; import { MessagesRepository } from '@entities/messages'; import { TestDataModule } from '@fixtures/data/test.data.module'; -import { TestUsersRepository } from '@fixtures/data/test.users.repository'; -import { TestMessagesRepository } from '@fixtures/data/test.messages.repository'; +import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; +import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository'; import { Room } from '@entities/room.entity'; import { RoomsRepository } from '@entities/rooms.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { CreateMessageDto } from './dto/messages'; import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; diff --git a/services/api/src/data/data.module.ts b/services/api/src/data/data.module.ts index 71c3d9a6..d427a3e3 100644 --- a/services/api/src/data/data.module.ts +++ b/services/api/src/data/data.module.ts @@ -2,14 +2,14 @@ import { Global, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { MessagesRepository } from '@entities/messages'; import databaseConfig from '@config/database.config'; -import { DynamoDBMessagesRepository } from './repositories/dynamodb.messages.repository'; +import { DynamoDBMessagesRepository } from './repositories/dynamodb/dynamodb.messages.repository'; import { RoomsRepository } from '@entities/rooms.repository'; import { UsersRepository } from '@entities/users'; -import { DynamoDBUsersRepository } from './repositories/dynamodb.users.repository'; +import { DynamoDBUsersRepository } from './repositories/dynamodb/dynamodb.users.repository'; import { DynamoDBAdapter } from './adapters/dynamodb.adapter'; -import { DynamoDBRoomsRepository } from './repositories/dynamodb.rooms.repository'; +import { DynamoDBRoomsRepository } from './repositories/dynamodb/dynamodb.rooms.repository'; import { MembershipsRepository } from '@entities/memberships.repository'; -import { DynamoDBMembershipsRepository } from './repositories/dynamodb.memberships.repository'; +import { DynamoDBMembershipsRepository } from './repositories/dynamodb/dynamodb.memberships.repository'; export const DatabaseConfigModule = ConfigModule.forFeature(databaseConfig); diff --git a/services/api/src/data/repositories/dynamodb.memberships.repository.e2e-spec.ts b/services/api/src/data/repositories/dynamodb.memberships.repository.e2e-spec.ts index eb742717..f23155d3 100644 --- a/services/api/src/data/repositories/dynamodb.memberships.repository.e2e-spec.ts +++ b/services/api/src/data/repositories/dynamodb.memberships.repository.e2e-spec.ts @@ -1,12 +1,12 @@ import { MembershipStatus } from '@entities/membership.entity'; import { CreateMembershipParams } from '@entities/memberships.repository'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { Test, TestingModule } from '@nestjs/testing'; import { DataModule } from '../data.module'; -import { DynamoDBMembershipsRepository } from './dynamodb.memberships.repository'; import { MockLoggerModule } from '@fixtures/MockLoggerModule'; +import { DynamoDBMembershipsRepository } from './dynamodb/dynamodb.memberships.repository'; type TestCase = { name: 'DynamoDBMembershipsRepository' | 'TestMembershipsRepository'; diff --git a/services/api/src/data/repositories/dynamodb.messages.repository.e2e-spec.ts b/services/api/src/data/repositories/dynamodb.messages.repository.e2e-spec.ts index e6af3803..4c8f8a10 100644 --- a/services/api/src/data/repositories/dynamodb.messages.repository.e2e-spec.ts +++ b/services/api/src/data/repositories/dynamodb.messages.repository.e2e-spec.ts @@ -1,6 +1,6 @@ -import { DynamoDBMessagesRepository } from '@data/repositories/dynamodb.messages.repository'; +import { DynamoDBMessagesRepository } from '@data/repositories/dynamodb/dynamodb.messages.repository'; import { DraftMessage } from '@entities/messages'; -import { TestMessagesRepository } from '@fixtures/data/test.messages.repository'; +import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { Test, TestingModule } from '@nestjs/testing'; diff --git a/services/api/src/data/repositories/dynamodb.rooms.repository.e2e-spec.ts b/services/api/src/data/repositories/dynamodb.rooms.repository.e2e-spec.ts index 3b2a16cc..65e950e4 100644 --- a/services/api/src/data/repositories/dynamodb.rooms.repository.e2e-spec.ts +++ b/services/api/src/data/repositories/dynamodb.rooms.repository.e2e-spec.ts @@ -1,7 +1,7 @@ -import { DynamoDBRoomsRepository } from '@data/repositories/dynamodb.rooms.repository'; +import { DynamoDBRoomsRepository } from '@data/repositories/dynamodb/dynamodb.rooms.repository'; import { ContentPolicy, JoinPolicy } from '@entities/room.entity'; import { CreateRoomParams } from '@entities/rooms.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { Test } from '@nestjs/testing'; import { DataModule } from '../data.module'; import { MockLoggerModule } from '@fixtures/MockLoggerModule'; diff --git a/services/api/src/data/repositories/dynamodb.users.repository.e2e-spec.ts b/services/api/src/data/repositories/dynamodb.users.repository.e2e-spec.ts index 20526b00..b691781f 100644 --- a/services/api/src/data/repositories/dynamodb.users.repository.e2e-spec.ts +++ b/services/api/src/data/repositories/dynamodb.users.repository.e2e-spec.ts @@ -1,6 +1,6 @@ -import { DynamoDBUsersRepository } from '@data/repositories/dynamodb.users.repository'; +import { DynamoDBUsersRepository } from '@data/repositories/dynamodb/dynamodb.users.repository'; import { userParamsFromAuth } from '@entities/users'; -import { TestUsersRepository } from '@fixtures/data/test.users.repository'; +import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; import { Test, TestingModule } from '@nestjs/testing'; import { DataModule } from '../data.module'; import { MockLoggerModule } from '@fixtures/MockLoggerModule'; diff --git a/services/api/src/data/repositories/dynamodb.memberships.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts similarity index 92% rename from services/api/src/data/repositories/dynamodb.memberships.repository.ts rename to services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts index f8fe9ebd..ff9ce901 100644 --- a/services/api/src/data/repositories/dynamodb.memberships.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts @@ -5,8 +5,8 @@ import { } from '@entities/memberships.repository'; import { Injectable } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../adapters/dynamodb.adapter'; -import { DbMembership } from '../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; +import { DbMembership } from '../../adapters/schema'; @Injectable() export class DynamoDBMembershipsRepository extends MembershipsRepository { diff --git a/services/api/src/data/repositories/dynamodb.messages.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts similarity index 92% rename from services/api/src/data/repositories/dynamodb.messages.repository.ts rename to services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts index 02d5fead..6ce4df34 100644 --- a/services/api/src/data/repositories/dynamodb.messages.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts @@ -2,8 +2,8 @@ import { DraftMessage, SentMessage } from '@entities/messages'; import { MessagesRepository } from '@entities/messages'; import { Injectable } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../adapters/dynamodb.adapter'; -import { DbMessage } from '../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; +import { DbMessage } from '../../adapters/schema'; @Injectable() export class DynamoDBMessagesRepository extends MessagesRepository { diff --git a/services/api/src/data/repositories/dynamodb.rooms.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts similarity index 93% rename from services/api/src/data/repositories/dynamodb.rooms.repository.ts rename to services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts index 0e15b72b..cc0694c0 100644 --- a/services/api/src/data/repositories/dynamodb.rooms.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts @@ -7,8 +7,8 @@ import { } from '@entities/rooms.repository'; import { Injectable, NotFoundException } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../adapters/dynamodb.adapter'; -import { DbRoom } from '../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; +import { DbRoom } from '../../adapters/schema'; @Injectable() export class DynamoDBRoomsRepository extends RoomsRepository { diff --git a/services/api/src/data/repositories/dynamodb.users.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts similarity index 94% rename from services/api/src/data/repositories/dynamodb.users.repository.ts rename to services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts index a6cb84e4..e42f2c47 100644 --- a/services/api/src/data/repositories/dynamodb.users.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts @@ -6,8 +6,8 @@ import { } from '@entities/users'; import { Injectable, NotFoundException } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../adapters/dynamodb.adapter'; -import { DbUser } from '../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; +import { DbUser } from '../../adapters/schema'; @Injectable() export class DynamoDBUsersRepository extends UsersRepository { diff --git a/services/api/src/fixtures/data/test.memberships.repository.ts b/services/api/src/data/repositories/test/test.memberships.repository.ts similarity index 100% rename from services/api/src/fixtures/data/test.memberships.repository.ts rename to services/api/src/data/repositories/test/test.memberships.repository.ts diff --git a/services/api/src/fixtures/data/test.messages.repository.ts b/services/api/src/data/repositories/test/test.messages.repository.ts similarity index 100% rename from services/api/src/fixtures/data/test.messages.repository.ts rename to services/api/src/data/repositories/test/test.messages.repository.ts diff --git a/services/api/src/fixtures/data/test.rooms.repository.ts b/services/api/src/data/repositories/test/test.rooms.repository.ts similarity index 100% rename from services/api/src/fixtures/data/test.rooms.repository.ts rename to services/api/src/data/repositories/test/test.rooms.repository.ts diff --git a/services/api/src/fixtures/data/test.users.repository.ts b/services/api/src/data/repositories/test/test.users.repository.ts similarity index 100% rename from services/api/src/fixtures/data/test.users.repository.ts rename to services/api/src/data/repositories/test/test.users.repository.ts diff --git a/services/api/src/domain/usecases/memberships/approve-request.spec.ts b/services/api/src/domain/usecases/memberships/approve-request.spec.ts index 0fa5397c..2f72f472 100644 --- a/services/api/src/domain/usecases/memberships/approve-request.spec.ts +++ b/services/api/src/domain/usecases/memberships/approve-request.spec.ts @@ -1,7 +1,7 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { UnauthorizedException } from '@nestjs/common'; @@ -9,7 +9,7 @@ import { AppLogger } from '@app/app.logger'; import { Role } from '@usecases/auth.service'; import mock, { MockProxy } from 'jest-mock-extended/lib/Mock'; import { Dispatcher } from '@entities/messages/message'; -import { TestUsersRepository } from '@fixtures/data/test.users.repository'; +import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; import { MembershipStatus } from '@entities/membership.entity'; import { ApproveRequestUseCase } from './approve-request'; diff --git a/services/api/src/domain/usecases/memberships/invite.spec.ts b/services/api/src/domain/usecases/memberships/invite.spec.ts index 787723d6..71b21b38 100644 --- a/services/api/src/domain/usecases/memberships/invite.spec.ts +++ b/services/api/src/domain/usecases/memberships/invite.spec.ts @@ -1,7 +1,7 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { UnauthorizedException } from '@nestjs/common'; @@ -10,7 +10,7 @@ import { Role } from '@usecases/auth.service'; import mock, { MockProxy } from 'jest-mock-extended/lib/Mock'; import { Dispatcher } from '@entities/messages/message'; import { InviteUseCase } from './invite'; -import { TestUsersRepository } from '@fixtures/data/test.users.repository'; +import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; import { MembershipStatus } from '@entities/membership.entity'; describe('InviteUseCase', () => { diff --git a/services/api/src/domain/usecases/memberships/join.spec.ts b/services/api/src/domain/usecases/memberships/join.spec.ts index 0416dc61..a5782cc7 100644 --- a/services/api/src/domain/usecases/memberships/join.spec.ts +++ b/services/api/src/domain/usecases/memberships/join.spec.ts @@ -1,7 +1,7 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { UnauthorizedException } from '@nestjs/common'; diff --git a/services/api/src/domain/usecases/memberships/leave.spec.ts b/services/api/src/domain/usecases/memberships/leave.spec.ts index 26204bca..9d9b7e24 100644 --- a/services/api/src/domain/usecases/memberships/leave.spec.ts +++ b/services/api/src/domain/usecases/memberships/leave.spec.ts @@ -1,7 +1,7 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { AppLogger } from '@app/app.logger'; diff --git a/services/api/src/domain/usecases/messages/get-messages.spec.ts b/services/api/src/domain/usecases/messages/get-messages.spec.ts index 39f4abac..f9653521 100644 --- a/services/api/src/domain/usecases/messages/get-messages.spec.ts +++ b/services/api/src/domain/usecases/messages/get-messages.spec.ts @@ -1,6 +1,6 @@ -import { TestMessagesRepository } from '@fixtures/data/test.messages.repository'; +import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository'; import { UserFactory } from '@fixtures/messages/user.factory'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { GetMessagesUseCase } from './get-messages'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; diff --git a/services/api/src/domain/usecases/messages/send.spec.ts b/services/api/src/domain/usecases/messages/send.spec.ts index 57db2ac0..8fdd8b76 100644 --- a/services/api/src/domain/usecases/messages/send.spec.ts +++ b/services/api/src/domain/usecases/messages/send.spec.ts @@ -1,5 +1,5 @@ import { UserFactory } from '@fixtures/messages/user.factory'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; import { UnauthorizedException } from '@nestjs/common'; diff --git a/services/api/src/domain/usecases/rooms/about-room.spec.ts b/services/api/src/domain/usecases/rooms/about-room.spec.ts index 1dc5656f..8526a20e 100644 --- a/services/api/src/domain/usecases/rooms/about-room.spec.ts +++ b/services/api/src/domain/usecases/rooms/about-room.spec.ts @@ -1,5 +1,5 @@ import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { UnauthorizedException } from '@nestjs/common'; @@ -8,7 +8,7 @@ import { Role } from '@usecases/auth.service'; import mock, { MockProxy } from 'jest-mock-extended/lib/Mock'; import { Dispatcher } from '@entities/messages/message'; import { AboutRoomUseCase } from './about-room'; -import { TestUsersRepository } from '@fixtures/data/test.users.repository'; +import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; describe('AboutRoomUseCase', () => { let aboutRoom: AboutRoomUseCase; diff --git a/services/api/src/domain/usecases/rooms/change-room-join-policy.spec.ts b/services/api/src/domain/usecases/rooms/change-room-join-policy.spec.ts index b6f83224..f60ca259 100644 --- a/services/api/src/domain/usecases/rooms/change-room-join-policy.spec.ts +++ b/services/api/src/domain/usecases/rooms/change-room-join-policy.spec.ts @@ -1,5 +1,5 @@ import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { mock, MockProxy } from 'jest-mock-extended'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; diff --git a/services/api/src/domain/usecases/rooms/create.spec.ts b/services/api/src/domain/usecases/rooms/create.spec.ts index 61a388b5..04ec5885 100644 --- a/services/api/src/domain/usecases/rooms/create.spec.ts +++ b/services/api/src/domain/usecases/rooms/create.spec.ts @@ -1,5 +1,5 @@ import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { UserFactory } from '@fixtures/messages/user.factory'; import { CreateRoomUseCase } from './create'; import { ContentPolicy, JoinPolicy } from '@entities/room.entity'; diff --git a/services/api/src/domain/usecases/rooms/get.spec.ts b/services/api/src/domain/usecases/rooms/get.spec.ts index 888f2bf1..c49e1841 100644 --- a/services/api/src/domain/usecases/rooms/get.spec.ts +++ b/services/api/src/domain/usecases/rooms/get.spec.ts @@ -1,5 +1,5 @@ import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; import { GetRoomUseCase } from './get'; diff --git a/services/api/src/domain/usecases/rooms/rename.spec.ts b/services/api/src/domain/usecases/rooms/rename.spec.ts index 209783f1..497c67e6 100644 --- a/services/api/src/domain/usecases/rooms/rename.spec.ts +++ b/services/api/src/domain/usecases/rooms/rename.spec.ts @@ -1,5 +1,5 @@ import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestRoomsRepository } from '@fixtures/data/test.rooms.repository'; +import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RenameRoomUseCase } from './rename'; import { mock, MockProxy } from 'jest-mock-extended'; import { RoomFactory } from '@fixtures/messages/room.factory'; diff --git a/services/api/src/domain/usecases/users/rename.spec.ts b/services/api/src/domain/usecases/users/rename.spec.ts index 3fccbc39..8fbaef78 100644 --- a/services/api/src/domain/usecases/users/rename.spec.ts +++ b/services/api/src/domain/usecases/users/rename.spec.ts @@ -2,7 +2,7 @@ import { RenameUserUseCase } from './rename'; import { mock, MockProxy } from 'jest-mock-extended'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; -import { TestUsersRepository } from '@fixtures/data/test.users.repository'; +import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; import { Dispatcher } from '@entities/messages'; describe('RenameUserUseCase', () => { diff --git a/services/api/src/fixtures/data/test.data.module.ts b/services/api/src/fixtures/data/test.data.module.ts index bad40f1b..0a0b09b6 100644 --- a/services/api/src/fixtures/data/test.data.module.ts +++ b/services/api/src/fixtures/data/test.data.module.ts @@ -3,10 +3,10 @@ import { MessagesRepository } from '@entities/messages'; import { RoomsRepository } from '@entities/rooms.repository'; import { UsersRepository } from '@entities/users'; import { Global, Module } from '@nestjs/common'; -import { TestMembershipsRepository } from './test.memberships.repository'; -import { TestMessagesRepository } from './test.messages.repository'; -import { TestRoomsRepository } from './test.rooms.repository'; -import { TestUsersRepository } from './test.users.repository'; +import { TestMembershipsRepository } from '../../data/repositories/test/test.memberships.repository'; +import { TestMessagesRepository } from '../../data/repositories/test/test.messages.repository'; +import { TestRoomsRepository } from '../../data/repositories/test/test.rooms.repository'; +import { TestUsersRepository } from '../../data/repositories/test/test.users.repository'; @Global() @Module({ From 0fbd6bff68de2e69f48c01893fe210628c54d4fa Mon Sep 17 00:00:00 2001 From: John Brunton Date: Mon, 26 Aug 2024 13:49:46 +0100 Subject: [PATCH 2/4] chore: ignore coverage --- services/api/.gitignore | 2 ++ services/api/jest.config.js | 1 + 2 files changed, 3 insertions(+) diff --git a/services/api/.gitignore b/services/api/.gitignore index e330a031..dda14866 100644 --- a/services/api/.gitignore +++ b/services/api/.gitignore @@ -39,3 +39,5 @@ reports/mutation # typedoc /docs + +/coverage \ No newline at end of file diff --git a/services/api/jest.config.js b/services/api/jest.config.js index 6f016386..91bd66b4 100644 --- a/services/api/jest.config.js +++ b/services/api/jest.config.js @@ -19,4 +19,5 @@ module.exports = { '^@entities/(.*)$': ['/src/domain/entities/$1'], '^@usecases/(.*)$': ['/src/domain/usecases/$1'], }, + coverageDirectory: 'coverage', }; From ba443faa526828ea86324c73197e50351fae9e2b Mon Sep 17 00:00:00 2001 From: John Brunton Date: Mon, 26 Aug 2024 15:14:24 +0100 Subject: [PATCH 3/4] fix: eslint boundaries --- services/api/.eslintrc.js | 8 +++++++- services/api/scripts/db/drop.ts | 2 +- services/api/scripts/db/init.ts | 2 +- .../src/data/adapters/{ => dynamodb}/dynamodb.adapter.ts | 2 +- services/api/src/data/adapters/{ => dynamodb}/schema.ts | 0 services/api/src/data/data.module.ts | 2 +- .../dynamodb/dynamodb.memberships.repository.ts | 4 ++-- .../repositories/dynamodb/dynamodb.messages.repository.ts | 4 ++-- .../repositories/dynamodb/dynamodb.rooms.repository.ts | 4 ++-- .../repositories/dynamodb/dynamodb.users.repository.ts | 4 ++-- services/api/src/fixtures/setup-e2e.ts | 2 +- services/api/src/fixtures/teardown-e2e.ts | 2 +- 12 files changed, 21 insertions(+), 15 deletions(-) rename services/api/src/data/adapters/{ => dynamodb}/dynamodb.adapter.ts (98%) rename services/api/src/data/adapters/{ => dynamodb}/schema.ts (100%) diff --git a/services/api/.eslintrc.js b/services/api/.eslintrc.js index 8745eef7..d74a152f 100644 --- a/services/api/.eslintrc.js +++ b/services/api/.eslintrc.js @@ -68,6 +68,10 @@ module.exports = { '@casl/ability', ], }, + { + from: [['data', { adapterType: 'test' }]], + allow: ['@faker-js/faker'], + }, { from: ['config'], allow: ['@aws-sdk/client-dynamodb', '@nestjs/config', 'assert'], @@ -121,7 +125,9 @@ module.exports = { }, { type: 'data', - pattern: 'src/data', + pattern: ['src/data/*/*', 'src/data'], + mode: 'folder', + capture: ['kind', 'adapterType'], }, { type: 'config', diff --git a/services/api/scripts/db/drop.ts b/services/api/scripts/db/drop.ts index fcdc265c..455f25e2 100644 --- a/services/api/scripts/db/drop.ts +++ b/services/api/scripts/db/drop.ts @@ -1,4 +1,4 @@ -import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter'; +import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter'; import { RunnableDataModule, runWithContext } from '../runWithContext'; runWithContext({ diff --git a/services/api/scripts/db/init.ts b/services/api/scripts/db/init.ts index 5034ea4b..0c0d6742 100644 --- a/services/api/scripts/db/init.ts +++ b/services/api/scripts/db/init.ts @@ -1,4 +1,4 @@ -import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter'; +import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter'; import { RunnableDataModule, runWithContext } from '../runWithContext'; runWithContext({ diff --git a/services/api/src/data/adapters/dynamodb.adapter.ts b/services/api/src/data/adapters/dynamodb/dynamodb.adapter.ts similarity index 98% rename from services/api/src/data/adapters/dynamodb.adapter.ts rename to services/api/src/data/adapters/dynamodb/dynamodb.adapter.ts index 3f1670b0..bd675007 100644 --- a/services/api/src/data/adapters/dynamodb.adapter.ts +++ b/services/api/src/data/adapters/dynamodb/dynamodb.adapter.ts @@ -11,7 +11,7 @@ import { DbRoom, DbSchema, DbUser, -} from '@data/adapters/schema'; +} from '@data/adapters/dynamodb/schema'; @Injectable() export class DynamoDBAdapter { diff --git a/services/api/src/data/adapters/schema.ts b/services/api/src/data/adapters/dynamodb/schema.ts similarity index 100% rename from services/api/src/data/adapters/schema.ts rename to services/api/src/data/adapters/dynamodb/schema.ts diff --git a/services/api/src/data/data.module.ts b/services/api/src/data/data.module.ts index d427a3e3..2d6f6743 100644 --- a/services/api/src/data/data.module.ts +++ b/services/api/src/data/data.module.ts @@ -6,7 +6,7 @@ import { DynamoDBMessagesRepository } from './repositories/dynamodb/dynamodb.mes import { RoomsRepository } from '@entities/rooms.repository'; import { UsersRepository } from '@entities/users'; import { DynamoDBUsersRepository } from './repositories/dynamodb/dynamodb.users.repository'; -import { DynamoDBAdapter } from './adapters/dynamodb.adapter'; +import { DynamoDBAdapter } from './adapters/dynamodb/dynamodb.adapter'; import { DynamoDBRoomsRepository } from './repositories/dynamodb/dynamodb.rooms.repository'; import { MembershipsRepository } from '@entities/memberships.repository'; import { DynamoDBMembershipsRepository } from './repositories/dynamodb/dynamodb.memberships.repository'; diff --git a/services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts index ff9ce901..f76f4c8d 100644 --- a/services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.memberships.repository.ts @@ -5,8 +5,8 @@ import { } from '@entities/memberships.repository'; import { Injectable } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; -import { DbMembership } from '../../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter'; +import { DbMembership } from '../../adapters/dynamodb/schema'; @Injectable() export class DynamoDBMembershipsRepository extends MembershipsRepository { diff --git a/services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts index 6ce4df34..c088c041 100644 --- a/services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.messages.repository.ts @@ -2,8 +2,8 @@ import { DraftMessage, SentMessage } from '@entities/messages'; import { MessagesRepository } from '@entities/messages'; import { Injectable } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; -import { DbMessage } from '../../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter'; +import { DbMessage } from '../../adapters/dynamodb/schema'; @Injectable() export class DynamoDBMessagesRepository extends MessagesRepository { diff --git a/services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts index cc0694c0..37fcc0cc 100644 --- a/services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.rooms.repository.ts @@ -7,8 +7,8 @@ import { } from '@entities/rooms.repository'; import { Injectable, NotFoundException } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; -import { DbRoom } from '../../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter'; +import { DbRoom } from '../../adapters/dynamodb/schema'; @Injectable() export class DynamoDBRoomsRepository extends RoomsRepository { diff --git a/services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts b/services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts index e42f2c47..ef501734 100644 --- a/services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts +++ b/services/api/src/data/repositories/dynamodb/dynamodb.users.repository.ts @@ -6,8 +6,8 @@ import { } from '@entities/users'; import { Injectable, NotFoundException } from '@nestjs/common'; import { pick } from 'rambda'; -import { DynamoDBAdapter } from '../../adapters/dynamodb.adapter'; -import { DbUser } from '../../adapters/schema'; +import { DynamoDBAdapter } from '../../adapters/dynamodb/dynamodb.adapter'; +import { DbUser } from '../../adapters/dynamodb/schema'; @Injectable() export class DynamoDBUsersRepository extends UsersRepository { diff --git a/services/api/src/fixtures/setup-e2e.ts b/services/api/src/fixtures/setup-e2e.ts index 63fb2de3..27886051 100644 --- a/services/api/src/fixtures/setup-e2e.ts +++ b/services/api/src/fixtures/setup-e2e.ts @@ -1,5 +1,5 @@ import 'tsconfig-paths/register'; -import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter'; +import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter'; import { DataModule } from '@data/data.module'; import { Test, TestingModule } from '@nestjs/testing'; import { LoggerModule } from '@app/app.logger'; diff --git a/services/api/src/fixtures/teardown-e2e.ts b/services/api/src/fixtures/teardown-e2e.ts index 8ff37cdd..b03709b6 100644 --- a/services/api/src/fixtures/teardown-e2e.ts +++ b/services/api/src/fixtures/teardown-e2e.ts @@ -1,5 +1,5 @@ import 'tsconfig-paths/register'; -import { DynamoDBAdapter } from '@data/adapters/dynamodb.adapter'; +import { DynamoDBAdapter } from '@data/adapters/dynamodb/dynamodb.adapter'; import { DataModule } from '@data/data.module'; import { Test, TestingModule } from '@nestjs/testing'; import { LoggerModule } from '@app/app.logger'; From f59f57156eb21522caf59ee5dcd49c1b1c3b2c48 Mon Sep 17 00:00:00 2001 From: John Brunton Date: Mon, 26 Aug 2024 15:16:29 +0100 Subject: [PATCH 4/4] fix: tests --- services/api/src/app/messages/messages.controller.spec.ts | 4 ++-- .../src/domain/usecases/memberships/approve-request.spec.ts | 2 +- services/api/src/domain/usecases/memberships/invite.spec.ts | 2 +- services/api/src/domain/usecases/memberships/join.spec.ts | 2 +- services/api/src/domain/usecases/memberships/leave.spec.ts | 2 +- services/api/src/domain/usecases/rooms/create.spec.ts | 2 +- services/api/src/domain/usecases/rooms/get.spec.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/api/src/app/messages/messages.controller.spec.ts b/services/api/src/app/messages/messages.controller.spec.ts index 2384f1f7..e7c5c099 100644 --- a/services/api/src/app/messages/messages.controller.spec.ts +++ b/services/api/src/app/messages/messages.controller.spec.ts @@ -11,7 +11,6 @@ import { import { MessageFactory } from '@fixtures/messages/message.factory'; import { UsersRepository } from '@entities/users'; import { MessagesRepository } from '@entities/messages'; -import { TestDataModule } from '@fixtures/data/test.data.module'; import { TestUsersRepository } from '@data/repositories/test/test.users.repository'; import { TestMessagesRepository } from '@data/repositories/test/test.messages.repository'; import { Room } from '@entities/room.entity'; @@ -19,12 +18,13 @@ import { RoomsRepository } from '@entities/rooms.repository'; import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { CreateMessageDto } from './dto/messages'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { MembershipsRepository } from '@entities/memberships.repository'; import { MembershipStatus } from '@entities/membership.entity'; import { MessagesModule } from './messages.module'; import { Auth0Client } from '@app/auth/auth0/auth0.client'; import { MockLoggerModule } from '@fixtures/MockLoggerModule'; +import { TestDataModule } from '@fixtures/data/test.data.module'; jest.mock('@app/auth/auth0/auth0.client'); diff --git a/services/api/src/domain/usecases/memberships/approve-request.spec.ts b/services/api/src/domain/usecases/memberships/approve-request.spec.ts index 2f72f472..5ef72674 100644 --- a/services/api/src/domain/usecases/memberships/approve-request.spec.ts +++ b/services/api/src/domain/usecases/memberships/approve-request.spec.ts @@ -1,6 +1,6 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; diff --git a/services/api/src/domain/usecases/memberships/invite.spec.ts b/services/api/src/domain/usecases/memberships/invite.spec.ts index 71b21b38..261cefa4 100644 --- a/services/api/src/domain/usecases/memberships/invite.spec.ts +++ b/services/api/src/domain/usecases/memberships/invite.spec.ts @@ -1,6 +1,6 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; diff --git a/services/api/src/domain/usecases/memberships/join.spec.ts b/services/api/src/domain/usecases/memberships/join.spec.ts index a5782cc7..382471af 100644 --- a/services/api/src/domain/usecases/memberships/join.spec.ts +++ b/services/api/src/domain/usecases/memberships/join.spec.ts @@ -1,6 +1,6 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; diff --git a/services/api/src/domain/usecases/memberships/leave.spec.ts b/services/api/src/domain/usecases/memberships/leave.spec.ts index 9d9b7e24..9c136dae 100644 --- a/services/api/src/domain/usecases/memberships/leave.spec.ts +++ b/services/api/src/domain/usecases/memberships/leave.spec.ts @@ -1,6 +1,6 @@ import { JoinPolicy } from '@entities/room.entity'; import { TestAuthService } from '@fixtures/auth/test-auth-service'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { RoomFactory } from '@fixtures/messages/room.factory'; import { UserFactory } from '@fixtures/messages/user.factory'; diff --git a/services/api/src/domain/usecases/rooms/create.spec.ts b/services/api/src/domain/usecases/rooms/create.spec.ts index 04ec5885..06508671 100644 --- a/services/api/src/domain/usecases/rooms/create.spec.ts +++ b/services/api/src/domain/usecases/rooms/create.spec.ts @@ -1,4 +1,4 @@ -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { TestRoomsRepository } from '@data/repositories/test/test.rooms.repository'; import { UserFactory } from '@fixtures/messages/user.factory'; import { CreateRoomUseCase } from './create'; diff --git a/services/api/src/domain/usecases/rooms/get.spec.ts b/services/api/src/domain/usecases/rooms/get.spec.ts index c49e1841..46fb8a21 100644 --- a/services/api/src/domain/usecases/rooms/get.spec.ts +++ b/services/api/src/domain/usecases/rooms/get.spec.ts @@ -5,7 +5,7 @@ import { UserFactory } from '@fixtures/messages/user.factory'; import { GetRoomUseCase } from './get'; import { AppLogger } from '@app/app.logger'; import { Role } from '@usecases/auth.service'; -import { TestMembershipsRepository } from '@fixtures/data/test.memberships.repository'; +import { TestMembershipsRepository } from '@data/repositories/test/test.memberships.repository'; import { MembershipStatus } from '@entities/membership.entity'; describe('GetRoomUseCase', () => {