This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

refactor: format code and remove unused imports

+89 -42
+89 -42
src/modules/notifications/tests/infrastructure/DrizzleNotificationRepository.findByRecipientEnriched.integration.test.ts
··· 17 17 import { libraryMemberships } from '../../../cards/infrastructure/repositories/schema/libraryMembership.sql'; 18 18 import { publishedRecords } from '../../../cards/infrastructure/repositories/schema/publishedRecord.sql'; 19 19 import { notifications } from '../../infrastructure/repositories/schema/notification.sql'; 20 - import { Collection, CollectionAccessType } from '../../../cards/domain/Collection'; 20 + import { 21 + Collection, 22 + CollectionAccessType, 23 + } from '../../../cards/domain/Collection'; 21 24 import { CardBuilder } from '../../../cards/tests/utils/builders/CardBuilder'; 22 25 import { URL } from '../../../cards/domain/value-objects/URL'; 23 26 import { UrlMetadata } from '../../../cards/domain/value-objects/UrlMetadata'; 24 27 import { createTestSchema } from '../../../cards/tests/test-utils/createTestSchema'; 25 - import { CardTypeEnum } from '../../../cards/domain/value-objects/CardType'; 26 28 import { Notification } from '../../domain/Notification'; 27 29 import { NotificationType } from '../../domain/value-objects/NotificationType'; 28 - import { NotificationTypeEnum } from '../../domain/value-objects/NotificationType'; 29 30 30 31 describe('DrizzleNotificationRepository - findByRecipientEnriched', () => { 31 32 let container: StartedPostgreSqlContainer; ··· 86 87 it('should return empty result when no notifications exist', async () => { 87 88 const result = await notificationRepository.findByRecipientEnriched( 88 89 recipientId, 89 - { page: 1, limit: 10 } 90 + { page: 1, limit: 10 }, 90 91 ); 91 92 92 93 expect(result.isOk()).toBe(true); ··· 128 129 const notification = Notification.create({ 129 130 recipientUserId: recipientId, 130 131 actorUserId: actorId, 131 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 132 + type: NotificationType.create( 133 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 134 + ).unwrap(), 132 135 metadata: { 133 136 cardId: urlCard.cardId.getStringValue(), 134 137 }, ··· 141 144 142 145 const result = await notificationRepository.findByRecipientEnriched( 143 146 recipientId, 144 - { page: 1, limit: 10 } 147 + { page: 1, limit: 10 }, 145 148 ); 146 149 147 150 expect(result.isOk()).toBe(true); ··· 152 155 expect(data.unreadCount).toBe(1); 153 156 154 157 const enrichedNotification = data.notifications[0]!; 155 - 158 + 156 159 // Check notification data 157 - expect(enrichedNotification.id).toBe(notification.notificationId.getStringValue()); 158 - expect(enrichedNotification.type).toBe(NotificationTypeEnum.USER_ADDED_YOUR_CARD); 160 + expect(enrichedNotification.id).toBe( 161 + notification.notificationId.getStringValue(), 162 + ); 163 + expect(enrichedNotification.type).toBe( 164 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 165 + ); 159 166 expect(enrichedNotification.read).toBe(false); 160 167 expect(enrichedNotification.actorUserId).toBe(actorId.value); 161 168 expect(enrichedNotification.cardAuthorId).toBe(cardAuthorId.value); ··· 164 171 expect(enrichedNotification.cardId).toBe(urlCard.cardId.getStringValue()); 165 172 expect(enrichedNotification.cardUrl).toBe(url.value); 166 173 expect(enrichedNotification.cardTitle).toBe('Test Article'); 167 - expect(enrichedNotification.cardDescription).toBe('A test article description'); 174 + expect(enrichedNotification.cardDescription).toBe( 175 + 'A test article description', 176 + ); 168 177 expect(enrichedNotification.cardAuthor).toBe('John Doe'); 169 - expect(enrichedNotification.cardPublishedDate).toEqual(new Date('2024-01-15')); 178 + expect(enrichedNotification.cardPublishedDate).toEqual( 179 + new Date('2024-01-15'), 180 + ); 170 181 expect(enrichedNotification.cardSiteName).toBe('Example Site'); 171 - expect(enrichedNotification.cardImageUrl).toBe('https://example.com/image.jpg'); 182 + expect(enrichedNotification.cardImageUrl).toBe( 183 + 'https://example.com/image.jpg', 184 + ); 172 185 expect(enrichedNotification.cardType).toBe('article'); 173 186 expect(enrichedNotification.cardDoi).toBe('10.1000/test'); 174 187 expect(enrichedNotification.cardIsbn).toBe('978-0123456789'); ··· 200 213 const notification = Notification.create({ 201 214 recipientUserId: recipientId, 202 215 actorUserId: actorId, 203 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 216 + type: NotificationType.create( 217 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 218 + ).unwrap(), 204 219 metadata: { 205 220 cardId: urlCard.cardId.getStringValue(), 206 221 }, ··· 213 228 214 229 const result = await notificationRepository.findByRecipientEnriched( 215 230 recipientId, 216 - { page: 1, limit: 10 } 231 + { page: 1, limit: 10 }, 217 232 ); 218 233 219 234 expect(result.isOk()).toBe(true); ··· 222 237 223 238 const enrichedNotification = data.notifications[0]!; 224 239 expect(enrichedNotification.cardNote).toBeDefined(); 225 - expect(enrichedNotification.cardNote?.id).toBe(noteCard.cardId.getStringValue()); 226 - expect(enrichedNotification.cardNote?.text).toBe('This is my detailed analysis of the article.'); 240 + expect(enrichedNotification.cardNote?.id).toBe( 241 + noteCard.cardId.getStringValue(), 242 + ); 243 + expect(enrichedNotification.cardNote?.text).toBe( 244 + 'This is my detailed analysis of the article.', 245 + ); 227 246 }); 228 247 229 248 it('should include collection data when card is in collections', async () => { 230 249 // Create URL card 231 - const url = URL.create('https://example.com/article-in-collections').unwrap(); 250 + const url = URL.create( 251 + 'https://example.com/article-in-collections', 252 + ).unwrap(); 232 253 const urlCard = new CardBuilder() 233 254 .withCuratorId(cardAuthorId.value) 234 255 .withUrlCard(url) ··· 273 294 const notification = Notification.create({ 274 295 recipientUserId: recipientId, 275 296 actorUserId: actorId, 276 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 297 + type: NotificationType.create( 298 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 299 + ).unwrap(), 277 300 metadata: { 278 301 cardId: urlCard.cardId.getStringValue(), 279 302 collectionIds: [ ··· 290 313 291 314 const result = await notificationRepository.findByRecipientEnriched( 292 315 recipientId, 293 - { page: 1, limit: 10 } 316 + { page: 1, limit: 10 }, 294 317 ); 295 318 296 319 expect(result.isOk()).toBe(true); ··· 301 324 expect(enrichedNotification.collections).toHaveLength(2); 302 325 303 326 // Check collection data 304 - const collectionNames = enrichedNotification.collections.map(c => c.name).sort(); 327 + const collectionNames = enrichedNotification.collections 328 + .map((c) => c.name) 329 + .sort(); 305 330 expect(collectionNames).toEqual(['My Favorites', 'Reading List']); 306 331 307 - const readingList = enrichedNotification.collections.find(c => c.name === 'Reading List'); 332 + const readingList = enrichedNotification.collections.find( 333 + (c) => c.name === 'Reading List', 334 + ); 308 335 expect(readingList?.id).toBe(collection1.collectionId.getStringValue()); 309 336 expect(readingList?.description).toBe('Articles to read'); 310 337 expect(readingList?.authorId).toBe(collectionAuthorId.value); ··· 312 339 expect(readingList?.createdAt).toEqual(new Date('2024-01-10')); 313 340 expect(readingList?.updatedAt).toEqual(new Date('2024-01-15')); 314 341 315 - const myFavorites = enrichedNotification.collections.find(c => c.name === 'My Favorites'); 342 + const myFavorites = enrichedNotification.collections.find( 343 + (c) => c.name === 'My Favorites', 344 + ); 316 345 expect(myFavorites?.id).toBe(collection2.collectionId.getStringValue()); 317 346 expect(myFavorites?.description).toBeUndefined(); 318 347 expect(myFavorites?.authorId).toBe(cardAuthorId.value); ··· 345 374 const notification = Notification.create({ 346 375 recipientUserId: recipientId, 347 376 actorUserId: actorId, 348 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 377 + type: NotificationType.create( 378 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 379 + ).unwrap(), 349 380 metadata: { 350 381 cardId: urlCard1.cardId.getStringValue(), 351 382 }, ··· 358 389 359 390 const result = await notificationRepository.findByRecipientEnriched( 360 391 recipientId, 361 - { page: 1, limit: 10 } 392 + { page: 1, limit: 10 }, 362 393 ); 363 394 364 395 expect(result.isOk()).toBe(true); ··· 385 416 const notification = Notification.create({ 386 417 recipientUserId: recipientId, 387 418 actorUserId: actorId, 388 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 419 + type: NotificationType.create( 420 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 421 + ).unwrap(), 389 422 metadata: { 390 423 cardId: urlCard.cardId.getStringValue(), 391 424 }, ··· 401 434 // Test first page 402 435 const page1Result = await notificationRepository.findByRecipientEnriched( 403 436 recipientId, 404 - { page: 1, limit: 2 } 437 + { page: 1, limit: 2 }, 405 438 ); 406 439 407 440 expect(page1Result.isOk()).toBe(true); ··· 414 447 // Test second page 415 448 const page2Result = await notificationRepository.findByRecipientEnriched( 416 449 recipientId, 417 - { page: 2, limit: 2 } 450 + { page: 2, limit: 2 }, 418 451 ); 419 452 420 453 expect(page2Result.isOk()).toBe(true); ··· 426 459 // Test last page 427 460 const page3Result = await notificationRepository.findByRecipientEnriched( 428 461 recipientId, 429 - { page: 3, limit: 2 } 462 + { page: 3, limit: 2 }, 430 463 ); 431 464 432 465 expect(page3Result.isOk()).toBe(true); ··· 450 483 const notification = Notification.create({ 451 484 recipientUserId: recipientId, 452 485 actorUserId: actorId, 453 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 486 + type: NotificationType.create( 487 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 488 + ).unwrap(), 454 489 metadata: { 455 490 cardId: urlCard.cardId.getStringValue(), 456 491 }, ··· 465 500 // Test all notifications 466 501 const allResult = await notificationRepository.findByRecipientEnriched( 467 502 recipientId, 468 - { page: 1, limit: 10 } 503 + { page: 1, limit: 10 }, 469 504 ); 470 505 471 506 expect(allResult.isOk()).toBe(true); ··· 477 512 // Test unread only 478 513 const unreadResult = await notificationRepository.findByRecipientEnriched( 479 514 recipientId, 480 - { page: 1, limit: 10, unreadOnly: true } 515 + { page: 1, limit: 10, unreadOnly: true }, 481 516 ); 482 517 483 518 expect(unreadResult.isOk()).toBe(true); ··· 487 522 expect(unreadData.unreadCount).toBe(2); 488 523 489 524 // Verify all returned notifications are unread 490 - unreadData.notifications.forEach(notification => { 525 + unreadData.notifications.forEach((notification) => { 491 526 expect(notification.read).toBe(false); 492 527 }); 493 528 }); ··· 497 532 const notification = Notification.create({ 498 533 recipientUserId: recipientId, 499 534 actorUserId: actorId, 500 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 535 + type: NotificationType.create( 536 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 537 + ).unwrap(), 501 538 metadata: { 502 539 cardId: new UniqueEntityID().toString(), // Non-existent card 503 540 }, ··· 510 547 511 548 const result = await notificationRepository.findByRecipientEnriched( 512 549 recipientId, 513 - { page: 1, limit: 10 } 550 + { page: 1, limit: 10 }, 514 551 ); 515 552 516 553 expect(result.isOk()).toBe(true); ··· 542 579 const notification = Notification.create({ 543 580 recipientUserId: recipientId, 544 581 actorUserId: actorId, 545 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 582 + type: NotificationType.create( 583 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 584 + ).unwrap(), 546 585 metadata: { 547 586 cardId: urlCard.cardId.getStringValue(), 548 587 }, ··· 556 595 557 596 const result = await notificationRepository.findByRecipientEnriched( 558 597 recipientId, 559 - { page: 1, limit: 10 } 598 + { page: 1, limit: 10 }, 560 599 ); 561 600 562 601 expect(result.isOk()).toBe(true); ··· 564 603 expect(data.notifications).toHaveLength(4); 565 604 566 605 // Should be ordered by creation date descending (newest first) 567 - const createdDates = data.notifications.map(n => n.createdAt.getTime()); 606 + const createdDates = data.notifications.map((n) => n.createdAt.getTime()); 568 607 expect(createdDates).toEqual([ 569 608 new Date('2024-01-20').getTime(), 570 609 new Date('2024-01-15').getTime(), ··· 574 613 }); 575 614 576 615 it('should only return notifications for the specified recipient', async () => { 577 - const otherRecipientId = CuratorId.create('did:plc:otherrecipient').unwrap(); 616 + const otherRecipientId = CuratorId.create( 617 + 'did:plc:otherrecipient', 618 + ).unwrap(); 578 619 579 620 // Create notifications for different recipients 580 621 for (const recipient of [recipientId, otherRecipientId]) { 581 - const url = URL.create(`https://example.com/article-${recipient.value}`).unwrap(); 622 + const url = URL.create( 623 + `https://example.com/article-${recipient.value}`, 624 + ).unwrap(); 582 625 const urlCard = new CardBuilder() 583 626 .withCuratorId(cardAuthorId.value) 584 627 .withUrlCard(url) ··· 589 632 const notification = Notification.create({ 590 633 recipientUserId: recipient, 591 634 actorUserId: actorId, 592 - type: NotificationType.create(NotificationTypeEnum.USER_ADDED_YOUR_CARD).unwrap(), 635 + type: NotificationType.create( 636 + NotificationTypeEnum.USER_ADDED_YOUR_CARD, 637 + ).unwrap(), 593 638 metadata: { 594 639 cardId: urlCard.cardId.getStringValue(), 595 640 }, ··· 604 649 // Query for specific recipient 605 650 const result = await notificationRepository.findByRecipientEnriched( 606 651 recipientId, 607 - { page: 1, limit: 10 } 652 + { page: 1, limit: 10 }, 608 653 ); 609 654 610 655 expect(result.isOk()).toBe(true); ··· 614 659 expect(data.unreadCount).toBe(1); 615 660 616 661 // Verify it's the correct notification 617 - expect(data.notifications[0]?.cardUrl).toBe(`https://example.com/article-${recipientId.value}`); 662 + expect(data.notifications[0]?.cardUrl).toBe( 663 + `https://example.com/article-${recipientId.value}`, 664 + ); 618 665 }); 619 666 }); 620 667 });