-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* get orders * unit test for order service * remove failing test * update create order service * user order status as a model not string * on create order, create order notes * add quantity available props to menu * create the delete category api * write init test for order service * fix failing test --------- Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-MacBook-Air.local>
- Loading branch information
1 parent
6161bf7
commit 91dc8b3
Showing
24 changed files
with
241 additions
and
78 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
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,25 @@ | ||
import { Types } from 'mongoose'; | ||
import { auditMockData } from '../audit/audit-mock-data'; | ||
import { Audit } from '../domain'; | ||
import { CreateCartItemsDTO } from '../order/dto/create-order.dto'; | ||
import { ICartItem } from './cart-entity.interface'; | ||
import { CartItem } from './cart-item'; | ||
import { createSelectedCartItems, selectedItemsMock } from './selectedItems/selected-item-mock-data'; | ||
const id = new Types.ObjectId(); | ||
const cartItemMockData: ICartItem = { | ||
menuId: id, | ||
orderId: id, | ||
total: 5, | ||
selectedItems: [selectedItemsMock], | ||
audit: Audit.create(auditMockData).getValue(), | ||
}; | ||
|
||
export const cartItemMock = CartItem.create(cartItemMockData); | ||
|
||
export const createItem: CreateCartItemsDTO = { | ||
menuId: id, | ||
orderId: id, | ||
note: '', | ||
total: 5, | ||
selectedItems: [createSelectedCartItems], | ||
}; |
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
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,26 @@ | ||
import { Types } from 'mongoose'; | ||
import { auditMockData } from '../../audit/audit-mock-data'; | ||
import { Audit } from '../../domain'; | ||
import { CreateSelectedItemsDTO } from '../../order/dto/create-order.dto'; | ||
import { ISelectedCartItem } from './selected-cart-items-entity.interface'; | ||
import { SelectedCartItem } from './selectedCartItem'; | ||
|
||
const id = new Types.ObjectId(); | ||
const selectedItemsMockData: ISelectedCartItem = { | ||
cartItemId: id, | ||
itemId: id, | ||
menuId: id, | ||
price: 2, | ||
quantity: 3, | ||
audit: Audit.create(auditMockData).getValue(), | ||
}; | ||
|
||
export const selectedItemsMock = SelectedCartItem.create(selectedItemsMockData); | ||
|
||
export const createSelectedCartItems: CreateSelectedItemsDTO = { | ||
cartItemId: id.toString(), | ||
menuId: id.toString(), | ||
itemId: id.toString(), | ||
price: 1, | ||
quantity: 1, | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
backend/src/infrastructure/data_access/repositories/schemas/order-status.schema.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
6 changes: 3 additions & 3 deletions
6
backend/src/infrastructure/data_access/repositories/schemas/order.schema.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
2 changes: 1 addition & 1 deletion
2
backend/src/infrastructure/data_access/repositories/schemas/selected-cart-item.schema.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
4 changes: 2 additions & 2 deletions
4
backend/src/infrastructure/data_access/repositories/selected-cart-item.repository.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Types } from 'mongoose'; | ||
import { auditMockData } from '../audit/audit-mock-data'; | ||
import { cartItemMock, createItem } from '../cart/cart-item-mock-data'; | ||
import { Audit } from '../domain'; | ||
import { orderStatusMockData } from '../order_statuses/order-status-mock'; | ||
import { OrderStatus } from '../order_statuses/order_status'; | ||
import { CreateOrderDTO } from './dto/create-order.dto'; | ||
import { IOrder } from './order-entity.interface'; | ||
|
||
const id = new Types.ObjectId(); | ||
|
||
export const orderMockData: IOrder = { | ||
state: OrderStatus.create(orderStatusMockData), | ||
type: 'DINE_IN', | ||
merchantId: id, | ||
customerId: id, | ||
total: 1, | ||
audit: Audit.create(auditMockData).getValue(), | ||
cartItems: [cartItemMock], | ||
}; | ||
|
||
export const orderMock: CreateOrderDTO = { | ||
state: 'CREATED', | ||
type: 'DINE_IN', | ||
merchantId: id.toString(), | ||
total: 1, | ||
cartItems: [createItem], | ||
}; |
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
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,75 @@ | ||
import { expect } from 'chai'; | ||
import mongoose, { Connection } from 'mongoose'; | ||
import * as sinon from 'ts-sinon'; | ||
import { CartItemMapper } from '../cart/cart-item.mapper'; | ||
import { SelectedCartItemMapper } from '../cart/selectedItems/selected-cart-item.mapper'; | ||
import { IContextService, MerchantRepository } from '../infrastructure'; | ||
import { ICartItemRepository } from '../infrastructure/data_access/repositories/interfaces/cart-item-repository.interface'; | ||
import { IOrderRepository } from '../infrastructure/data_access/repositories/interfaces/order-repository.interface'; | ||
import { IOrderStatusRespository } from '../infrastructure/data_access/repositories/interfaces/order-status.repository'; | ||
import { SelectedCartItemRepository } from '../infrastructure/data_access/repositories/selected-cart-item.repository'; | ||
import { IMerchantService } from '../merchant'; | ||
import { IOrderNoteService } from '../order_notes/interface/order-note-service.interface'; | ||
import { IOrderProcessingQueueService } from '../order_processing_queue/interface/order-processing-queue-service.interface'; | ||
import { OrderStatusMapper } from '../order_statuses/order_status.mapper'; | ||
import { AuditMapper } from './../audit/audit.mapper'; | ||
import { IOrderService } from './interface/order-service.interface'; | ||
import { orderMock } from './order-mock-data'; | ||
import { OrderMapper } from './order.mapper'; | ||
import { OrderService } from './order.service'; | ||
|
||
describe('Order Service', () => { | ||
let connection: Connection; | ||
beforeEach(async () => { | ||
connection = new Connection(); | ||
}); | ||
afterEach(async () => { | ||
connection.close(); | ||
mongoose.disconnect(); | ||
}); | ||
|
||
const orderRepositoryStub: IOrderRepository = sinon.stubInterface<IOrderRepository>(); | ||
const merchantServiceStub: IMerchantService = sinon.stubInterface<IMerchantService>(); | ||
const contextServiceStub: IContextService = sinon.stubInterface<IContextService>(); | ||
const merchantRepositoryStub: MerchantRepository = sinon.stubInterface<MerchantRepository>(); | ||
const selectedCartItemRepositoryStub: SelectedCartItemRepository = sinon.stubInterface<SelectedCartItemRepository>(); | ||
const auditMapperStub = new AuditMapper(); | ||
const selectedCartItemMapperStub = new SelectedCartItemMapper(); | ||
const cartItemMapperStub = new CartItemMapper(auditMapperStub, selectedCartItemMapperStub); | ||
const cartItemRepositoryStub: ICartItemRepository = sinon.stubInterface<ICartItemRepository>(); | ||
const orderStatusMapperStub = new OrderStatusMapper(auditMapperStub); | ||
const orderMapperStub = new OrderMapper(auditMapperStub, cartItemMapperStub, orderStatusMapperStub); | ||
const orderStatusRepositoryStub: IOrderStatusRespository = sinon.stubInterface<IOrderStatusRespository>(); | ||
const orderNoteServiceStub: IOrderNoteService = sinon.stubInterface<IOrderNoteService>(); | ||
const orderProcessingQueueServiceStub: IOrderProcessingQueueService = | ||
sinon.stubInterface<IOrderProcessingQueueService>(); | ||
const orderService: IOrderService = new OrderService( | ||
orderRepositoryStub, | ||
merchantServiceStub, | ||
contextServiceStub, | ||
merchantRepositoryStub, | ||
selectedCartItemRepositoryStub, | ||
orderMapperStub, | ||
selectedCartItemMapperStub, | ||
cartItemMapperStub, | ||
cartItemRepositoryStub, | ||
orderStatusRepositoryStub, | ||
orderNoteServiceStub, | ||
orderProcessingQueueServiceStub, | ||
); | ||
|
||
it('Should not create an order, It should throw a duplicate order warning', async () => { | ||
try { | ||
merchantServiceStub.validateContext = async () => { | ||
return Promise.resolve(true); | ||
}; | ||
orderRepositoryStub.getDuplicateOrder = async () => { | ||
return Promise.resolve(true); | ||
}; | ||
await orderService.createOrder(orderMock); | ||
} catch (error: any) { | ||
expect(error.response.status).to.equal(404); | ||
expect(error.response.error).to.equal('Duplicate order detected. Please confirm.'); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.