Skip to content

Commit 252e08c

Browse files
committed
fix: naming of delete notification
1 parent 3c12fbe commit 252e08c

File tree

8 files changed

+25
-34
lines changed

8 files changed

+25
-34
lines changed

docs/useCases.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The different use cases currently available in the package are classified below,
8787
- [Send Feedback to Object Contacts](#send-feedback-to-object-contacts)
8888
- [Notifications](#Notifications)
8989
- [Get All Notifications by User](#get-all-notifications-by-user)
90-
- [Delete Notification by User](#delete-notification-by-user)
90+
- [Delete Notification](#delete-notification)
9191

9292
## Collections
9393

@@ -2017,24 +2017,24 @@ getAllNotificationsByUser.execute().then((notifications: Notification[]) => {
20172017

20182018
_See [use case](../src/notifications/domain/useCases/GetAllNotificationsByUser.ts) implementation_.
20192019

2020-
#### Delete Notification by User
2020+
#### Delete Notification
20212021

20222022
Deletes a specific notification for the current authenticated user by its ID.
20232023

20242024
##### Example call:
20252025

20262026
```typescript
2027-
import { deleteNotificationByUser } from '@iqss/dataverse-client-javascript'
2027+
import { deleteNotification } from '@iqss/dataverse-client-javascript'
20282028

20292029
/* ... */
20302030

20312031
const notificationId = 123
20322032

2033-
deleteNotificationByUser.execute(notificationId: number).then(() => {
2033+
deleteNotification.execute(notificationId: number).then(() => {
20342034
/* ... */
20352035
})
20362036

20372037
/* ... */
20382038
```
20392039

2040-
_See [use case](../src/notifications/domain/useCases/DeleteNotificationByUser.ts) implementation_.
2040+
_See [use case](../src/notifications/domain/useCases/DeleteNotification.ts) implementation_.

src/notifications/domain/repositories/INotificationsRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { Notification } from '../models/Notification'
22

33
export interface INotificationsRepository {
44
getAllNotificationsByUser(): Promise<Notification[]>
5-
deleteNotificationByUser(notificationId: number): Promise<void>
5+
deleteNotification(notificationId: number): Promise<void>
66
}

src/notifications/domain/useCases/DeleteNotificationByUser.ts renamed to src/notifications/domain/useCases/DeleteNotification.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { INotificationsRepository } from '../repositories/INotificationsReposito
77
* @param notificationId - The ID of the notification to delete.
88
* @returns {Promise<void>} - A promise that resolves when the notification is deleted.
99
*/
10-
export class DeleteNotificationByUser implements UseCase<void> {
10+
export class DeleteNotification implements UseCase<void> {
1111
constructor(private readonly notificationsRepository: INotificationsRepository) {}
1212

1313
async execute(notificationId: number): Promise<void> {
14-
return this.notificationsRepository.deleteNotificationByUser(notificationId)
14+
return this.notificationsRepository.deleteNotification(notificationId)
1515
}
1616
}

src/notifications/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { NotificationsRepository } from './infra/repositories/NotificationsRepository'
22
import { GetAllNotificationsByUser } from './domain/useCases/GetAllNotificationsByUser'
3-
import { DeleteNotificationByUser } from './domain/useCases/DeleteNotificationByUser'
3+
import { DeleteNotification } from './domain/useCases/DeleteNotification'
44

55
const notificationsRepository = new NotificationsRepository()
66

77
const getAllNotificationsByUser = new GetAllNotificationsByUser(notificationsRepository)
8-
const deleteNotificationByUser = new DeleteNotificationByUser(notificationsRepository)
8+
const deleteNotification = new DeleteNotification(notificationsRepository)
99

10-
export { getAllNotificationsByUser, deleteNotificationByUser }
10+
export { getAllNotificationsByUser, deleteNotification }
1111

1212
export { Notification } from './domain/models/Notification'

src/notifications/infra/repositories/NotificationsRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class NotificationsRepository extends ApiRepository implements INotificat
1313
})
1414
}
1515

16-
public async deleteNotificationByUser(notificationId: number): Promise<void> {
16+
public async deleteNotification(notificationId: number): Promise<void> {
1717
return this.doDelete(
1818
this.buildApiEndpoint(this.notificationsResourceName, notificationId.toString())
1919
)

test/functional/notifications/DeleteNotificationByUser.test.ts renamed to test/functional/notifications/DeleteNotification.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
ApiConfig,
3-
deleteNotificationByUser,
4-
getAllNotificationsByUser,
5-
WriteError
6-
} from '../../../src'
1+
import { ApiConfig, deleteNotification, getAllNotificationsByUser, WriteError } from '../../../src'
72
import { TestConstants } from '../../testHelpers/TestConstants'
83
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
94

@@ -20,13 +15,13 @@ describe('execute', () => {
2015
const notifications = await getAllNotificationsByUser.execute()
2116
const notificationId = notifications[notifications.length - 1].id
2217

23-
await deleteNotificationByUser.execute(notificationId)
18+
await deleteNotification.execute(notificationId)
2419

2520
const notificationsAfterDelete = await getAllNotificationsByUser.execute()
2621
expect(notificationsAfterDelete.length).toBe(notifications.length - 1)
2722
})
2823

2924
test('should throw an error when the notification id does not exist', async () => {
30-
await expect(deleteNotificationByUser.execute(123)).rejects.toThrow(WriteError)
25+
await expect(deleteNotification.execute(123)).rejects.toThrow(WriteError)
3126
})
3227
})

test/integration/notifications/NotificationsRepository.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('NotificationsRepository', () => {
5555

5656
const notificationToDelete = notifications[0]
5757

58-
await sut.deleteNotificationByUser(notificationToDelete.id)
58+
await sut.deleteNotification(notificationToDelete.id)
5959

6060
const notificationsAfterDelete: Notification[] = await sut.getAllNotificationsByUser()
6161
const deletedNotification = notificationsAfterDelete.find(
@@ -65,14 +65,12 @@ describe('NotificationsRepository', () => {
6565
})
6666

6767
test('should throw error when trying to delete notification with wrong ID', async () => {
68-
const nonExistentMetadataBlockName = 99999
68+
const nonExistentNotificationId = 99999
6969

7070
const expectedError = new WriteError(
71-
`[404] Notification ${nonExistentMetadataBlockName} not found.`
71+
`[404] Notification ${nonExistentNotificationId} not found.`
7272
)
7373

74-
await expect(sut.deleteNotificationByUser(nonExistentMetadataBlockName)).rejects.toThrow(
75-
expectedError
76-
)
74+
await expect(sut.deleteNotification(nonExistentNotificationId)).rejects.toThrow(expectedError)
7775
})
7876
})

test/unit/notifications/DeleteNotificationByUser.test.ts renamed to test/unit/notifications/DeleteNotification.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DeleteNotificationByUser } from '../../../src/notifications/domain/useCases/DeleteNotificationByUser'
1+
import { DeleteNotification } from '../../../src/notifications/domain/useCases/DeleteNotification'
22
import { INotificationsRepository } from '../../../src/notifications/domain/repositories/INotificationsRepository'
33
import { Notification } from '../../../src/notifications/domain/models/Notification'
44

@@ -23,23 +23,21 @@ describe('execute', () => {
2323
test('should delete notification from repository', async () => {
2424
const notificationsRepositoryStub: INotificationsRepository = {} as INotificationsRepository
2525
notificationsRepositoryStub.getAllNotificationsByUser = jest.fn().mockResolvedValue([])
26-
notificationsRepositoryStub.deleteNotificationByUser = jest
27-
.fn()
28-
.mockResolvedValue(mockNotifications)
29-
const sut = new DeleteNotificationByUser(notificationsRepositoryStub)
26+
notificationsRepositoryStub.deleteNotification = jest.fn().mockResolvedValue(mockNotifications)
27+
const sut = new DeleteNotification(notificationsRepositoryStub)
3028

3129
await sut.execute(123)
3230

33-
expect(notificationsRepositoryStub.deleteNotificationByUser).toHaveBeenCalledWith(123)
31+
expect(notificationsRepositoryStub.deleteNotification).toHaveBeenCalledWith(123)
3432
})
3533

3634
test('should throw error when repository throws error', async () => {
3735
const notificationsRepositoryStub: INotificationsRepository = {} as INotificationsRepository
3836
notificationsRepositoryStub.getAllNotificationsByUser = jest.fn().mockResolvedValue([])
39-
notificationsRepositoryStub.deleteNotificationByUser = jest
37+
notificationsRepositoryStub.deleteNotification = jest
4038
.fn()
4139
.mockRejectedValue(new Error('Repository error'))
42-
const sut = new DeleteNotificationByUser(notificationsRepositoryStub)
40+
const sut = new DeleteNotification(notificationsRepositoryStub)
4341

4442
await expect(sut.execute(123)).rejects.toThrow('Repository error')
4543
})

0 commit comments

Comments
 (0)