From 0c035d0168ff7b02c26a494de59c82433601ed67 Mon Sep 17 00:00:00 2001 From: Stanislav Basarab Date: Wed, 5 Jun 2024 23:24:00 +0300 Subject: [PATCH] ci: added github workflows to the project - added build - added build, linter and tests for back - added linter for front closes #24 --- .github/actions/install/action.yml | 18 +++ .github/workflows/back-actions.yml | 33 +++++ .github/workflows/front-actions.yml | 15 +++ .../src/api/auction/auction.service.ispec.ts | 60 +++++++++ .../src/api/auction/tests/auctions.ispec.ts | 118 ------------------ apps/api/src/api/auth/auth.controller.ts | 2 +- .../src/api/bid/responses/bids.resposne.ts | 2 +- apps/api/src/api/photo/photo.controller.ts | 2 +- apps/web/src/app/providers.tsx | 3 - apps/web/src/components/ui/command.tsx | 2 +- apps/web/src/components/ui/textarea.tsx | 3 +- 11 files changed, 131 insertions(+), 127 deletions(-) create mode 100644 .github/actions/install/action.yml create mode 100644 .github/workflows/back-actions.yml create mode 100644 .github/workflows/front-actions.yml create mode 100644 apps/api/src/api/auction/auction.service.ispec.ts delete mode 100644 apps/api/src/api/auction/tests/auctions.ispec.ts diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml new file mode 100644 index 0000000..5598fa1 --- /dev/null +++ b/.github/actions/install/action.yml @@ -0,0 +1,18 @@ +name: 'Install Node.js and dependencies' + +description: 'Set up Node and dependencies' +runs: + using: composite + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 18.17.0 + - name: Install pnpm + shell: bash + run: npm install -g pnpm + - name: Install dependencies + shell: bash + run: pnpm install \ No newline at end of file diff --git a/.github/workflows/back-actions.yml b/.github/workflows/back-actions.yml new file mode 100644 index 0000000..0c869d9 --- /dev/null +++ b/.github/workflows/back-actions.yml @@ -0,0 +1,33 @@ +name: Backend Actions +on: + push: + paths: + - 'apps/api/**' +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node and dependencies + uses: ./.github/actions/install + - name: Run build + run: pnpm dlx nx build api + linter: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node and dependencies + uses: ./.github/actions/install + - name: Run lint + run: pnpm dlx nx lint api + integration-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node and dependencies + uses: ./.github/actions/install + - name: Run integration tests + run: export NODE_ENV=development && pnpm dlx nx test:integration api \ No newline at end of file diff --git a/.github/workflows/front-actions.yml b/.github/workflows/front-actions.yml new file mode 100644 index 0000000..cf21df9 --- /dev/null +++ b/.github/workflows/front-actions.yml @@ -0,0 +1,15 @@ +name: Frontend Actions +on: + push: + paths: + - 'apps/web/**' +jobs: + linter: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Node and dependencies + uses: ./.github/actions/install + - name: Run lint + run: pnpm dlx nx lint web \ No newline at end of file diff --git a/apps/api/src/api/auction/auction.service.ispec.ts b/apps/api/src/api/auction/auction.service.ispec.ts new file mode 100644 index 0000000..a43ea88 --- /dev/null +++ b/apps/api/src/api/auction/auction.service.ispec.ts @@ -0,0 +1,60 @@ +import { Test } from '@nestjs/testing'; +import { MessageModule } from '../message/message.module'; +import { BidModule } from '../bid/bid.module'; +import { FileModule } from '../../file/file.module'; +import { AuctionGateway } from './gateways/auction.gateway'; +import { AuctionService } from './auction.service'; +import { AuctionMapper } from './auction.mapper'; +import { messageProviders } from '../../database/providers/message.provider'; +import { bidProviders } from '../../database/providers/bid.provider'; +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'; + +describe('Auction integration test', () => { + let auctionService: AuctionService; + let auction; + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + AuctionGateway, + AuctionService, + AuctionMapper, + ...messageProviders, + ...bidProviders, + ...auctionProviders, + ...photoProviders, + ], + imports: [MessageModule, BidModule, FileModule, DatabaseModule], + }).compile(); + auctionService = moduleRef.get(AuctionService); + + auction = await auctionService.createAuction({ + name: 'Vintage Painting Auction', + startPrice: 100, + stepPrice: 10, + currentPrice: 100, + endDate: '2024-12-31T23:59:59Z', + description: 'A vintage painting from the 19th century.', + } as Auction); + }); + + it('should return auction', async () => { + const gottenAuction = await auctionService.get(auction.id); + + expect(gottenAuction.dataValues).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: [], + }); + }); +}); \ No newline at end of file diff --git a/apps/api/src/api/auction/tests/auctions.ispec.ts b/apps/api/src/api/auction/tests/auctions.ispec.ts deleted file mode 100644 index b95c86b..0000000 --- a/apps/api/src/api/auction/tests/auctions.ispec.ts +++ /dev/null @@ -1,118 +0,0 @@ -import { Test } from "@nestjs/testing"; -import { MessageModule } from "../../message/message.module"; -import { BidModule } from "../../bid/bid.module"; -import { FileModule } from "../../../file/file.module"; -import { AuctionGateway } from "../gateways/auction.gateway"; -import { AuctionService } from "../auction.service"; -import { AuctionMapper } from "../auction.mapper"; -import { messageProviders } from "../../../database/providers/message.provider"; -import { bidProviders } from "../../../database/providers/bid.provider"; -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 auction1; - let auction2; - let auction3; - - beforeAll(async () => { - const moduleRef = await Test.createTestingModule({ - providers: [ - AuctionGateway, - AuctionService, - AuctionMapper, - ...messageProviders, - ...bidProviders, - ...auctionProviders, - ...photoProviders, - ], - imports: [MessageModule, BidModule, FileModule, DatabaseModule], - }).compile(); - auctionService = moduleRef.get(AuctionService); - - auction1 = await auctionService.createAuction({ - name: "Vintage Painting Auction", - startPrice: 100, - stepPrice: 10, - currentPrice: 100, - endDate: "2024-12-31T23:59:59Z", - description: "A vintage painting from the 19th century.", - } as Auction); - - auction2 = await auctionService.createAuction({ - name: "Container", - startPrice: 500, - stepPrice: 100, - currentPrice: 600, - endDate: "2024-12-31T23:59:59Z", // Corrected date format - description: "15 years old container.", - } as Auction); - - auction3 = await auctionService.createAuction({ - name: "Linkin park's group guitar", - startPrice: 8000, - stepPrice: 500, - currentPrice: 15000, - endDate: "2024-12-31T23:59:59Z", // Corrected date format - description: "Linkin park's group guitar from 2000s.", - } as Auction); - }); - - it('should return auction', async () => { - const gottenAuction = await auctionService.getAllAuctions({ sortBy: AuctionSortingEnum.CURRENT_PRICE, sortOrder: 'ASC' }); - - const auctions = gottenAuction.map((auction) => { - return auction.dataValues; - }) - console.log(gottenAuction) - - expect(auctions).toEqual([ - { - id: auction1.id, - name: 'Vintage Painting Auction', - userId: null, - startPrice: 100, - stepPrice: 10, - currentPrice: 100, - endDate: auction1.endDate, - description: 'A vintage painting from the 19th century.', - createdAt: auction1.createdAt, - updatedAt: auction1.updatedAt, - photos: [], - bids: [] - }, - { - id: auction2.id, - name: 'Container', - userId: null, - startPrice: 500, - stepPrice: 100, - currentPrice: 600, - endDate: auction2.endDate, - description: '15 years old container.', - createdAt: auction2.createdAt, - updatedAt: auction2.updatedAt, - photos: [], - bids: [] - }, - { - id: auction3.id, - name: "Linkin park's group guitar", - userId: null, - startPrice: 8000, - stepPrice: 500, - currentPrice: 15000, - endDate: auction3.endDate, - description: "Linkin park's group guitar from 2000s.", - createdAt: auction3.createdAt, - updatedAt: auction3.updatedAt, - photos: [], - bids: [] - } - ]); - }); -}); diff --git a/apps/api/src/api/auth/auth.controller.ts b/apps/api/src/api/auth/auth.controller.ts index ec20532..eefa76b 100644 --- a/apps/api/src/api/auth/auth.controller.ts +++ b/apps/api/src/api/auth/auth.controller.ts @@ -20,7 +20,7 @@ import { LoginDto } from './dto/login.dto'; @Controller('auth') export class AuthController { constructor ( - private authService: AuthService + private authService: AuthService, ) {} @Post('/register') diff --git a/apps/api/src/api/bid/responses/bids.resposne.ts b/apps/api/src/api/bid/responses/bids.resposne.ts index 90b05b8..8159ad2 100644 --- a/apps/api/src/api/bid/responses/bids.resposne.ts +++ b/apps/api/src/api/bid/responses/bids.resposne.ts @@ -1,4 +1,4 @@ -import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; +import { ApiProperty } from '@nestjs/swagger'; class ShortUserResponse { @ApiProperty({ description: 'User id' }) diff --git a/apps/api/src/api/photo/photo.controller.ts b/apps/api/src/api/photo/photo.controller.ts index 42fd961..2609aee 100644 --- a/apps/api/src/api/photo/photo.controller.ts +++ b/apps/api/src/api/photo/photo.controller.ts @@ -15,7 +15,7 @@ import { PhotoResponse } from '../auction/responses/auctions.resposne'; @Controller('/photos') export class PhotoController { constructor ( - private readonly photoService: PhotoService + private readonly photoService: PhotoService, ) {} @Post('/:index') diff --git a/apps/web/src/app/providers.tsx b/apps/web/src/app/providers.tsx index 3908db0..70c17d8 100644 --- a/apps/web/src/app/providers.tsx +++ b/apps/web/src/app/providers.tsx @@ -1,8 +1,5 @@ // In Next.js, this file would be called: app/providers.jsx "use client"; - -// We can not useState or useRef in a server component, which is why we are -// extracting this part out into it's own file with 'use client' on top import { useState } from "react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; diff --git a/apps/web/src/components/ui/command.tsx b/apps/web/src/components/ui/command.tsx index 17cc641..a3bd065 100644 --- a/apps/web/src/components/ui/command.tsx +++ b/apps/web/src/components/ui/command.tsx @@ -23,7 +23,7 @@ const Command = React.forwardRef< )) Command.displayName = CommandPrimitive.displayName -interface CommandDialogProps extends DialogProps {} +type CommandDialogProps = DialogProps const CommandDialog = ({ children, ...props }: CommandDialogProps) => { return ( diff --git a/apps/web/src/components/ui/textarea.tsx b/apps/web/src/components/ui/textarea.tsx index 9f9a6dc..12c9136 100644 --- a/apps/web/src/components/ui/textarea.tsx +++ b/apps/web/src/components/ui/textarea.tsx @@ -2,8 +2,7 @@ import * as React from "react" import { cn } from "@/lib/utils" -export interface TextareaProps - extends React.TextareaHTMLAttributes {} +export type TextareaProps = React.TextareaHTMLAttributes const Textarea = React.forwardRef( ({ className, ...props }, ref) => {