Skip to content

Commit

Permalink
Merge pull request #12 from Adrianmjim/feature/reafactor-base-code
Browse files Browse the repository at this point in the history
Refactor food module and user module
  • Loading branch information
Adrianmjim authored Sep 15, 2022
2 parents b15f1ae + bbf9ca2 commit 430f510
Show file tree
Hide file tree
Showing 151 changed files with 1,140 additions and 2,008 deletions.
148 changes: 95 additions & 53 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,84 +1,108 @@
{
"root": true,
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
"plugin:import/typescript",
"plugin:import/warnings"
],
"overrides": [{
"files": [ "**/*.spec.ts" ],
"extends": [
"plugin:jest/recommended",
"plugin:jest/style"
],
"rules": {
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-magic-numbers": "off",
"jest/valid-title": "off"
"overrides": [
{
"extends": ["plugin:jest/recommended", "plugin:jest/style"],
"files": ["**/*.spec.ts"],
"rules": {
"@typescript-eslint/no-magic-numbers": "off",
"@typescript-eslint/unbound-method": "off",
"jest/valid-title": "off"
}
}
}],
"plugins": ["@typescript-eslint", "import"],
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module",
"project": [
"./tsconfig.build.json"
]
"project": ["./tsconfig.build.json"],
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "import"],
"root": true,
"rules": {
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-array-constructor": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/restrict-plus-operands": ["error", {
"checkCompoundAssignments": true
}],
"@typescript-eslint/typedef": ["error", {
"arrayDestructuring": false,
"arrowParameter": true,
"memberVariableDeclaration": true,
"objectDestructuring": true,
"parameter": true,
"propertyDeclaration": true,
"variableDeclaration": true
}],
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/restrict-plus-operands": [
"error",
{
"checkCompoundAssignments": true
}
],
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/no-unused-vars": ["warn", {"argsIgnorePattern": "^_"}],
"@typescript-eslint/typedef": [
"error",
{
"arrayDestructuring": false,
"arrowParameter": true,
"memberVariableDeclaration": true,
"objectDestructuring": true,
"parameter": true,
"propertyDeclaration": true,
"variableDeclaration": true
}
],
"@typescript-eslint/unified-signatures": "error",
"array-callback-return": "error",
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline"
}],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline",
"imports": "always-multiline",
"objects": "always-multiline"
}
],
"complexity": ["error", 12],
"consistent-return": "error",
"curly": "error",
"default-param-last": "error",
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"import/no-unresolved": [
"error",
{
"ignore": ["^firebase-admin/.+"]
}
],
"import/order": [
"error",
{
"alphabetize": {
"order": "asc",
"caseInsensitive": true
"caseInsensitive": true,
"order": "asc"
},
"groups": ["builtin", "external"]
"groups": ["builtin", "external"],
"newlines-between": "always"
}
],
"indent": "off",
Expand All @@ -88,8 +112,8 @@
"no-eval": "error",
"no-extra-label": "error",
"no-floating-decimal": "error",
"no-import-assign": "error",
"no-implied-eval": "error",
"no-import-assign": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-labels": "error",
Expand All @@ -98,6 +122,13 @@
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-proto": "error",
"no-restricted-syntax": [
"error",
{
"selector": "ClassBody > PropertyDefinition[optional=true] > TSTypeAnnotation > TSUnionType:has(TSUndefinedKeyword)",
"message": "We don't want to use undefined in optional properties"
}
],
"no-return-assign": "error",
"no-return-await": "error",
"no-self-compare": "error",
Expand All @@ -110,14 +141,25 @@
"no-useless-return": "error",
"no-var": "error",
"object-shorthand": "error",
"padding-line-between-statements": ["error", { "blankLine": "always", "prev": "block-like", "next": "*" }],
"prefer-arrow-callback": "error",
"prefer-promise-reject-errors": "error",
"quotes": [ "error", "single", { "avoidEscape": true } ],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"semi": "error",
"sort-keys": ["error", "asc", {
"caseSensitive": false,
"natural": true
}],
"sort-keys": [
"error",
"asc",
{
"caseSensitive": false,
"natural": true
}
],
"sort-vars": "error"
}
}
}
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ jobs:
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Upload coverage to Code Climate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_TOKEN }}

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@
"graphql-scalars": "1.18.0",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"rxjs": "7.5.6",
"uuid": "9.0.0"
"rxjs": "7.5.6"
},
"devDependencies": {
"@types/cookies": "0.7.7",
"@types/jest": "29.0.2",
"@types/jsonwebtoken": "8.5.9",
"@types/node": "16.11.59",
"@types/passport-jwt": "3.0.6",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.37.0",
"@typescript-eslint/parser": "5.37.0",
"enhanced-resolve": "5.10.0",
Expand Down
45 changes: 45 additions & 0 deletions src/AppModule.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { IMigrator, MikroORM } from '@mikro-orm/core';

import { AppModule } from './AppModule';

describe(AppModule.name, () => {
let migratorMock: jest.Mocked<IMigrator>;
let mikroOrmMock: jest.Mocked<MikroORM>;
let appModule: AppModule;

beforeAll(() => {
migratorMock = {
up: jest.fn(),
} as Partial<jest.Mocked<IMigrator>> as jest.Mocked<IMigrator>;

mikroOrmMock = {
getMigrator: jest.fn(),
} as Partial<jest.Mocked<MikroORM>> as jest.Mocked<MikroORM>;

appModule = new AppModule(mikroOrmMock);
});

describe('.onModuleInit()', () => {
describe('when called', () => {
beforeAll(async () => {
mikroOrmMock.getMigrator.mockReturnValueOnce(migratorMock);

await appModule.onModuleInit();
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call mikroOrm.getMigrator()', () => {
expect(mikroOrmMock.getMigrator).toHaveBeenCalledTimes(1);
expect(mikroOrmMock.getMigrator).toHaveBeenCalledWith();
});

it('should call mikroOrm.getMigrator().up()', () => {
expect(migratorMock.up).toHaveBeenCalledTimes(1);
expect(migratorMock.up).toHaveBeenCalledWith();
});
});
});
});
1 change: 1 addition & 0 deletions src/AppModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UUIDResolver,
VoidResolver,
} from 'graphql-scalars';

import { ConfigModule } from './config/infrastructure/injection/ConfigModule';
import { MikroOrmConfig } from './config/infrastructure/mikroOrm/MikroOrmConfig';

Expand Down
14 changes: 0 additions & 14 deletions src/cat/application/handler/CatDeleteCommandHandler.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/cat/application/handler/CatFindQueryHandler.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/cat/application/handler/CatInsertCommandHandlert.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/cat/application/handler/CatUpdateCommandHandler.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/cat/domain/command/CatUpdateCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ICommand } from '@nestjs/cqrs';

import { CatFindQuery } from '../query/CatFindQuery';
import { CatSetCommand } from './CatSetCommand';

Expand Down
12 changes: 0 additions & 12 deletions src/cat/domain/service/DeleteCatManager.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/cat/domain/service/FindCatManager.ts

This file was deleted.

Loading

0 comments on commit 430f510

Please sign in to comment.