Skip to content

Commit

Permalink
test: implemented integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
illiakroshka committed Jun 7, 2024
1 parent 32ea7ed commit 3a49a0c
Showing 1 changed file with 159 additions and 0 deletions.
159 changes: 159 additions & 0 deletions apps/api/src/api/auction/auction.service.ispec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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 () => {
Expand All @@ -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: [],
}]);
});
});

0 comments on commit 3a49a0c

Please sign in to comment.