From 809885dbd23418e0be3b4ba461ca6f68dd4f49e8 Mon Sep 17 00:00:00 2001 From: Fortune Ochi Date: Mon, 14 Oct 2019 07:38:50 +0100 Subject: [PATCH] Updated package.json (#2)(#66) * Updated BaseEntity navigation properties to reference User type * Used auto mapper's array mapper for mapping array to DTO * Removed vscode local settings from version control * Updated createdBy field in user entity * Added user auto mapper profile * Added user auto mapper profile * Updated package.json and set tenant and user globally. Closes #16, closes #17 * Implement save or update feature. Closes #11 * Moved hooks to base entity class and implemented soft-delete * Implement soft delete feature. Closes #56 * Fixed #63, and refactor some part of test files (#14) * A sample swagger integration/implementation (#2) * A sample swagger integration/implementation (#2) * Fix breaking change * Implement auto swagger generation * Sample swagger doc integration/implementation #2 #66 * Refactoring * Updated NPM package and refactor test --- package-lock.json | 62 +++++++++++++++++-- package.json | 9 +-- src/infrastructure/bootstrapping/index.ts | 1 - src/infrastructure/config/swagger.config.ts | 6 +- .../db/repository/tenant_repository.test.ts | 21 ++++--- 5 files changed, 79 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5e05381..5fc8ff6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -790,9 +790,9 @@ "dev": true }, "automapper-nartc": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/automapper-nartc/-/automapper-nartc-3.1.2.tgz", - "integrity": "sha512-zJhG8UFyuREAHi1fIb1tjLVCPbiFpde2jY8NZErvAgTzE79ggL/LY4Q9h0RJ04BZiV+SEAO58Bt0lb5X3LGGGg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/automapper-nartc/-/automapper-nartc-4.0.0.tgz", + "integrity": "sha512-ZlRuP32ZhAgzMed8xAWo/QNB3cR04QWisXVVjGaFceMcxEK3gAdp+YtlgfnwWcTlsRZbDmXfn5mlqH98zBWF2A==", "requires": { "class-transformer": "0.2.3", "lodash.get": "4.4.2", @@ -4965,6 +4965,15 @@ "ms": "^2.1.1" } }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -5994,6 +6003,16 @@ "rimraf": "^2.6.1", "semver": "^5.3.0", "tar": "^4" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "requires": { + "glob": "^7.1.3" + } + } } }, "nodemon": { @@ -6129,6 +6148,15 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true + }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } } } }, @@ -6939,9 +6967,9 @@ "dev": true }, "rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz", + "integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==", "requires": { "glob": "^7.1.3" } @@ -7417,6 +7445,17 @@ "rimraf": "^2.6.2", "signal-exit": "^3.0.2", "which": "^1.3.0" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, "spdx-correct": { @@ -7782,6 +7821,17 @@ "dev": true, "requires": { "rimraf": "^2.6.3" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, "to-buffer": { diff --git a/package.json b/package.json index 0e3341f..53593b4 100644 --- a/package.json +++ b/package.json @@ -39,13 +39,13 @@ "no-build": "npx ts-node src/index.ts", "non-build:start": "npx ts-code src/index.ts", "nyc": "nyc npm run test", - "rm-files": "rm -r -f coverage .nyc_output dist", - "start": "npm run rm-files && npm run tsc && npm run start-node", + "clean": "rimraf coverage .nyc_output dist", + "start": "npm run clean && npm run tsc && npm run start-node", "dev": "nodemon -e ts --exec \"npx ts-node -r tsconfig-paths/register -T --pretty --project tsconfig.json src/index.ts\"", "start-node": "node dist/src/index.js", "test": "ts-mocha --paths", "test-watch": "nodemon -e ts --exec \"ts-mocha --paths\"", - "test-cover": "npm run rm-files && npm run nyc", + "test-cover": "npm run clean && npm run nyc", "tsc": "tsc -p tsconfig.json", "lint": "eslint \"**/*.ts\"", "build": "npm run lint && npm run tsc", @@ -55,7 +55,7 @@ "@hapi/joi": "^16.1.7", "@hasezoey/typegoose": "^5.9.2", "agenda": "^2.1.0", - "automapper-nartc": "^3.1.2", + "automapper-nartc": "^4.0.0", "bcrypt": "^3.0.6", "body-parser": "^1.19.0", "class-transformer": "^0.2.3", @@ -76,6 +76,7 @@ "method-override": "^3.0.0", "mongoose": "^5.7.4", "reflect-metadata": "^0.1.13", + "rimraf": "^3.0.0", "swagger-ui-express": "^4.1.2", "tsconfig-paths": "^3.9.0", "tsoa": "^2.5.6", diff --git a/src/infrastructure/bootstrapping/index.ts b/src/infrastructure/bootstrapping/index.ts index 30990a5..aefdd19 100644 --- a/src/infrastructure/bootstrapping/index.ts +++ b/src/infrastructure/bootstrapping/index.ts @@ -3,7 +3,6 @@ import { Container, ContainerModule, decorate, injectable } from "inversify"; import { buildProviderModule } from "inversify-binding-decorators"; import { InversifyExpressServer } from "inversify-express-utils"; import swaggerUi from "swagger-ui-express"; - import { Controller } from "tsoa"; import swaggerJsonDoc from "../../../swagger.json"; import { TYPES } from "../../domain/constants/types"; diff --git a/src/infrastructure/config/swagger.config.ts b/src/infrastructure/config/swagger.config.ts index e42794d..67df067 100644 --- a/src/infrastructure/config/swagger.config.ts +++ b/src/infrastructure/config/swagger.config.ts @@ -9,6 +9,10 @@ import { X_TENANT_ID } from "../../ui/constants/header_constants"; const basePath = config.api.prefix; const entryFile = "./src/index.ts"; +const protocol = + process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" + ? "http" + : "https"; export const swaggerGen = async () => { const swaggerOptions: SwaggerConfig = { basePath, @@ -31,7 +35,7 @@ export const swaggerGen = async () => { version: "1.0.0", name: "node-typescript-boilerplate", specVersion: 3, - schemes: ["http", "https"], + schemes: [protocol], tags: [ { name: "Foos", diff --git a/test/infrastructure/db/repository/tenant_repository.test.ts b/test/infrastructure/db/repository/tenant_repository.test.ts index f16152e..1f47bd4 100644 --- a/test/infrastructure/db/repository/tenant_repository.test.ts +++ b/test/infrastructure/db/repository/tenant_repository.test.ts @@ -49,14 +49,19 @@ describe("Tenant Repository", () => { username: "admin" }; }); - it("should create user using the foo endpoint", async () => { - const tenant = await tenantRepository.findOneByQuery({ name: "T2" }); - const { body } = await req - .post(`${endpoint}/auth/signUp`) - .send(signUpInput) - .set(X_TENANT_ID, tenant.id) - .expect(httpStatus.OK); - userDto = body.userDto; + it("should create user using the foo endpoint", done => { + tenantRepository + .findOneByQuery({ name: "T2" }) + .then(async tenant => { + const { body } = await req + .post(`${endpoint}/auth/signUp`) + .send(signUpInput) + .set(X_TENANT_ID, tenant.id) + .expect(httpStatus.OK); + userDto = body.userDto; + done(); + }) + .catch(done); }); it("should get all the tenants but without the deleted ones", async () => {