Skip to content

Commit

Permalink
feat(tests): support github actions
Browse files Browse the repository at this point in the history
revised test to fix NODE_ENV production bug and added ci testing

fix #3
  • Loading branch information
Manny authored and Manny committed Jul 10, 2020
1 parent 1395e58 commit fdeaa1b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ build
dist
*.log
coverage
prisma/migrations/*.lock
prisma/migrations/*.lock
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
"scripts": {
"commit": "npx git-cz",
"build": "tsc",
"dev": "ts-node-dev src/server.ts",
"start": "export NODE_ENV=production && tsc && node build/server.js",
"dev": "export ts-node-dev src/server.ts",
"start": "tsc && export NODE_ENV=production && node build/server.js",
"newman:run": "./node_modules/.bin/newman run postman/NodeTS-REST-Auth-Bootstrap.postman_collection.json -e postman/NodeTS-Local-ENV-VARS.postman_environment.json",
"test": "yarn test:lint; yarn test:coverage; yarn test:newman;",
"test:newman": "./node_modules/.bin/ts-node-dev prisma/commands/UsersDelete.ts --delete; yarn db:seed:all; start-server-and-test dev http://localhost:5000 newman:run;",
"test:dev": "yarn test:lint; yarn test:coverage; yarn test:newman:dev;",
"test:newman": "./node_modules/.bin/ts-node-dev prisma/commands/UsersDelete.ts --delete; yarn db:seed:all; start-server-and-test start http://localhost:5000 newman:run;",
"test:newman:dev": "./node_modules/.bin/ts-node-dev prisma/commands/UsersDelete.ts --delete; yarn db:seed:all; start-server-and-test dev http://localhost:5000 newman:run;",
"test:jest": "./node_modules/.bin/jest --watch src",
"test:coverage": "./node_modules/.bin/jest --coverage src",
"test:lint": "./node_modules/.bin/eslint '*/**/*.{js,ts}' --quiet --fix",
Expand Down Expand Up @@ -57,6 +59,7 @@
"@types/cors": "^2.8.6",
"@types/csurf": "^1.9.36",
"@types/express": "^4.17.6",
"@types/express-session": "^1.17.0",
"@types/faker": "^4.1.12",
"@types/helmet": "^0.0.47",
"@types/http-errors": "^1.6.3",
Expand Down
4 changes: 2 additions & 2 deletions prisma/seedings/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Imports
// ========================================================
import { PrismaClient } from '@prisma/client';
import { getGeneratedToken, createResetToken } from '../../src/utils';
import { getGeneratedToken } from '../../src/utils';
import faker from 'faker';

// Seeds
Expand Down Expand Up @@ -35,7 +35,7 @@ async function seedAll(): Promise<void> {
});

// RESET TOKEN account
const resetTokeAccount = await UserSeed({
await UserSeed({
id: 'cfb09a6e-463d-48d4-bdbb-d0430b4e544f',
email: 'reset@account.com',
first_name: faker.fake('{{name.firstName}}'),
Expand Down
4 changes: 0 additions & 4 deletions src/controllers/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ router.post(
res.cookie('token', token, {
httpOnly: true,
maxAge: parseInt(process.env.JWT_MAX_AGE || '900') * 1000,
// domain: '.app.local',
path: '/',
secure: process.env.NODE_ENV === 'production' ? true : false,
});

// 6. Set refresh token cookie
res.cookie('refreshToken', refreshToken, {
httpOnly: true,
maxAge: parseInt(process.env.JWT_REFRESH_MAX_AGE || '604800') * 1000,
// domain: '.app.local',
path: '/',
secure: process.env.NODE_ENV === 'production' ? true : false,
});

// 7. Send token data
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ app.use(
cookie: {
key: process.env.CSRF_COOKIE_PREFIX || '_csrf',
maxAge: parseInt(process.env.CSRF_COOKIE_MAXAGE || '900'),
signed: NODE_ENV === 'production' ? true : false, // signature
secure: NODE_ENV === 'production' ? true : false, // https
httpOnly: true,
sameSite: NODE_ENV === 'production' ? true : false, // sets the same site policy for the cookie
sameSite: false,
},
}),
);
Expand Down

0 comments on commit fdeaa1b

Please sign in to comment.