Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
pull_request:
branches:
- main
- develop

jobs:
linter_eslint:
name: linter:eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run lint

tests_units:
name: tests:units
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run test:cov

build_app:
name: build:app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm run build
1 change: 1 addition & 0 deletions .idea/locklite.iml

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

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ format: node_modules
npm run format

tests: node_modules
npm run test
npm test

coverage: node_modules
npm run test:cov

migrate: up
npx prisma migrate dev --name init

.PHONY: up down dev build lint format tests migrate
.PHONY: up down dev build lint format tests coverage migrate

# Aliases
run: up dev
Expand Down
24 changes: 17 additions & 7 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
roots: ['<rootDir>/tests'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.jest.json',
},
},
transform: {
'^.+\\.(ts|tsx)$': ['ts-jest', {}],
'^.+\\.(ts|tsx)$': [
'ts-jest',
{
tsconfig: 'tsconfig.jest.json',
},
],
},
roots: ['<rootDir>'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
Expand All @@ -22,6 +22,16 @@ const config: Config = {
'^@prisma/(.*)$': '<rootDir>/prisma/$1',
'^@lib/(.*)$': '<rootDir>/lib/$1',
},
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
coveragePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/prisma/'],
};

export default config;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "next start",
"lint": "next lint",
"format": "prettier --write .",
"test": "jest"
"test": "jest",
"test:cov": "jest --coverage"
},
"dependencies": {
"@prisma/client": "^6.12.0",
Expand Down
55 changes: 55 additions & 0 deletions tests/units/modules/api/adapters/user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import "reflect-metadata";

import {UserAdapter} from '@api/adapters/user.adapter';
import type {MasterAccount} from '@prisma/generated';
import type {UserModelDto} from '@shared/dto/models/user.model.dto';

describe('UserAdapter', () => {
let adapter: UserAdapter;

beforeEach(() => {
adapter = new UserAdapter();
});

describe('getUsersFromMasterAccounts()', () => {
it('should map an array of MasterAccount to UserModelDto[]', () => {
const masterAccounts: MasterAccount[] = [
{
id: '1',
email: 'alice@example.com',
password: 'secret1',
createdAt: new Date('2025-01-01T00:00:00.000Z'),
} as any,
{
id: '2',
email: 'bob@example.com',
password: 'secret2',
createdAt: new Date('2025-02-02T00:00:00.000Z'),
} as any,
];

const expected: UserModelDto[] = [
{
id: '1',
email: 'alice@example.com',
password: 'secret1',
createdAt: new Date('2025-01-01T00:00:00.000Z'),
},
{
id: '2',
email: 'bob@example.com',
password: 'secret2',
createdAt: new Date('2025-02-02T00:00:00.000Z'),
},
];

const result = adapter.getUsersFromMasterAccounts(masterAccounts);
expect(result).toEqual(expected);
});

it('should return an empty array when passed an empty array', () => {
const result = adapter.getUsersFromMasterAccounts([]);
expect(result).toEqual([]);
});
});
});