Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI/CD Pipeline

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install Dependencies
run: npm ci

- name: Run Linter
run: npm run lint || true

- name: Run Tests
run: npm run test

- name: Build Project
run: npm run build

- name: Deploy to Server via SSH
if: github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd ${{ secrets.SERVER_APP_PATH }}
git pull origin main
npm ci
npm run build
pm2 restart all
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testEnvironment: 'node',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/src/$1',
},
};
17 changes: 0 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,5 @@
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
40 changes: 25 additions & 15 deletions src/PuzzleService Logic/puzzle.controller.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
// import { Controller, Post, Param, Body, UseGuards } from '@nestjs/common';
// import { PuzzleService } from './puzzle.service';
import { Controller, Post, Param, Body, UseGuards } from '@nestjs/common';
import { PuzzleService } from './puzzle.service';
import { AuthGuard } from '@nestjs/passport';
import { createParamDecorator, ExecutionContext } from '@nestjs/common';

// @Controller('puzzles')
// // @UseGuards(AuthGuard)
// export class PuzzleController {
// constructor(private readonly puzzleService: PuzzleService) {}
@Controller('puzzles')
@UseGuards(AuthGuard)
export class PuzzleController {
constructor(private readonly puzzleService: PuzzleService) {}

// @Post(':id/submit')
// async submitPuzzle(
// @UserId() userId: string,
// @Param('id') puzzleId: string,
// @Body() attemptData: any,
// ) {
// return this.puzzleService.submitPuzzleSolution(userId, puzzleId, attemptData);
// }
// }
@Post(':id/submit')
async submitPuzzle(
@UserId() userId: string,
@Param('id') puzzleId: string,
@Body() attemptData: any,
) {
return this.puzzleService.submitPuzzleSolution(userId, puzzleId, attemptData);
}
};

export const UserId = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
// Assumes user object is attached to request by AuthGuard
return request.user?.id;
},
);

Check failure on line 27 in src/PuzzleService Logic/puzzle.controller.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Unsafe assignment of an `any` value
24 changes: 13 additions & 11 deletions src/PuzzleService Logic/puzzle.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { PuzzleService } from './puzzle.service';
import {
Puzzle,
PuzzleSubmission,
PuzzleProgress,
User,
PuzzleType,
PuzzleDifficulty,
} from './entities';
import {
XP_BY_DIFFICULTY,
TOKENS_BY_DIFFICULTY,
} from './constants';
import { PuzzleType } from 'src/puzzle/enums/puzzle-type.enum';
import { Puzzle } from './puzzle.entity';
import { PuzzleSubmission } from './puzzle-submission.entity';
import { PuzzleProgress } from './puzzle-progress.entity';
import { User } from './user.entity';
import { PuzzleDifficulty } from 'src/puzzle/enums/puzzle-difficulty.enum';

describe('PuzzleService', () => {
let service: PuzzleService;
Expand All @@ -27,11 +25,15 @@ describe('PuzzleService', () => {
providers: [
PuzzleService,
{
provide: getRepositoryToken(Puzzle),
useClass: Repository,
provide: getRepositoryToken(PuzzleSubmission),
useValue: {
create: jest.fn(),
save: jest.fn(),
findOne: jest.fn(),
},
},
{
provide: getRepositoryToken(PuzzleSubmission),
provide: getRepositoryToken(Puzzle),
useClass: Repository,
},
{
Expand Down
Loading
Loading