-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bruno-valero/dev
domain: notification domain ok, ci: unit tests ok
- Loading branch information
Showing
11 changed files
with
403 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Run Unit Tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
run-unit-tests: | ||
name: Run Unit Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: "npm" | ||
|
||
- run: npm ci | ||
|
||
- run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/domain/core/deliveries-and-orders/enterprise/events/order-courier-canceled-event.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import UniqueEntityId from '@/core/entities/unique-entity-id' | ||
import { OnOrderCourierCanceled } from '@/domain/generic/notification/application/subscribers/on-order-courier-canceled' | ||
import { | ||
SendNotificationUseCaseRequest, | ||
SendNotificationUseCaseResponse, | ||
} from '@/domain/generic/notification/application/use-cases/send-notification' | ||
import { makeAdm } from 'test/factories/entities/makeAdm' | ||
import { makeAddress } from 'test/factories/entities/value-objects/makeAddress' | ||
import { makeSendNotificationUseCase } from 'test/factories/use-cases/notification/make-send-notification-use-case' | ||
import { makeCreateOrderUseCase } from 'test/factories/use-cases/order/make-create-order-use-case' | ||
import { makeMarkOrderAsAwaitingForPickupUseCase } from 'test/factories/use-cases/order/make-mark-order-as-awaiting-for-pickup-use-case' | ||
import { waitFor } from 'test/lib/await-for' | ||
import { MockInstance } from 'vitest' | ||
|
||
let createOrder = makeCreateOrderUseCase() | ||
let awaitingPickup = makeMarkOrderAsAwaitingForPickupUseCase({ | ||
admsRepositoryAlt: createOrder.dependencies.admsRepository, | ||
ordersRepositoryAlt: createOrder.dependencies.ordersRepository, | ||
}) | ||
let createNotification = makeSendNotificationUseCase() | ||
let sut: OnOrderCourierCanceled // eslint-disable-line | ||
|
||
let sendNotificationSpy: MockInstance< | ||
[SendNotificationUseCaseRequest], | ||
Promise<SendNotificationUseCaseResponse> | ||
> | ||
|
||
describe('on courier cancel order', () => { | ||
beforeEach(() => { | ||
createOrder = makeCreateOrderUseCase() | ||
awaitingPickup = makeMarkOrderAsAwaitingForPickupUseCase({ | ||
admsRepositoryAlt: createOrder.dependencies.admsRepository, | ||
ordersRepositoryAlt: createOrder.dependencies.ordersRepository, | ||
}) | ||
createNotification = makeSendNotificationUseCase() | ||
|
||
sut = new OnOrderCourierCanceled( | ||
createOrder.dependencies.ordersRepository, | ||
createNotification.useCase, | ||
) | ||
sendNotificationSpy = vi.spyOn(createNotification.useCase, 'execute') | ||
}) | ||
|
||
afterAll(() => {}) | ||
|
||
it('shoud be able to send a notification on courier cancel order', async () => { | ||
await createOrder.dependencies.admsRepository.create(makeAdm()) | ||
|
||
const adm = (await createOrder.dependencies.admsRepository.findMany())[0] | ||
|
||
await createOrder.useCase.execute({ | ||
requestResponsibleId: adm.id.value, | ||
creationProps: { | ||
address: makeAddress(), | ||
courierId: new UniqueEntityId('123'), | ||
recipientId: new UniqueEntityId('1188'), | ||
}, | ||
}) | ||
|
||
const order = ( | ||
await createOrder.dependencies.ordersRepository.findMany() | ||
)[0] | ||
|
||
order.actions.courier.courierReject(adm.id) | ||
|
||
await createOrder.dependencies.ordersRepository.update(order) | ||
|
||
await awaitingPickup.useCase.execute({ | ||
orderId: order.id.value, | ||
requestResponsibleId: adm.id.value, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(sendNotificationSpy).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
78 changes: 78 additions & 0 deletions
78
...domain/core/deliveries-and-orders/enterprise/events/order-courier-collected-event.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import UniqueEntityId from '@/core/entities/unique-entity-id' | ||
import { OnOrderCourierCollected } from '@/domain/generic/notification/application/subscribers/on-order-courier-collected' | ||
import { | ||
SendNotificationUseCaseRequest, | ||
SendNotificationUseCaseResponse, | ||
} from '@/domain/generic/notification/application/use-cases/send-notification' | ||
import { makeAdm } from 'test/factories/entities/makeAdm' | ||
import { makeAddress } from 'test/factories/entities/value-objects/makeAddress' | ||
import { makeSendNotificationUseCase } from 'test/factories/use-cases/notification/make-send-notification-use-case' | ||
import { makeCreateOrderUseCase } from 'test/factories/use-cases/order/make-create-order-use-case' | ||
import { makeMarkOrderAsAwaitingForPickupUseCase } from 'test/factories/use-cases/order/make-mark-order-as-awaiting-for-pickup-use-case' | ||
import { waitFor } from 'test/lib/await-for' | ||
import { MockInstance } from 'vitest' | ||
|
||
let createOrder = makeCreateOrderUseCase() | ||
let awaitingPickup = makeMarkOrderAsAwaitingForPickupUseCase({ | ||
admsRepositoryAlt: createOrder.dependencies.admsRepository, | ||
ordersRepositoryAlt: createOrder.dependencies.ordersRepository, | ||
}) | ||
let createNotification = makeSendNotificationUseCase() | ||
let sut: OnOrderCourierCollected // eslint-disable-line | ||
|
||
let sendNotificationSpy: MockInstance< | ||
[SendNotificationUseCaseRequest], | ||
Promise<SendNotificationUseCaseResponse> | ||
> | ||
|
||
describe('on courier collect order', () => { | ||
beforeEach(() => { | ||
createOrder = makeCreateOrderUseCase() | ||
awaitingPickup = makeMarkOrderAsAwaitingForPickupUseCase({ | ||
admsRepositoryAlt: createOrder.dependencies.admsRepository, | ||
ordersRepositoryAlt: createOrder.dependencies.ordersRepository, | ||
}) | ||
createNotification = makeSendNotificationUseCase() | ||
|
||
sut = new OnOrderCourierCollected( | ||
createOrder.dependencies.ordersRepository, | ||
createNotification.useCase, | ||
) | ||
sendNotificationSpy = vi.spyOn(createNotification.useCase, 'execute') | ||
}) | ||
|
||
afterAll(() => {}) | ||
|
||
it('shoud be able to send a notification on courier collect order', async () => { | ||
await createOrder.dependencies.admsRepository.create(makeAdm()) | ||
|
||
const adm = (await createOrder.dependencies.admsRepository.findMany())[0] | ||
|
||
await createOrder.useCase.execute({ | ||
requestResponsibleId: adm.id.value, | ||
creationProps: { | ||
address: makeAddress(), | ||
courierId: new UniqueEntityId('123'), | ||
recipientId: new UniqueEntityId('1188'), | ||
}, | ||
}) | ||
|
||
const order = ( | ||
await createOrder.dependencies.ordersRepository.findMany() | ||
)[0] | ||
|
||
order.actions.adm.admSetAwaitingPickup(adm.id) | ||
order.actions.adm.admCollected(adm.id) | ||
|
||
await createOrder.dependencies.ordersRepository.update(order) | ||
|
||
await awaitingPickup.useCase.execute({ | ||
orderId: order.id.value, | ||
requestResponsibleId: adm.id.value, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(sendNotificationSpy).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/domain/core/deliveries-and-orders/enterprise/events/order-courier-deliver-event.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import UniqueEntityId from '@/core/entities/unique-entity-id' | ||
import { OnOrderCourierDeliver } from '@/domain/generic/notification/application/subscribers/on-order-courier-deliver' | ||
import { | ||
SendNotificationUseCaseRequest, | ||
SendNotificationUseCaseResponse, | ||
} from '@/domain/generic/notification/application/use-cases/send-notification' | ||
import { makeAdm } from 'test/factories/entities/makeAdm' | ||
import { makeAddress } from 'test/factories/entities/value-objects/makeAddress' | ||
import { makeSendNotificationUseCase } from 'test/factories/use-cases/notification/make-send-notification-use-case' | ||
import { makeCreateOrderUseCase } from 'test/factories/use-cases/order/make-create-order-use-case' | ||
import { makeMarkOrderAsAwaitingForPickupUseCase } from 'test/factories/use-cases/order/make-mark-order-as-awaiting-for-pickup-use-case' | ||
import { waitFor } from 'test/lib/await-for' | ||
import { MockInstance } from 'vitest' | ||
|
||
let createOrder = makeCreateOrderUseCase() | ||
let awaitingPickup = makeMarkOrderAsAwaitingForPickupUseCase({ | ||
admsRepositoryAlt: createOrder.dependencies.admsRepository, | ||
ordersRepositoryAlt: createOrder.dependencies.ordersRepository, | ||
}) | ||
let createNotification = makeSendNotificationUseCase() | ||
let sut: OnOrderCourierDeliver // eslint-disable-line | ||
|
||
let sendNotificationSpy: MockInstance< | ||
[SendNotificationUseCaseRequest], | ||
Promise<SendNotificationUseCaseResponse> | ||
> | ||
|
||
describe('on courier collect order', () => { | ||
beforeEach(() => { | ||
createOrder = makeCreateOrderUseCase() | ||
awaitingPickup = makeMarkOrderAsAwaitingForPickupUseCase({ | ||
admsRepositoryAlt: createOrder.dependencies.admsRepository, | ||
ordersRepositoryAlt: createOrder.dependencies.ordersRepository, | ||
}) | ||
createNotification = makeSendNotificationUseCase() | ||
|
||
sut = new OnOrderCourierDeliver( | ||
createOrder.dependencies.ordersRepository, | ||
createNotification.useCase, | ||
) | ||
sendNotificationSpy = vi.spyOn(createNotification.useCase, 'execute') | ||
}) | ||
|
||
afterAll(() => {}) | ||
|
||
it('shoud be able to send a notification on courier collect order', async () => { | ||
await createOrder.dependencies.admsRepository.create(makeAdm()) | ||
|
||
const adm = (await createOrder.dependencies.admsRepository.findMany())[0] | ||
|
||
await createOrder.useCase.execute({ | ||
requestResponsibleId: adm.id.value, | ||
creationProps: { | ||
address: makeAddress(), | ||
courierId: new UniqueEntityId('123'), | ||
recipientId: new UniqueEntityId('1188'), | ||
}, | ||
}) | ||
|
||
const order = ( | ||
await createOrder.dependencies.ordersRepository.findMany() | ||
)[0] | ||
|
||
order.actions.adm.admSetAwaitingPickup(adm.id) | ||
order.actions.adm.admCollected(adm.id) | ||
order.actions.courier.courierDeliver(new UniqueEntityId('123')) | ||
|
||
await createOrder.dependencies.ordersRepository.update(order) | ||
|
||
await awaitingPickup.useCase.execute({ | ||
orderId: order.id.value, | ||
requestResponsibleId: adm.id.value, | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(sendNotificationSpy).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.