Skip to content

Commit

Permalink
Merge pull request #14 from Sma1lboy/feat-adding-jest-test
Browse files Browse the repository at this point in the history
Feat adding jest test
  • Loading branch information
Sma1lboy authored Oct 23, 2024
2 parents d7f3716 + 1ff324d commit c336f4c
Show file tree
Hide file tree
Showing 25 changed files with 1,443 additions and 149 deletions.
16 changes: 16 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
coverageDirectory: '../coverage',
testEnvironment: 'node',
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/$1',
},
modulePaths: ['<rootDir>'],
moduleDirectories: ['node_modules', 'src'],
};
22 changes: 4 additions & 18 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "generator-ai",
"name": "codefox",
"version": "0.0.1",
"description": "",
"author": "",
Expand Down Expand Up @@ -33,8 +33,10 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"@types/bcrypt": "^5.0.2",
"@types/fs-extra": "^11.0.4",
"bcrypt": "^5.1.1",
"class-validator": "^0.14.1",
"fs-extra": "^11.2.0",
"graphql": "^16.9.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
Expand All @@ -55,6 +57,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"os": "^0.1.2",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
Expand All @@ -63,22 +66,5 @@
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
37 changes: 37 additions & 0 deletions backend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import { InjectRepository } from '@nestjs/typeorm';
import { compare, hash } from 'bcrypt';
import { LoginUserInput } from 'src/user/dto/lgoin-user.input';
import { LoginUserInput } from 'src/user/dto/login-user.input';
import { RegisterUserInput } from 'src/user/dto/register-user.input';
import { User } from 'src/user/user.model';
import { Repository } from 'typeorm';
Expand Down
161 changes: 161 additions & 0 deletions backend/src/config/common-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import path from 'path';
import os from 'os';
import { name } from '../../package.json';
import { existsSync, mkdirSync, promises } from 'fs-extra';

export class CodeFoxPaths {
private static readonly APP_NAME = name;
private static readonly ROOT_DIR = path.join(
os.homedir(),
`.${CodeFoxPaths.APP_NAME}`,
);

/**
* Internal helper to ensure a directory exists before returning its path
* @param dirPath The directory path to check/create
* @returns The same directory path
*/
private static ensureDir(dirPath: string): string {
if (!existsSync(path.dirname(dirPath))) {
this.ensureDir(path.dirname(dirPath));
}
if (!existsSync(dirPath)) {
mkdirSync(dirPath, { recursive: true });
}
return dirPath;
}

/**
* Root Directory
*/
public static getRootDir(): string {
return this.ensureDir(CodeFoxPaths.ROOT_DIR);
}

/**
* Models Directory
*/
public static getModelsDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'models'));
}

public static getModelPath(modelName: string): string {
return path.join(this.getModelsDir(), modelName);
}

/**
* Projects Directory
*/
public static getProjectsDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'projects'));
}

public static getProjectPath(projectId: string): string {
return this.ensureDir(path.join(this.getProjectsDir(), projectId));
}

public static getProjectSourceDir(projectId: string): string {
return this.ensureDir(path.join(this.getProjectPath(projectId), 'src'));
}

public static getProjectGeneratedDir(projectId: string): string {
return this.ensureDir(
path.join(this.getProjectPath(projectId), 'generated'),
);
}

public static getProjectTestsDir(projectId: string): string {
return this.ensureDir(path.join(this.getProjectPath(projectId), 'tests'));
}

/**
* Database
*/
public static getDatabaseDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'data'));
}

public static getDatabasePath(): string {
this.getDatabaseDir(); // Ensure database directory exists
return path.join(this.getDatabaseDir(), 'codefox.db');
}

/**
* Configuration
*/
public static getConfigDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'config'));
}

public static getConfigPath(configName: string): string {
this.getConfigDir(); // Ensure config directory exists
return path.join(this.getConfigDir(), `${configName}.json`);
}

/**
* Cache
*/
public static getCacheDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'cache'));
}

/**
* Logs
*/
public static getLogsDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'logs'));
}

/**
* Temporary files
*/
public static getTempDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'temp'));
}

/**
* Templates
*/
public static getTemplatesDir(): string {
return this.ensureDir(path.join(this.getRootDir(), 'templates'));
}

public static getPromptTemplatePath(templateName: string): string {
this.getTemplatesDir(); // Ensure templates directory exists
return path.join(this.getTemplatesDir(), `${templateName}.txt`);
}

/**
* Utility Methods
*/
public static resolvePath(...pathSegments: string[]): string {
const resolvedPath = path.join(this.getRootDir(), ...pathSegments);
return this.ensureDir(path.dirname(resolvedPath));
}

public static exists(filePath: string): boolean {
return existsSync(filePath);
}

public static async cleanTempDir(): Promise<void> {
const tempDir = this.getTempDir();
const files = await promises.readdir(tempDir);
await Promise.all(
files.map((file) => promises.unlink(path.join(tempDir, file))),
);
}

public static getProjectStructure(projectId: string): {
root: string;
src: string;
generated: string;
tests: string;
} {
return {
root: this.getProjectPath(projectId),
src: this.getProjectSourceDir(projectId),
generated: this.getProjectGeneratedDir(projectId),
tests: this.getProjectTestsDir(projectId),
};
}
}
Loading

0 comments on commit c336f4c

Please sign in to comment.