From 3a49a0c2c07639a9ccb0b74965dfda3f03cf4091 Mon Sep 17 00:00:00 2001 From: Illia Date: Fri, 7 Jun 2024 19:13:24 +0300 Subject: [PATCH] test: implemented integration tests --- .../src/api/auction/auction.service.ispec.ts | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/apps/api/src/api/auction/auction.service.ispec.ts b/apps/api/src/api/auction/auction.service.ispec.ts index a43ea88..56cd9aa 100644 --- a/apps/api/src/api/auction/auction.service.ispec.ts +++ b/apps/api/src/api/auction/auction.service.ispec.ts @@ -11,10 +11,13 @@ import { auctionProviders } from '../../database/providers/auction.provider'; import { photoProviders } from '../../database/providers/photo.provider'; import { DatabaseModule } from '../../database/database.module'; import { Auction } from '../../database/entities/auction.entity'; +import {AuctionSortingEnum} from "./enums/auction-sorting.enum"; describe('Auction integration test', () => { let auctionService: AuctionService; let auction; + let auction2; + let auction3; beforeAll(async () => { const moduleRef = await Test.createTestingModule({ providers: [ @@ -38,6 +41,24 @@ describe('Auction integration test', () => { endDate: '2024-12-31T23:59:59Z', description: 'A vintage painting from the 19th century.', } as Auction); + + auction2 = await auctionService.createAuction({ + name: 'Container', + startPrice: 5000, + stepPrice: 500, + currentPrice: 6500, + endDate: '2024-12-31T23:59:59Z', + description: 'A 10 years old container.', + } as Auction); + + auction3 = await auctionService.createAuction({ + name: 'Car', + startPrice: 500000, + stepPrice: 10000, + currentPrice: 500000, + endDate: '2024-12-31T23:59:59Z', + description: 'Car of the president.', + } as Auction); }); it('should return auction', async () => { @@ -57,4 +78,142 @@ describe('Auction integration test', () => { photos: [], }); }); + + it('should return sorted by price auctions',async () => { + const auctions = await auctionService.getAllAuctions({ sortBy: AuctionSortingEnum.CURRENT_PRICE, sortOrder: 'ASC' }); + + const mapped = auctions.map((auction) => auction.dataValues); + + expect(mapped).toEqual([{ + id: auction.id, + userId: null, + name: 'Vintage Painting Auction', + startPrice: 100, + stepPrice: 10, + currentPrice: 100, + endDate: auction.endDate, + description: 'A vintage painting from the 19th century.', + createdAt: auction.createdAt, + updatedAt: auction.updatedAt, + photos: [], + bids: [], + }, { + id: auction2.id, + userId: null, + name: 'Container', + startPrice: 5000, + stepPrice: 500, + currentPrice: 6500, + endDate: auction2.endDate, + description: 'A 10 years old container.', + createdAt: auction2.createdAt, + updatedAt: auction2.updatedAt, + photos: [], + bids: [], + }, { + id: auction3.id, + userId: null, + name: 'Car', + startPrice: 500000, + stepPrice: 10000, + currentPrice: 500000, + endDate: auction3.endDate, + description: 'Car of the president.', + createdAt: auction3.createdAt, + updatedAt: auction3.updatedAt, + photos: [], + bids: [], + }]); + }); + + it('should return filtered auctions by name', async () => { + const auctions = await auctionService.getAllAuctions({ sortBy: AuctionSortingEnum.NAME, sortOrder: 'ASC' }); + + const mapped = auctions.map((auction) => auction.dataValues); + + expect(mapped).toEqual([{ + id: auction3.id, + userId: null, + name: 'Car', + startPrice: 500000, + stepPrice: 10000, + currentPrice: 500000, + endDate: auction3.endDate, + description: 'Car of the president.', + createdAt: auction3.createdAt, + updatedAt: auction3.updatedAt, + photos: [], + bids: [], + }, { + id: auction2.id, + userId: null, + name: 'Container', + startPrice: 5000, + stepPrice: 500, + currentPrice: 6500, + endDate: auction2.endDate, + description: 'A 10 years old container.', + createdAt: auction2.createdAt, + updatedAt: auction2.updatedAt, + photos: [], + bids: [], + }, { + id: auction.id, + userId: null, + name: 'Vintage Painting Auction', + startPrice: 100, + stepPrice: 10, + currentPrice: 100, + endDate: auction.endDate, + description: 'A vintage painting from the 19th century.', + createdAt: auction.createdAt, + updatedAt: auction.updatedAt, + photos: [], + bids: [], + }]); + }); + + it('should update auction', async () => { + const updatedAuction = await auctionService.updateAuction(auction.id, { + startPrice: 200, + stepPrice: 20, + currentPrice: 200 + }); + + expect(updatedAuction).toEqual({ + id: auction.id, + userId: null, + name: 'Vintage Painting Auction', + startPrice: 200, + stepPrice: 20, + currentPrice: 200, + endDate: auction.endDate, + description: 'A vintage painting from the 19th century.', + createdAt: auction.createdAt, + updatedAt: updatedAuction.updatedAt, + photos: [], + }); + }) + + + it('It should return one auction with appropriate name',async () => { + const auctions = await auctionService.getAllAuctions({ sortBy: AuctionSortingEnum.NAME, sortOrder: 'ASC' }, 'Car'); + + const mapped = auctions.map((auction) => auction.dataValues); + + expect(mapped).toEqual([{ + id: auction3.id, + userId: null, + name: 'Car', + startPrice: 500000, + stepPrice: 10000, + currentPrice: 500000, + endDate: auction3.endDate, + description: 'Car of the president.', + createdAt: auction3.createdAt, + updatedAt: auction3.updatedAt, + photos: [], + bids: [], + }]); + }); }); \ No newline at end of file