Skip to content

Commit

Permalink
Merge pull request #836 from jembi/updated-tests
Browse files Browse the repository at this point in the history
Updated Jest & Create React App
  • Loading branch information
euanmillar authored Jun 17, 2019
2 parents c128faa + dc11c44 commit c7fa1a3
Show file tree
Hide file tree
Showing 557 changed files with 16,598 additions and 30,850 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ build
.secrets/*
# But, keep the .gitignore so the folder is created
!.secrets/.gitignore
.vscode
.idea
data
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"editor.formatOnSave": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
],
"typescript.updateImportsOnFileMove.enabled": "always",
"eslint.workingDirectories": [
{ "directory": "./packages/performance", "changeProcessCWD": true },
{ "directory": "./packages/register", "changeProcessCWD": true },
{ "directory": "./packages/login", "changeProcessCWD": true }
]
}
Binary file modified infrastructure/backups/hearth-dev.gz
Binary file not shown.
Binary file modified infrastructure/backups/openhim-dev.gz
Binary file not shown.
Binary file modified infrastructure/backups/user-mgnt.gz
Binary file not shown.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
}
},
"scripts": {
"postinstall": "patch-package",
"start": "lerna run build --scope @opencrvs/components && lerna run --parallel --ignore e2e --ignore @opencrvs/integration $OTHER_LERNA_FLAGS start",
"start:prod": "lerna run build --scope @opencrvs/components && lerna run --parallel --ignore e2e --ignore @opencrvs/integration $OTHER_LERNA_FLAGS start:prod",
"dev": "yarn dev:secrets:gen && concurrently \"yarn run start\" \"yarn run compose\"",
"dev:secrets:gen": "openssl genrsa -out .secrets/private-key.pem 2048 && openssl rsa -pubout -in .secrets/private-key.pem -out .secrets/public-key.pem",
"dev:tmux": "tmuxinator start",
"dev:tmux:kill": "tmux kill-session -t opencrvs",
"open": "opener 'http://localhost:6060/' && opener 'http://localhost:3020/'",
"test": "lerna run test --stream --watchAll=false",
"test": "CI=true lerna run test --silent --noStackTrace --stream --watchAll=false",
"compose": "docker-compose -p opencrvs -f docker-compose.deps.yml -f docker-compose.dev.yml up",
"compose:down": "docker-compose -p opencrvs -f docker-compose.deps.yml -f docker-compose.dev.yml down",
"compose:build": "docker-compose build",
Expand All @@ -40,6 +41,8 @@
"prettier": "^1.15.2"
},
"dependencies": {
"opener": "^1.5.1"
"opener": "^1.5.1",
"patch-package": "^6.1.2",
"postinstall-postinstall": "^2.0.0"
}
}
29 changes: 19 additions & 10 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"license": "NONE",
"private": true,
"scripts": {
"start": "cross-env NODE_ENV=DEVELOPMENT nodemon --exec ts-node -- src/index.ts",
"start:prod": "ts-node src/index.ts",
"test": "jest --coverage && yarn test:compilation",
"start": "cross-env NODE_ENV=DEVELOPMENT nodemon --exec ts-node -r tsconfig-paths/register src/index.ts",
"start:prod": "ts-node -r tsconfig-paths/register src/index.ts",
"test": "jest --silent --noStackTrace && yarn test:compilation",
"test:watch": "jest --watch",
"precommit": "lint-staged",
"precommit": "tslint --project ./tsconfig.json && lint-staged",
"generate-test-token": "NODE_PATH=. ts-node resources/generate-test-token",
"request-token": "NODE_PATH=. ts-node resources/request-token",
"test:compilation": "tsc --noEmit"
Expand All @@ -20,7 +20,7 @@
"@types/hapi": "^17.0.12",
"@types/joi": "^14.0.0",
"@types/jsonwebtoken": "^7.2.7",
"@types/node-fetch": "^2.1.2",
"@types/node-fetch": "^2.3.4",
"@types/redis": "^2.8.6",
"@types/winston": "^2.3.9",
"app-module-path": "^2.2.0",
Expand All @@ -35,23 +35,29 @@
"io-ts": "^1.2.1",
"joi": "^14.0.6",
"jsonwebtoken": "^8.3.0",
"node-fetch": "^2.2.1",
"node-fetch": "^2.6.0",
"redis": "^2.8.0",
"typescript": "^3.0.1",
"lint-staged": "^7.1.0",
"winston": "^3.0.0"
},
"devDependencies": {
"@types/command-line-args": "^5.0.0",
"@types/command-line-usage": "^5.0.1",
"@types/jest": "^24.0.13",
"command-line-args": "^5.0.2",
"command-line-usage": "^5.0.5",
"cross-env": "^5.2.0",
"jest": "23.6.0",
"jest-fetch-mock": "^1.6.5",
"jest": "24.7.1",
"jest-fetch-mock": "^2.1.2",
"nodemon": "^1.17.5",
"prettier": "^1.15.2",
"ts-jest": "^22.4.6",
"ts-node": "^6.1.1"
"redis-mock": "^0.27.0",
"ts-jest": "^24.0.2",
"ts-node": "^6.1.1",
"tsconfig-paths": "^3.8.0",
"tslint": "^5.17.0",
"tslint-microsoft-contrib": "^6.2.0"
},
"lint-staged": {
"src/**/*.{ts,graphql}": [
Expand All @@ -72,6 +78,9 @@
"modulePaths": [
"<rootDir>"
],
"moduleNameMapper": {
"@auth/(.*)": "<rootDir>/src/$1"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"setupFiles": [
"./test/setupJest.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as redis from 'redis'
import { REDIS_HOST } from './constants'
import { REDIS_HOST } from '@auth/constants'
import { promisify } from 'util'

let redisClient: redis.RedisClient
Expand Down
7 changes: 4 additions & 3 deletions packages/auth/src/features/authenticate/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as fetch from 'jest-fetch-mock'
import { createServerWithEnvironment } from 'src/tests/util'
import * as fetchAny from 'jest-fetch-mock'
import { createServerWithEnvironment } from '@auth/tests/util'
import { createServer } from '../..'
import * as codeService from 'src/features/verifyCode/service'
import * as codeService from '@auth/features/verifyCode/service'

const fetch = fetchAny as any
describe('authenticate handler receives a request', () => {
let server: any

Expand Down
11 changes: 7 additions & 4 deletions packages/auth/src/features/authenticate/handler.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import * as Hapi from 'hapi'
import * as Joi from 'joi'
import { authenticate, storeUserInformation } from './service'
import {
authenticate,
storeUserInformation
} from '@auth/features/authenticate/service'
import {
generateVerificationCode,
sendVerificationCode,
generateNonce,
storeVerificationCode
} from 'src/features/verifyCode/service'
import { logger } from 'src/logger'
} from '@auth/features/verifyCode/service'
import { logger } from '@auth/logger'
import { unauthorized } from 'boom'
import { PRODUCTION } from 'src/constants'
import { PRODUCTION } from '@auth/constants'

interface IAuthPayload {
mobile: string
Expand Down
5 changes: 4 additions & 1 deletion packages/auth/src/features/authenticate/service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { verifyToken, getStoredUserInformation } from './service'
import {
verifyToken,
getStoredUserInformation
} from '@auth/features/authenticate/service'

describe('authenticate service errors', () => {
describe('verifyToken - token expired', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/auth/src/features/authenticate/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
CERT_PRIVATE_KEY_PATH,
CERT_PUBLIC_KEY_PATH,
CONFIG_TOKEN_EXPIRY_SECONDS
} from 'src/constants'
} from '@auth/constants'
import { resolve } from 'url'
import { readFileSync } from 'fs'
import { promisify } from 'util'
import * as jwt from 'jsonwebtoken'
import { get, set } from 'src/database'
import { get, set } from '@auth/database'
import * as t from 'io-ts'
import { ThrowReporter } from 'io-ts/lib/ThrowReporter'

Expand Down Expand Up @@ -92,6 +92,7 @@ export async function getStoredUserInformation(nonce: string) {
return JSON.parse(record)
}

/* tslint:disable */
const TokenPayload = t.type({
sub: t.string,
scope: t.array(t.string),
Expand All @@ -111,3 +112,4 @@ export function verifyToken(token: string): ITokenPayload {
ThrowReporter.report(result)
return result.value as ITokenPayload
}
/* tslint:enable */
2 changes: 1 addition & 1 deletion packages/auth/src/features/invalidateToken/handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Hapi from 'hapi'
import * as Joi from 'joi'
import { internal } from 'boom'
import { invalidateToken } from './service'
import { invalidateToken } from '@auth/features/invalidateToken/service'

interface IInvalidateTokenPayload {
token: string
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/invalidateToken/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { setex } from 'src/database'
import { setex } from '@auth/database'
import {
INVALID_TOKEN_NAMESPACE,
CONFIG_TOKEN_EXPIRY_SECONDS
} from 'src/constants'
} from '@auth/constants'

export async function invalidateToken(token: string) {
return setex(
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/features/refresh/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServerWithEnvironment } from 'src/tests/util'
import { createServerWithEnvironment } from '@auth/tests/util'

describe('authenticate handler receives a request', () => {
let server: any
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/refresh/handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Hapi from 'hapi'
import * as Joi from 'joi'
import { unauthorized } from 'boom'
import { verifyToken } from 'src/features/authenticate/service'
import { refreshToken } from './service'
import { verifyToken } from '@auth/features/authenticate/service'
import { refreshToken } from '@auth/features/refresh/service'

interface IRefreshPayload {
nonce: string
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/refresh/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createToken, ITokenPayload } from '../authenticate/service'
import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from 'src/constants'
import { createToken, ITokenPayload } from '@auth/features/authenticate/service'
import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from '@auth/constants'

export async function refreshToken(payload: ITokenPayload): Promise<string> {
return createToken(
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/features/resend/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServerWithEnvironment } from 'src/tests/util'
import { createServerWithEnvironment } from '@auth/tests/util'
import { createServer } from '../..'

describe('resend handler receives a request', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/auth/src/features/resend/handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Hapi from 'hapi'
import * as Joi from 'joi'
import { unauthorized } from 'boom'
import { getStoredUserInformation } from 'src/features/authenticate/service'
import { getStoredUserInformation } from '@auth/features/authenticate/service'
import {
generateVerificationCode,
sendVerificationCode
} from 'src/features/verifyCode/service'
import { PRODUCTION } from 'src/constants'
import { logger } from 'src/logger'
} from '@auth/features/verifyCode/service'
import { PRODUCTION } from '@auth/constants'
import { logger } from '@auth/logger'

interface IRefreshPayload {
nonce: string
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/features/verifyCode/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServerWithEnvironment } from 'src/tests/util'
import { createServerWithEnvironment } from '@auth/tests/util'

describe('authenticate handler receives a request', () => {
let server: any
Expand Down
11 changes: 7 additions & 4 deletions packages/auth/src/features/verifyCode/handler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as Hapi from 'hapi'
import * as Joi from 'joi'
import { unauthorized } from 'boom'
import { checkVerificationCode, deleteUsedVerificationCode } from './service'
import {
checkVerificationCode,
deleteUsedVerificationCode
} from '@auth/features/verifyCode/service'
import {
getStoredUserInformation,
createToken
} from 'src/features/authenticate/service'
import { logger } from 'src/logger'
import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from 'src/constants'
} from '@auth/features/authenticate/service'
import { logger } from '@auth/logger'
import { WEB_USER_JWT_AUDIENCES, JWT_ISSUER } from '@auth/constants'

interface IVerifyPayload {
nonce: string
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/verifyCode/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
generateNonce,
checkVerificationCode,
deleteUsedVerificationCode
} from './service'
} from '@auth/features/verifyCode/service'

import { CONFIG_SMS_CODE_EXPIRY_SECONDS } from 'src/constants'
import { CONFIG_SMS_CODE_EXPIRY_SECONDS } from '@auth/constants'

const nonce = '12345'
const mobile = '+447111111111'
Expand Down
8 changes: 4 additions & 4 deletions packages/auth/src/features/verifyCode/service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fetch from 'node-fetch'
import { set, get, del } from 'src/database'
import { set, get, del } from '@auth/database'
import {
NOTIFICATION_SERVICE_URL,
CONFIG_SMS_CODE_EXPIRY_SECONDS,
JWT_ISSUER
} from 'src/constants'
} from '@auth/constants'
import * as crypto from 'crypto'
import { resolve } from 'url'
import { createToken } from 'src/features/authenticate/service'
import { createToken } from '@auth/features/authenticate/service'

interface ICodeDetails {
code: string
Expand All @@ -29,7 +29,7 @@ export async function generateVerificationCode(
nonce: string,
mobile: string
): Promise<SixDigitVerificationCode> {
// TODO lets come back to how these are generated
// tslint:disable-next-line
const code = Math.floor(100000 + Math.random() * 900000).toString()

await storeVerificationCode(nonce, code)
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/features/verifyToken/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Hapi from 'hapi'
import * as Joi from 'joi'
import { verifyToken } from './service'
import { verifyToken } from '@auth/features/verifyToken/service'
import { internal } from 'boom'

interface IVerifyTokenPayload {
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/features/verifyToken/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get } from 'src/database'
import { INVALID_TOKEN_NAMESPACE } from 'src/constants'
import { get } from '@auth/database'
import { INVALID_TOKEN_NAMESPACE } from '@auth/constants'

export async function verifyToken(token: string) {
const record = await get(`${INVALID_TOKEN_NAMESPACE}:${token}`)
Expand Down
Loading

0 comments on commit c7fa1a3

Please sign in to comment.