Skip to content

Commit

Permalink
Paths (#498)
Browse files Browse the repository at this point in the history
Add paths alias on server
  • Loading branch information
paolocattani committed Mar 17, 2021
1 parent 1a5ce3d commit 4dfc061
Show file tree
Hide file tree
Showing 56 changed files with 279 additions and 295 deletions.
2 changes: 1 addition & 1 deletion .idea/shelf/Pages/shelved.patch

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

25 changes: 16 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Debug Server",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
"type": "node",
"runtimeArgs": [
"-r",
"${workspaceFolder}/server/node_modules/ts-node/register",
"-r",
"${workspaceFolder}/server/node_modules/tsconfig-paths/register"
],
"program": "${workspaceFolder}/scripts/start.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
},
"args": ["${workspaceFolder}/server/server.ts"],
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"env": {
"NODE_ENV": "development",
"TS_NODE_PROJECT": "${workspaceFolder}/server/tsconfig.json"
},
"outFiles": ["${workspaceFolder}/server/lib/**/*.js"]
},
{
"name": "Chrome",
"type": "chrome",
Expand Down
5 changes: 2 additions & 3 deletions cli/functions/heroku.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function heroku_cli {
cp -r build server/build_server/* ./production_build
rm ./production_build/server/ecosystem.*.js
rm -r ./production_build/server/test
cp server/ecosystem.config.prod.js ./production_build/server/ecosystem.config.js
cp server/ecosystem.config.prod.js ./production_build/ecosystem.config.js
cp server/package*.json ./production_build
cp Procfile ./production_build

Expand Down Expand Up @@ -173,8 +173,7 @@ function heroku_cli {
#
if [[ $start -eq 1 ]]; then
text_color " --------------> Bootstrap application using pm2-runtime" $yellow
cd server
./node_modules/.bin/pm2-runtime start ecosystem.config.js
./node_modules/.bin/pm2-runtime start ./ecosystem.config.js
fi
exit 0
}
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/auth.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// https://on.cypress.io/intelligent-code-completion

import { AUTH_FORM, LandingPage, LOGIN_BUTTON, RegistrationProps, SWAP_BUTTON } from '../pages/landing.page';
import { UserRole } from '../../src/@common/dto';
import { UserRole } from '@common/dto';
import { Tournament } from '../pages/tournament.page';
import { fixCypressSpec } from '../support';
import { AuthState } from '../../src/@common/models';
import { AuthState } from '@common/models';
import { BE_DISABLED, BE_VISIBLE, HAVE_LENGTH } from '../pages/abstract.page';

const { users } = require('../fixtures/auth.fixture.json');
Expand Down
10 changes: 5 additions & 5 deletions cypress/pages/abstract.page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AuthenticationResponse, RootState} from '../../src/@common/models';
import { AuthenticationResponse, RootState } from '@common/models';
import { RegistrationProps } from './landing.page';
import { AuthAction } from '../../src/redux/actions';
import {UserDTO} from "../../src/@common/dto";
import { UserDTO } from '@common/dto';
const { users } = require('../fixtures/auth.fixture.json');
const user: RegistrationProps = users.user;
const admin: RegistrationProps = users.admin;
Expand All @@ -12,11 +12,11 @@ export const HAVE_LENGTH = 'have.length';
export const headers = { headers: { 'Content-Type': 'application/json' } };

export abstract class AbstractPage {
user?:UserDTO;
user?: UserDTO;

abstract visit(username?: string, password?: string): Cypress.Chainable<Cypress.AUTWindow>;

getUser(){
getUser() {
return this.user;
}

Expand Down Expand Up @@ -74,7 +74,7 @@ export abstract class AbstractPage {

forceRegisterAdmin() {
this.forceDeleteUser(admin.email, admin.username, admin.password);
this.forceRegistration({...admin,name:`[A]${admin.name}`});
this.forceRegistration({ ...admin, name: `[A]${admin.name}` });
}

forceRegistration(registrationOptions: RegistrationProps) {
Expand Down
8 changes: 3 additions & 5 deletions cypress/pages/pair.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AbstractPage, headers} from './abstract.page';
import {AuthAction} from "../../src/redux/actions";
import {OmitHistory, SaveTournamentRequest} from "../../src/@common/models";
import { AbstractPage, headers } from './abstract.page';
import { AuthAction } from '../../src/redux/actions';
import { OmitHistory, SaveTournamentRequest } from '@common/models';

export class Pairs extends AbstractPage {
// Override
Expand All @@ -15,6 +15,4 @@ export class Pairs extends AbstractPage {
getTable() {
return cy.get('[data-cy=pair-table]');
}


}
32 changes: 16 additions & 16 deletions cypress/pages/tournament.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AbstractPage, headers} from './abstract.page';
import {AuthAction} from "../../src/redux/actions";
import {DeleteTournamentRequest, OmitHistory, SaveTournamentRequest} from "../../src/@common/models";
import { AbstractPage, headers } from './abstract.page';
import { AuthAction } from '../../src/redux/actions';
import { DeleteTournamentRequest, OmitHistory, SaveTournamentRequest } from '@common/models';

export class Tournament extends AbstractPage {
// Override
Expand All @@ -14,51 +14,51 @@ export class Tournament extends AbstractPage {
}

// New Tournament
getNewName(){
getNewName() {
return cy.get('[data-cy=new-name]');
}
getNewDate(){
getNewDate() {
return cy.get('[data-cy=new-date]');
}
getNewVisibility(){
getNewVisibility() {
return cy.get('[data-cy=new-visibility]');
}
getNewSubmit(){
getNewSubmit() {
return cy.get('[data-cy=new-submit]');
}
getNewTournamentButton() {
return cy.get('[data-cy=new-tournament]');
}

// Selection
getSelect(){
return cy.get("#tournamentSelect");
getSelect() {
return cy.get('#tournamentSelect');
}
getSelectSubmit(){
getSelectSubmit() {
return cy.get('[data-cy=select-submit]');
} getSelectTournamentButton() {
}
getSelectTournamentButton() {
return cy.get('[data-cy=select-tournament]');
}

// Force
forceNewTournament(body: OmitHistory<SaveTournamentRequest> ){
forceNewTournament(body: OmitHistory<SaveTournamentRequest>) {
cy.request({
...headers,
method: 'POST',
url: 'http://localhost:5001/api/v2/tournament/new',
body
body,
}).then((resp) => {
cy.visit('/');
});
}

forceDeleteTournament(){
forceDeleteTournament() {
cy.request({
...headers,
method: 'DELETE',
url: 'http://localhost:5001/api/v2/tournament/test/delete',
body:{secret: Cypress.env('secret')}
body: { secret: Cypress.env('secret') },
});
}

}
44 changes: 22 additions & 22 deletions server/controller/auth/__mocks__/auth.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { PlayerRole } from '../../../../src/@common/dto/player.dto';
import { PlayerRole } from '@common/dto/player.dto';

// https://www.fakenamegenerator.com/gen-male-us-it.php
export const TEST_USER_1 = {
username: 'dummy1',
name: 'William1',
surname: 'J. Ayers1',
email: 'WilliamJAyers@spy1.com',
cEmail: 'WilliamJAyers@spy1.com',
password: 'dummyPassword1',
cPassword: 'dummyPassword1',
phone: '0362 3981901',
birthday: new Date(1939, 0, 16),
playerRole: PlayerRole.Master,
username: 'dummy1',
name: 'William1',
surname: 'J. Ayers1',
email: 'WilliamJAyers@spy1.com',
cEmail: 'WilliamJAyers@spy1.com',
password: 'dummyPassword1',
cPassword: 'dummyPassword1',
phone: '0362 3981901',
birthday: new Date(1939, 0, 16),
playerRole: PlayerRole.Master,
};

export const TEST_USER_2 = {
// https://www.fakenamegenerator.com/gen-male-us-it.php
username: 'dummy2',
name: 'William2',
surname: 'J. Ayers2',
email: 'WilliamJAyers@army2.com',
cEmail: 'WilliamJAyers@army2.com',
password: 'dummyPassword12',
cPassword: 'dummyPassword12',
phone: '0362 398190022',
birthday: new Date(1939, 0, 16),
playerRole: PlayerRole.GoalKeeper,
// https://www.fakenamegenerator.com/gen-male-us-it.php
username: 'dummy2',
name: 'William2',
surname: 'J. Ayers2',
email: 'WilliamJAyers@army2.com',
cEmail: 'WilliamJAyers@army2.com',
password: 'dummyPassword12',
cPassword: 'dummyPassword12',
phone: '0362 398190022',
birthday: new Date(1939, 0, 16),
playerRole: PlayerRole.GoalKeeper,
};
5 changes: 2 additions & 3 deletions server/controller/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import {
UpdateUserRequest,
OmitGeneric,
OmitHistory,
UnsubscribeResponse,
} from '../../../src/@common/models';
import { HTTPStatusCode } from '../../../src/@common/models/HttpStatusCode';
} from '@common/models';
import { HTTPStatusCode } from '@common/models/HttpStatusCode';
import { setSession, removeSession } from './session.utils';
import { comparePasswords } from './auth.utils';

Expand Down
6 changes: 3 additions & 3 deletions server/controller/auth/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import supertest from 'supertest';
import { HTTPStatusCode } from '../../../src/@common/models/HttpStatusCode';
import { AuthenticationResponse, RegistrationRequest } from '../../../src/@common/models/auth.model';
import { HTTPStatusCode } from '@common/models/HttpStatusCode';
import { AuthenticationResponse, RegistrationRequest } from '@common/models/auth.model';
import AppServer from '../../express/AppServer';
import { TEST_USER_1 } from './__mocks__/auth.mocks';
//
import { httpServer } from '../../server';
import { OmitHistory } from '../../../src/@common/models/common.models';
import { OmitHistory } from '@common/models/common.models';
import { APPLICATION_JSON } from '../../core/constats';

describe('Authentication Endpoints', () => {
Expand Down
2 changes: 1 addition & 1 deletion server/controller/auth/auth.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Password utils
import bcrypt from 'bcryptjs';
import { UserDTO } from '../../../src/@common/dto';
import { UserDTO } from '@common/dto';
import jwt from 'jsonwebtoken';

// Password
Expand Down
4 changes: 2 additions & 2 deletions server/controller/auth/session.utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Cookies
import { UserDTO } from '../../../src/@common/dto';
import { UserDTO } from '@common/dto';
import { v5 as uuidv5 } from 'uuid';
import jwt from 'jsonwebtoken';
import 'express-session';
import { CookieOptions, Response, Request } from 'express';
import { isProductionMode } from '../../../src/@common/utils/env.utils';
import { isProductionMode } from '@common/utils/env.utils';
import { TOKEN_SECRET } from './auth.utils';
import { logger } from '../../core/logger';

Expand Down
6 changes: 3 additions & 3 deletions server/controller/common.response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Response } from 'express';
import { HTTPStatusCode } from '../../src/@common/models/HttpStatusCode';
import { GenericResponse, I18nLabel, OmitGeneric, UserMessageType } from '../../src/@common/models/common.models';
import { HTTPStatusCode } from '@common/models/HttpStatusCode';
import { GenericResponse, I18nLabel, OmitGeneric, UserMessageType } from '@common/models/common.models';
import { logger } from '../core/logger';
import chalk from 'chalk';

Expand All @@ -17,7 +17,7 @@ export const ComposeReponse = <T extends GenericResponse>(
...additionalInfo,
code: status,
message: internalMessage,
userMessage: { type, ...label },
userMessage: { type, label },
});
};

Expand Down
4 changes: 2 additions & 2 deletions server/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import statsRouter from './stats.controller';
// mddleware
import { controllerLogger } from '../middleware';
// DTO
import { HTTPStatusCode } from '../../src/@common/models/HttpStatusCode';
import { UserDTO } from '../../src/@common/dto';
import { HTTPStatusCode } from '@common/models/HttpStatusCode';
import { UserDTO } from '@common/dto';

export interface AppRequest extends Request {
user?: UserDTO;
Expand Down
2 changes: 1 addition & 1 deletion server/controller/pair.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
SavePairResponse,
SelectPairsRequest,
SelectPairsResponse,
} from '../../src/@common/models';
} from '@common/models';

const router = Router();

Expand Down
2 changes: 1 addition & 1 deletion server/controller/player.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FetchPlayersResponse,
SavePlayerRequest,
SavePlayerResponse,
} from '../../src/@common/models/player.model';
} from '@common/models/player.model';
import { withAuth, asyncMiddleware, withAdminRights } from '../middleware';
import {
create,
Expand Down
4 changes: 2 additions & 2 deletions server/controller/stage1.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
UpdateCellResponse,
UpdatePlacementRequest,
UpdatePlacementResponse,
} from '../../src/@common/models';
} from '@common/models';
import { failure, success } from './common.response';
import { TournamentProgress } from '../../src/@common/dto';
import { TournamentProgress } from '@common/dto';

const router = Router();

Expand Down
4 changes: 2 additions & 2 deletions server/controller/stage2.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
SessionStatus,
UpdateStage2CellRequest,
UpdateStage2CellResponse,
} from '../../src/@common/models';
import { TournamentProgress } from '../../src/@common/dto';
} from '@common/models';
import { TournamentProgress } from '@common/dto';

// all API path must be relative to /api/v2/stage2
const router = Router();
Expand Down
4 changes: 2 additions & 2 deletions server/controller/stats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
StatsBestPairsRequest,
StatsBestPairsResponse,
StatsSummaryResponse,
} from '../../src/@common/models/stats.model';
import { formatDate } from '../../src/@common/utils/date.utils';
} from '@common/models/stats.model';
import { formatDate } from '@common/utils/date.utils';
import { withAuth, doNotCacheThis, asyncMiddleware } from '../middleware';
import { findById } from '../manager/pair.manager';

Expand Down

0 comments on commit 4dfc061

Please sign in to comment.