src
modules
cards
domain
infrastructure
tests
application
infrastructure
utils
···
8
8
findById(id: CollectionId): Promise<Result<Collection | null>>;
9
9
findByCuratorId(curatorId: CuratorId): Promise<Result<Collection[]>>;
10
10
findByCardId(cardId: CardId): Promise<Result<Collection[]>>;
11
11
-
findByAuthorIdContainingCard(authorId: CuratorId, cardId: CardId): Promise<Result<Collection[]>>;
11
11
+
findByCuratorIdContainingCard(
12
12
+
authorId: CuratorId,
13
13
+
cardId: CardId,
14
14
+
): Promise<Result<Collection[]>>;
12
15
save(collection: Collection): Promise<Result<void>>;
13
16
delete(collectionId: CollectionId): Promise<Result<void>>;
14
17
}
···
295
295
}
296
296
}
297
297
298
298
-
async findByAuthorIdContainingCard(authorId: CuratorId, cardId: CardId): Promise<Result<Collection[]>> {
298
298
+
async findByCuratorIdContainingCard(
299
299
+
authorId: CuratorId,
300
300
+
cardId: CardId,
301
301
+
): Promise<Result<Collection[]>> {
299
302
try {
300
303
const authorIdString = authorId.value;
301
304
const cardIdString = cardId.getStringValue();
···
318
321
.where(
319
322
and(
320
323
eq(collections.authorId, authorIdString),
321
321
-
eq(collectionCards.cardId, cardIdString)
322
322
-
)
324
324
+
eq(collectionCards.cardId, cardIdString),
325
325
+
),
323
326
);
324
327
325
328
const domainCollections: Collection[] = [];
···
11
11
import { CardContent } from '../../domain/value-objects/CardContent';
12
12
import { UrlMetadata } from '../../domain/value-objects/UrlMetadata';
13
13
import { URL } from '../../domain/value-objects/URL';
14
14
-
import {
15
15
-
CardSortField,
16
16
-
SortOrder,
17
17
-
CollectionCardQueryResultDTO,
18
18
-
} from '../../domain/ICardQueryRepository';
14
14
+
import { CardSortField, SortOrder } from '../../domain/ICardQueryRepository';
19
15
import { UniqueEntityID } from '../../../../shared/domain/UniqueEntityID';
16
16
+
import { ICollectionRepository } from '../../domain/ICollectionRepository';
20
17
21
18
describe('GetCollectionPageUseCase', () => {
22
19
let useCase: GetCollectionPageUseCase;
···
722
719
723
720
it('should handle repository errors gracefully', async () => {
724
721
// Create a mock collection repository that throws an error
725
725
-
const errorCollectionRepo = {
722
722
+
const errorCollectionRepo: ICollectionRepository = {
726
723
findById: jest
727
724
.fn()
728
725
.mockRejectedValue(new Error('Database connection failed')),
···
730
727
delete: jest.fn(),
731
728
findByCuratorId: jest.fn(),
732
729
findByCardId: jest.fn(),
730
730
+
findByCuratorIdContainingCard: jest.fn(),
733
731
};
734
732
735
733
const errorUseCase = new GetCollectionPageUseCase(
···
550
550
await collectionRepository.save(collection3);
551
551
552
552
// Find collections by the original curator containing this card
553
553
-
const foundCollectionsResult = await collectionRepository.findByAuthorIdContainingCard(
554
554
-
curatorId,
555
555
-
card.cardId,
556
556
-
);
553
553
+
const foundCollectionsResult =
554
554
+
await collectionRepository.findByCuratorIdContainingCard(
555
555
+
curatorId,
556
556
+
card.cardId,
557
557
+
);
557
558
expect(foundCollectionsResult.isOk()).toBe(true);
558
559
559
560
const foundCollections = foundCollectionsResult.unwrap();
···
71
71
}
72
72
}
73
73
74
74
-
async findByAuthorIdContainingCard(authorId: CuratorId, cardId: CardId): Promise<Result<Collection[]>> {
74
74
+
async findByCuratorIdContainingCard(
75
75
+
authorId: CuratorId,
76
76
+
cardId: CardId,
77
77
+
): Promise<Result<Collection[]>> {
75
78
try {
76
79
const collections = Array.from(this.collections.values()).filter(
77
80
(collection) =>