From 5bbe196ee18068a70bcbf62b60469297f349b64b Mon Sep 17 00:00:00 2001 From: zelzhan Date: Mon, 24 Aug 2020 19:20:14 +0600 Subject: [PATCH 01/15] WIP: report controller file handler --- angular.json | 29 +++++++ apps/api/src/app/app.module.ts | 11 ++- libs/api-implementation/report/README.md | 7 ++ libs/api-implementation/report/jest.config.js | 10 +++ libs/api-implementation/report/src/index.ts | 1 + .../lib/api-implementation-report.module.ts | 12 +++ .../report/src/lib/report.controller.ts | 22 +++++ libs/api-implementation/report/tsconfig.json | 8 ++ .../report/tsconfig.lib.json | 12 +++ .../report/tsconfig.spec.json | 15 ++++ libs/api-implementation/report/tslint.json | 5 ++ nx.json | 3 + package-lock.json | 85 +++++++++++++++++++ package.json | 2 + tsconfig.json | 3 + 15 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 libs/api-implementation/report/README.md create mode 100644 libs/api-implementation/report/jest.config.js create mode 100644 libs/api-implementation/report/src/index.ts create mode 100644 libs/api-implementation/report/src/lib/api-implementation-report.module.ts create mode 100644 libs/api-implementation/report/src/lib/report.controller.ts create mode 100644 libs/api-implementation/report/tsconfig.json create mode 100644 libs/api-implementation/report/tsconfig.lib.json create mode 100644 libs/api-implementation/report/tsconfig.spec.json create mode 100644 libs/api-implementation/report/tslint.json diff --git a/angular.json b/angular.json index a04f750..abe0ee0 100644 --- a/angular.json +++ b/angular.json @@ -530,6 +530,35 @@ "style": "scss" } } + }, + "api-implementation-report": { + "root": "libs/api-implementation/report", + "sourceRoot": "libs/api-implementation/report/src", + "projectType": "library", + "schematics": {}, + "architect": { + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "libs/api-implementation/report/tsconfig.lib.json", + "libs/api-implementation/report/tsconfig.spec.json" + ], + "exclude": [ + "**/node_modules/**", + "!libs/api-implementation/report/**" + ] + } + }, + "test": { + "builder": "@nrwl/jest:jest", + "options": { + "jestConfig": "libs/api-implementation/report/jest.config.js", + "tsConfig": "libs/api-implementation/report/tsconfig.spec.json", + "passWithNoTests": true + } + } + } } }, "cli": { diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 06638e6..b661a4e 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -1,14 +1,19 @@ -import { Module } from '@nestjs/common'; +import { Module, HttpModule } from '@nestjs/common'; import { AppController } from './app.controller'; +//TODO: fix the naming so that prefix import will work import { VMOrchestrationModule } from '../../../../libs/api-implementation/orchestration/src'; import { ApiImplementationRegressionTestsModule } from '@new-sample-platform/api-implementation/regression-tests'; import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; import { ApiImplementationSamplesModule } from '@new-sample-platform/api-implementation/samples' +import { ApiImplementationReportModule } from '@new-sample-platform/api-implementation/report' +import { HttpAdapterHost } from '@nestjs/core'; @Module({ imports: [ + HttpAdapterHost, VMOrchestrationModule, + ApiImplementationReportModule, ApiImplementationRegressionTestsModule, ApiImplementationDatabaseModule, ApiImplementationSamplesModule @@ -16,4 +21,6 @@ import { ApiImplementationSamplesModule } from '@new-sample-platform/api-impleme controllers: [AppController], providers: [], }) -export class AppModule {} +export class AppModule { +} + diff --git a/libs/api-implementation/report/README.md b/libs/api-implementation/report/README.md new file mode 100644 index 0000000..59bcfea --- /dev/null +++ b/libs/api-implementation/report/README.md @@ -0,0 +1,7 @@ +# api-implementation-report + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `ng test api-implementation-report` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/api-implementation/report/jest.config.js b/libs/api-implementation/report/jest.config.js new file mode 100644 index 0000000..90b2f0e --- /dev/null +++ b/libs/api-implementation/report/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + name: 'api-implementation-report', + preset: '../../../jest.config.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]sx?$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], + coverageDirectory: '../../../coverage/libs/api-implementation/report', +}; diff --git a/libs/api-implementation/report/src/index.ts b/libs/api-implementation/report/src/index.ts new file mode 100644 index 0000000..cffb105 --- /dev/null +++ b/libs/api-implementation/report/src/index.ts @@ -0,0 +1 @@ +export * from './lib/api-implementation-report.module'; diff --git a/libs/api-implementation/report/src/lib/api-implementation-report.module.ts b/libs/api-implementation/report/src/lib/api-implementation-report.module.ts new file mode 100644 index 0000000..154c506 --- /dev/null +++ b/libs/api-implementation/report/src/lib/api-implementation-report.module.ts @@ -0,0 +1,12 @@ +import { Module, HttpModule } from '@nestjs/common'; +import { ReportController } from './report.controller'; + +import { HttpAdapterHost } from '@nestjs/core'; + +@Module({ + imports: [HttpAdapterHost], + controllers: [ReportController], + providers: [], + exports: [], +}) +export class ApiImplementationReportModule {} diff --git a/libs/api-implementation/report/src/lib/report.controller.ts b/libs/api-implementation/report/src/lib/report.controller.ts new file mode 100644 index 0000000..e449ef1 --- /dev/null +++ b/libs/api-implementation/report/src/lib/report.controller.ts @@ -0,0 +1,22 @@ +import { + Controller, + Post, + UseInterceptors, + UploadedFiles, +} from '@nestjs/common'; + +import { + FilesInterceptor, +} from '@nestjs/platform-express'; + +@Controller('report') +export class ReportController { + constructor() { } + + @Post() + @UseInterceptors(FilesInterceptor('files')) + async processReport(@UploadedFiles() files) { + console.log(files) + } +} + diff --git a/libs/api-implementation/report/tsconfig.json b/libs/api-implementation/report/tsconfig.json new file mode 100644 index 0000000..e65708f --- /dev/null +++ b/libs/api-implementation/report/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"], + "target": "es6" + }, + "include": ["**/*.ts"] +} diff --git a/libs/api-implementation/report/tsconfig.lib.json b/libs/api-implementation/report/tsconfig.lib.json new file mode 100644 index 0000000..9c463b5 --- /dev/null +++ b/libs/api-implementation/report/tsconfig.lib.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../../dist/out-tsc", + "declaration": true, + "rootDir": "./src", + "types": ["node"] + }, + "exclude": ["**/*.spec.ts"], + "include": ["**/*.ts"] +} diff --git a/libs/api-implementation/report/tsconfig.spec.json b/libs/api-implementation/report/tsconfig.spec.json new file mode 100644 index 0000000..1798b37 --- /dev/null +++ b/libs/api-implementation/report/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts" + ] +} diff --git a/libs/api-implementation/report/tslint.json b/libs/api-implementation/report/tslint.json new file mode 100644 index 0000000..2cdd298 --- /dev/null +++ b/libs/api-implementation/report/tslint.json @@ -0,0 +1,5 @@ +{ + "extends": "../../../tslint.json", + "linterOptions": { "exclude": ["!**/*"] }, + "rules": {} +} diff --git a/nx.json b/nx.json index 63a5b94..96356d9 100644 --- a/nx.json +++ b/nx.json @@ -67,6 +67,9 @@ }, "frontend-samples": { "tags": [] + }, + "api-implementation-report": { + "tags": [] } } } diff --git a/package-lock.json b/package-lock.json index 44780d8..f90228c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6465,6 +6465,18 @@ "integrity": "sha512-e54B99q/OUoH64zYYRf3HBP5z24G38h5D3qXu23JGRoigpX5Ss4r9ZnDk3g0Z8uQC2x2lPaJ+UlWBc1ZWBWdLg==", "dev": true }, + "connect-multiparty": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/connect-multiparty/-/connect-multiparty-2.2.0.tgz", + "integrity": "sha512-zKcpA7cuXGEhuw9Pz7JmVCFmp85jzGLGm/iiagXTwyEAJp4ypLPtRS/V4IGuGb9KjjrgHBs6P/gDCpZHnFzksA==", + "requires": { + "http-errors": "~1.7.0", + "multiparty": "~4.2.1", + "on-finished": "~2.3.0", + "qs": "~6.5.2", + "type-is": "~1.6.16" + } + }, "consola": { "version": "2.12.2", "resolved": "https://registry.npmjs.org/consola/-/consola-2.12.2.tgz", @@ -8359,6 +8371,32 @@ } } }, + "express-fileupload": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.2.0.tgz", + "integrity": "sha512-oe4WpKcSppXnl5peornawWUa6tKmIc1/kJxMNRGJR1A0v4zyLL6VsFR6wZ8P2a4Iq3aGx8xae3Vlr+MOMQhFPw==", + "requires": { + "busboy": "^0.3.1" + }, + "dependencies": { + "busboy": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz", + "integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==", + "requires": { + "dicer": "0.3.0" + } + }, + "dicer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz", + "integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==", + "requires": { + "streamsearch": "0.1.2" + } + } + } + }, "ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", @@ -12591,6 +12629,40 @@ "integrity": "sha1-iZ8R2WhuXgXLkbNdXw5jt3PPyQE=", "dev": true }, + "multiparty": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/multiparty/-/multiparty-4.2.2.tgz", + "integrity": "sha512-NtZLjlvsjcoGrzojtwQwn/Tm90aWJ6XXtPppYF4WmOk/6ncdwMMKggFY2NlRRN9yiCEIVxpOfPWahVEG2HAG8Q==", + "requires": { + "http-errors": "~1.8.0", + "safe-buffer": "5.2.1", + "uid-safe": "2.1.5" + }, + "dependencies": { + "http-errors": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.0.tgz", + "integrity": "sha512-4I8r0C5JDhT5VkvI47QktDW75rNlGVsUf/8hzjCC/wkWI/jdTRmBb9aI7erSG82r1bjKY3F6k28WnsVxB1C73A==", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + } + } + }, "mute-stream": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", @@ -14501,6 +14573,11 @@ "integrity": "sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ==", "dev": true }, + "random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs=" + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -17171,6 +17248,14 @@ "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", "dev": true }, + "uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==", + "requires": { + "random-bytes": "~1.0.0" + } + }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", diff --git a/package.json b/package.json index a2b2332..abe1f94 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,10 @@ "@nrwl/angular": "9.3.0", "@octokit/auth-app": "^2.4.7", "bootstrap": "^4.4.0", + "connect-multiparty": "^2.2.0", "core-js": "^2.5.4", "doasync": "^2.0.1", + "express-fileupload": "^1.2.0", "formidable": "^1.2.2", "mongodb": "^3.5.8", "mongoose": "^5.9.26", diff --git a/tsconfig.json b/tsconfig.json index 36428ce..b3bee6e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -43,6 +43,9 @@ ], "@new-sample-platform/frontend/samples": [ "libs/frontend/samples/src/index.ts" + ], + "@new-sample-platform/api-implementation/report": [ + "libs/api-implementation/report/src/index.ts" ] } }, From de0807dd527ffb1cc46351b9b23acaf2bcd10bda Mon Sep 17 00:00:00 2001 From: zelzhan Date: Tue, 25 Aug 2020 10:56:33 +0600 Subject: [PATCH 02/15] feat(api): added mongoose models for the test entry --- .../regression-tests/test-entry.model.ts | 7 ++++ .../regression-tests/test-entry.schema.ts | 40 +++++++++++++++++++ .../regression-tests/test-entry.types.ts | 12 ++++++ .../report/src/lib/report.controller.ts | 9 +++-- 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 libs/api-implementation/models/regression-tests/test-entry.model.ts create mode 100644 libs/api-implementation/models/regression-tests/test-entry.schema.ts create mode 100644 libs/api-implementation/models/regression-tests/test-entry.types.ts diff --git a/libs/api-implementation/models/regression-tests/test-entry.model.ts b/libs/api-implementation/models/regression-tests/test-entry.model.ts new file mode 100644 index 0000000..0c348bf --- /dev/null +++ b/libs/api-implementation/models/regression-tests/test-entry.model.ts @@ -0,0 +1,7 @@ +import { model } from 'mongoose'; +import { ITestEntryDocument } from './test-entry.types'; +import TestEntrySchema from './test-entry.schema'; +export const TestEntryModel: model = model( + 'test-entry', + TestEntrySchema +); diff --git a/libs/api-implementation/models/regression-tests/test-entry.schema.ts b/libs/api-implementation/models/regression-tests/test-entry.schema.ts new file mode 100644 index 0000000..07018fd --- /dev/null +++ b/libs/api-implementation/models/regression-tests/test-entry.schema.ts @@ -0,0 +1,40 @@ +import { Schema } from 'mongoose'; + +const TestEntrySchema = new Schema({ + category: { + type: String, + enum: [ + 'broken', + 'cea-708', + 'dvb', + 'dvd', + 'dvr-ms', + 'general', + 'hauppage', + 'mp4', + 'nocc', + 'options', + 'teletext', + 'wtv', + 'xds', + ], + required: true, + }, + correctFiles: { + type: [Buffer], + required: true, + }, + command: { + type: String, + required: true, + }, + dateOfEntry: { + type: Date, + default: new Date(), + }, + lastUpdated: { + type: Date, + default: new Date(), + }, +}); +export default TestEntrySchema; diff --git a/libs/api-implementation/models/regression-tests/test-entry.types.ts b/libs/api-implementation/models/regression-tests/test-entry.types.ts new file mode 100644 index 0000000..366e7fe --- /dev/null +++ b/libs/api-implementation/models/regression-tests/test-entry.types.ts @@ -0,0 +1,12 @@ +import { Document, Model } from "mongoose"; + +export interface ITestEntry { + category: string; + correctFiles: Buffer[]; + command: string; + dateOfEntry?: Date; + lastUpdated?: Date; +} + +export interface ITestEntryDocument extends ITestEntry, Document {} +export interface ITestEntryModel extends Model {} \ No newline at end of file diff --git a/libs/api-implementation/report/src/lib/report.controller.ts b/libs/api-implementation/report/src/lib/report.controller.ts index e449ef1..1866621 100644 --- a/libs/api-implementation/report/src/lib/report.controller.ts +++ b/libs/api-implementation/report/src/lib/report.controller.ts @@ -3,10 +3,11 @@ import { Post, UseInterceptors, UploadedFiles, + Body, } from '@nestjs/common'; import { - FilesInterceptor, + FilesInterceptor, AnyFilesInterceptor, } from '@nestjs/platform-express'; @Controller('report') @@ -14,9 +15,9 @@ export class ReportController { constructor() { } @Post() - @UseInterceptors(FilesInterceptor('files')) - async processReport(@UploadedFiles() files) { - console.log(files) + @UseInterceptors(AnyFilesInterceptor()) + async processReport(@UploadedFiles() files, @Body() body) { + console.log(files, body) } } From d9a1cb48279c2e22437b2d19bae165ccacbceee8 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Tue, 25 Aug 2020 11:54:51 +0600 Subject: [PATCH 03/15] feat(api): added controller to handle the test entry --- angular.json | 29 +++++++++++++++++ ccextractor-277307-b36fffc9a6cb.json | 12 +++++++ ...st-entry.model.ts => test-entry.models.ts} | 0 .../report/src/lib/report.controller.ts | 9 ++---- libs/api-implementation/test-entry/README.md | 7 ++++ .../test-entry/jest.config.js | 10 ++++++ .../test-entry/src/index.ts | 1 + .../api-implementation-test-entry.module.ts | 12 +++++++ .../test-entry/src/lib/dto/test-entry.dto.ts | 4 +++ .../src/lib/services/test-entry.service.ts | 24 ++++++++++++++ .../src/lib/test-entry.controller.ts | 32 +++++++++++++++++++ .../test-entry/tsconfig.json | 8 +++++ .../test-entry/tsconfig.lib.json | 12 +++++++ .../test-entry/tsconfig.spec.json | 15 +++++++++ .../api-implementation/test-entry/tslint.json | 5 +++ nx.json | 3 ++ tsconfig.json | 3 ++ 17 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 ccextractor-277307-b36fffc9a6cb.json rename libs/api-implementation/models/regression-tests/{test-entry.model.ts => test-entry.models.ts} (100%) create mode 100644 libs/api-implementation/test-entry/README.md create mode 100644 libs/api-implementation/test-entry/jest.config.js create mode 100644 libs/api-implementation/test-entry/src/index.ts create mode 100644 libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts create mode 100644 libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts create mode 100644 libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts create mode 100644 libs/api-implementation/test-entry/src/lib/test-entry.controller.ts create mode 100644 libs/api-implementation/test-entry/tsconfig.json create mode 100644 libs/api-implementation/test-entry/tsconfig.lib.json create mode 100644 libs/api-implementation/test-entry/tsconfig.spec.json create mode 100644 libs/api-implementation/test-entry/tslint.json diff --git a/angular.json b/angular.json index abe0ee0..855ebe0 100644 --- a/angular.json +++ b/angular.json @@ -559,6 +559,35 @@ } } } + }, + "api-implementation-test-entry": { + "root": "libs/api-implementation/test-entry", + "sourceRoot": "libs/api-implementation/test-entry/src", + "projectType": "library", + "schematics": {}, + "architect": { + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "libs/api-implementation/test-entry/tsconfig.lib.json", + "libs/api-implementation/test-entry/tsconfig.spec.json" + ], + "exclude": [ + "**/node_modules/**", + "!libs/api-implementation/test-entry/**" + ] + } + }, + "test": { + "builder": "@nrwl/jest:jest", + "options": { + "jestConfig": "libs/api-implementation/test-entry/jest.config.js", + "tsConfig": "libs/api-implementation/test-entry/tsconfig.spec.json", + "passWithNoTests": true + } + } + } } }, "cli": { diff --git a/ccextractor-277307-b36fffc9a6cb.json b/ccextractor-277307-b36fffc9a6cb.json new file mode 100644 index 0000000..b49a3f7 --- /dev/null +++ b/ccextractor-277307-b36fffc9a6cb.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "ccextractor-277307", + "private_key_id": "b36fffc9a6cb067f369c5330e644fda3bde953cc", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC6C56o0AmMk+We\nJyWNWLpM5cHK9JDnP9hefbqnBF4hwnCawMG4bxVCo/fgYPvRDcyAZ9CeMVlIdMOE\nXT0H3fy52A5h8R4Ysiq/m6dIRnnEW0HbtnZvjgR0wnmqlxhpsMuQGWea0arcHjWd\nWcVLjDD+3xpZndf9VjwKSqcRgMMv5KPC51ClKVJoibE1I1NDi5EZ/WziPsY5quwi\n4pQMDIuY06Mn5lvuDLwcOFWqDBPSJBFYlUUXn7ekMjDhCv1O91Y+W8OXzFoNiwkb\nE4AX65y3JHYVauoeONgUy8GeZ47fyN+D75xhpgR4XqzuazDSxDCT+0alHulW7JZb\n0wYvCzuDAgMBAAECggEAEu/i2Z5kvRqYHpsvzy2PDQu9SETQ87uZG7PNiiQ/gU0y\n5rWkd6Wq8tUQ1+ssm/tnwPw64myggL0N4mJr4hSeSGZtvwTALQBZqeuUlp6XKhL7\nPFDcHlUaLq5VnF/JMYeNjjXfyK+l0MZXFmn6/fUfpERzq1fjPTCyvNNwzQR1Gbc4\nlxL4gSF2CpOafchECNesP0TU51aGbTONIileuwOU5ZpGrs6M9/n/twY7bQ/mW4kw\nGCSbX1UnxzvkrMeIoL60dEzF+JQCS9OSmmEcIejICMJIZcc2fEqYfJNzO0LFGGLx\nCLKc8k6QeOh70F5UeSBTdqG9AAoICPcS/2e9lWC93QKBgQD1tHUHIk8iilOCd6Qx\n6CK3b4JuzRvNesnRreaFlieoNKne+S12kdOV8lVtUDMnrQll1nouA6RU7vvZ6civ\nmfyimOZStQRHA0TEaqPEG0ZGPrzwNXxyTh+wBf2YfMfOMpqmPSpxVpwxxJVGNu18\n84EB0mOGCtetnRd1WCKKYHL2rwKBgQDB1zo3fwDTNSqIaQB/GWAsgLfJSjNZGwIY\nB/bv+0vcZLM+bRZMih2lMzuihv2ZptoL0BwyMWpR6oxgNtiwneiweUXYJGlkjPtZ\nJuA4afuAID4VaVbIeQN55P2dFTCtxTI2JLma4v4Z7D71J68mWXWZULO16sVO9xh8\nl9mcP9e9bQKBgGFPy1m7+OORLWnqwJkTe0xzWZFQosZK70ugOECIK8Sutuicf6kK\nMGaex763mMsJ+ULgIxu+TYNl81FnChiiQDCVpgLztnH5lW7FXX753mdLycDJLjSH\nRH2OodWW9ftwh1d3uiuRReNgHE7mykBGoL17+fbIrIsSQIw1D9kGQgH5AoGAGupT\nvxj3eFxNh5ts4jkXzZYh7uVKs/i4FbYlZ7UxF200JlrnWcFj1GiEw1CTLh6o8DL5\nd069QJqc209CT2Pdx4NPW2/S4o9g50QqpiqxLV1MwZRa5INJJEfTn1gt5jMXgcUf\nsI4MUnUnWMsl2uFZHuzBx2TN+OT+lW5QXQ3QWxECgYAtaUQZZCQI4MbmyutDUp4i\ni/ZM22hsgNbBJ74y5EdOjm3JPoDJDDE6u04Uujyi+5Ki2rtxtgg96ZouHIv1pLaq\n3/i2bT+33enxXfDHXnvY2btNQ9xQRXBKFUl+o/A4dtVSJSkizEpR5dTXb+ePV2cp\njjJq46h1bas64uWzhwB+3Q==\n-----END PRIVATE KEY-----\n", + "client_email": "elzhan-service@ccextractor-277307.iam.gserviceaccount.com", + "client_id": "107305404303111498344", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/elzhan-service%40ccextractor-277307.iam.gserviceaccount.com" +} diff --git a/libs/api-implementation/models/regression-tests/test-entry.model.ts b/libs/api-implementation/models/regression-tests/test-entry.models.ts similarity index 100% rename from libs/api-implementation/models/regression-tests/test-entry.model.ts rename to libs/api-implementation/models/regression-tests/test-entry.models.ts diff --git a/libs/api-implementation/report/src/lib/report.controller.ts b/libs/api-implementation/report/src/lib/report.controller.ts index 1866621..5268efe 100644 --- a/libs/api-implementation/report/src/lib/report.controller.ts +++ b/libs/api-implementation/report/src/lib/report.controller.ts @@ -6,18 +6,15 @@ import { Body, } from '@nestjs/common'; -import { - FilesInterceptor, AnyFilesInterceptor, -} from '@nestjs/platform-express'; +import { AnyFilesInterceptor } from '@nestjs/platform-express'; @Controller('report') export class ReportController { - constructor() { } + constructor() {} @Post() @UseInterceptors(AnyFilesInterceptor()) async processReport(@UploadedFiles() files, @Body() body) { - console.log(files, body) + console.log(files, body); } } - diff --git a/libs/api-implementation/test-entry/README.md b/libs/api-implementation/test-entry/README.md new file mode 100644 index 0000000..67a6a47 --- /dev/null +++ b/libs/api-implementation/test-entry/README.md @@ -0,0 +1,7 @@ +# api-implementation-test-entry + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `ng test api-implementation-test-entry` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/api-implementation/test-entry/jest.config.js b/libs/api-implementation/test-entry/jest.config.js new file mode 100644 index 0000000..dcf318c --- /dev/null +++ b/libs/api-implementation/test-entry/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + name: 'api-implementation-test-entry', + preset: '../../../jest.config.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]sx?$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], + coverageDirectory: '../../../coverage/libs/api-implementation/test-entry', +}; diff --git a/libs/api-implementation/test-entry/src/index.ts b/libs/api-implementation/test-entry/src/index.ts new file mode 100644 index 0000000..d57d3fe --- /dev/null +++ b/libs/api-implementation/test-entry/src/index.ts @@ -0,0 +1 @@ +export * from './lib/api-implementation-test-entry.module'; diff --git a/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts b/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts new file mode 100644 index 0000000..688a5ce --- /dev/null +++ b/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; +import { TestEntryController } from './test-entry.controller'; +import { TestEntryService } from './services/test-entry.service'; + +@Module({ + imports: [ApiImplementationDatabaseModule], + controllers: [TestEntryController], + providers: [TestEntryService], + exports: [], +}) +export class ApiImplementationTestEntryModule {} diff --git a/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts b/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts new file mode 100644 index 0000000..c577bc9 --- /dev/null +++ b/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts @@ -0,0 +1,4 @@ +export class TestEntryDTO { + category: string; + command: string; +} diff --git a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts new file mode 100644 index 0000000..e3f5aa7 --- /dev/null +++ b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@nestjs/common'; +import { TestEntryModel } from '../../../../models/regression-tests/test-entry.models'; + +@Injectable() +export class TestEntryService { + async getAll() { + return await TestEntryModel.find({}); + } + + async create(category: string, new_command: string, files: Buffer[]) { + try { + return await TestEntryModel.create({ + command: new_command, + category: category, + correctFiles: files, + }); + } catch (error) { + console.error('Error while creating the test entry'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + throw error; + } + } +} diff --git a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts new file mode 100644 index 0000000..c768b2b --- /dev/null +++ b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts @@ -0,0 +1,32 @@ +import { Controller, Post, Body, Get, UseInterceptors, UploadedFiles } from '@nestjs/common'; +import { TestEntryDTO } from './dto/test-entry.dto'; +import { TestEntryService } from './services/test-entry.service'; +import { AnyFilesInterceptor } from '@nestjs/platform-express'; + +@Controller('test-entry') +export class TestEntryController { + constructor(private service: TestEntryService) {} + + @UseInterceptors(AnyFilesInterceptor()) + @Post() + async createRegressionTest(@UploadedFiles() files, @Body() testEntryDTO: TestEntryDTO) { + try { + return await this.service.create( + testEntryDTO.category, + testEntryDTO.command, + files + ); + } catch (error) { + return `Error creating the test entry`; + } + } + + @Get() + async getAllTestEntries() { + try { + return await this.service.getAll(); + } catch (error) { + return `Error while fetching the regression tests`; + } + } +} diff --git a/libs/api-implementation/test-entry/tsconfig.json b/libs/api-implementation/test-entry/tsconfig.json new file mode 100644 index 0000000..e65708f --- /dev/null +++ b/libs/api-implementation/test-entry/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"], + "target": "es6" + }, + "include": ["**/*.ts"] +} diff --git a/libs/api-implementation/test-entry/tsconfig.lib.json b/libs/api-implementation/test-entry/tsconfig.lib.json new file mode 100644 index 0000000..9c463b5 --- /dev/null +++ b/libs/api-implementation/test-entry/tsconfig.lib.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../../dist/out-tsc", + "declaration": true, + "rootDir": "./src", + "types": ["node"] + }, + "exclude": ["**/*.spec.ts"], + "include": ["**/*.ts"] +} diff --git a/libs/api-implementation/test-entry/tsconfig.spec.json b/libs/api-implementation/test-entry/tsconfig.spec.json new file mode 100644 index 0000000..1798b37 --- /dev/null +++ b/libs/api-implementation/test-entry/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts" + ] +} diff --git a/libs/api-implementation/test-entry/tslint.json b/libs/api-implementation/test-entry/tslint.json new file mode 100644 index 0000000..2cdd298 --- /dev/null +++ b/libs/api-implementation/test-entry/tslint.json @@ -0,0 +1,5 @@ +{ + "extends": "../../../tslint.json", + "linterOptions": { "exclude": ["!**/*"] }, + "rules": {} +} diff --git a/nx.json b/nx.json index 96356d9..57b01fd 100644 --- a/nx.json +++ b/nx.json @@ -70,6 +70,9 @@ }, "api-implementation-report": { "tags": [] + }, + "api-implementation-test-entry": { + "tags": [] } } } diff --git a/tsconfig.json b/tsconfig.json index b3bee6e..bb12f0c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -46,6 +46,9 @@ ], "@new-sample-platform/api-implementation/report": [ "libs/api-implementation/report/src/index.ts" + ], + "@new-sample-platform/api-implementation/test-entry": [ + "libs/api-implementation/test-entry/src/index.ts" ] } }, From 5e028eb0504122e1e29249c2dba0c859725f4c19 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Tue, 25 Aug 2020 13:12:13 +0600 Subject: [PATCH 04/15] feat(api): added model for sample and refactored model structure --- .../models/samples/sample.models.ts | 7 +++++++ .../models/samples/sample.schema.ts | 17 +++++++++++++++++ .../models/samples/sample.types.ts | 10 ++++++++++ .../test-entry.models.ts | 0 .../test-entry.schema.ts | 4 ++++ .../test-entry.types.ts | 1 + 6 files changed, 39 insertions(+) create mode 100644 libs/api-implementation/models/samples/sample.models.ts create mode 100644 libs/api-implementation/models/samples/sample.schema.ts create mode 100644 libs/api-implementation/models/samples/sample.types.ts rename libs/api-implementation/models/{regression-tests => test-entries}/test-entry.models.ts (100%) rename libs/api-implementation/models/{regression-tests => test-entries}/test-entry.schema.ts (92%) rename libs/api-implementation/models/{regression-tests => test-entries}/test-entry.types.ts (94%) diff --git a/libs/api-implementation/models/samples/sample.models.ts b/libs/api-implementation/models/samples/sample.models.ts new file mode 100644 index 0000000..da4f86b --- /dev/null +++ b/libs/api-implementation/models/samples/sample.models.ts @@ -0,0 +1,7 @@ +import { model } from 'mongoose'; +import { ISampleDocument } from './sample.types'; +import SampleSchema from './sample.schema'; +export const SampleModel: model = model( + 'sample', + SampleSchema +); diff --git a/libs/api-implementation/models/samples/sample.schema.ts b/libs/api-implementation/models/samples/sample.schema.ts new file mode 100644 index 0000000..5128b26 --- /dev/null +++ b/libs/api-implementation/models/samples/sample.schema.ts @@ -0,0 +1,17 @@ +import { Schema } from 'mongoose'; + +const SampleSchema = new Schema({ + filename: { + type: String, + required: true, + }, + dateOfEntry: { + type: Date, + default: new Date(), + }, + lastUpdated: { + type: Date, + default: new Date(), + }, +}); +export default SampleSchema; diff --git a/libs/api-implementation/models/samples/sample.types.ts b/libs/api-implementation/models/samples/sample.types.ts new file mode 100644 index 0000000..14e9951 --- /dev/null +++ b/libs/api-implementation/models/samples/sample.types.ts @@ -0,0 +1,10 @@ +import { Document, Model } from "mongoose"; + +export interface ISample { + filename: String; + dateOfEntry?: Date; + lastUpdated?: Date; +} + +export interface ISampleDocument extends ISample, Document {} +export interface ISampleModel extends Model {} \ No newline at end of file diff --git a/libs/api-implementation/models/regression-tests/test-entry.models.ts b/libs/api-implementation/models/test-entries/test-entry.models.ts similarity index 100% rename from libs/api-implementation/models/regression-tests/test-entry.models.ts rename to libs/api-implementation/models/test-entries/test-entry.models.ts diff --git a/libs/api-implementation/models/regression-tests/test-entry.schema.ts b/libs/api-implementation/models/test-entries/test-entry.schema.ts similarity index 92% rename from libs/api-implementation/models/regression-tests/test-entry.schema.ts rename to libs/api-implementation/models/test-entries/test-entry.schema.ts index 07018fd..0fb1209 100644 --- a/libs/api-implementation/models/regression-tests/test-entry.schema.ts +++ b/libs/api-implementation/models/test-entries/test-entry.schema.ts @@ -24,6 +24,10 @@ const TestEntrySchema = new Schema({ type: [Buffer], required: true, }, + sample: { + type: String, + required: true + }, command: { type: String, required: true, diff --git a/libs/api-implementation/models/regression-tests/test-entry.types.ts b/libs/api-implementation/models/test-entries/test-entry.types.ts similarity index 94% rename from libs/api-implementation/models/regression-tests/test-entry.types.ts rename to libs/api-implementation/models/test-entries/test-entry.types.ts index 366e7fe..47cc0d1 100644 --- a/libs/api-implementation/models/regression-tests/test-entry.types.ts +++ b/libs/api-implementation/models/test-entries/test-entry.types.ts @@ -4,6 +4,7 @@ export interface ITestEntry { category: string; correctFiles: Buffer[]; command: string; + sample: string; dateOfEntry?: Date; lastUpdated?: Date; } From 39df40d3f8f3398536cb29c9edc0a5dfac34718c Mon Sep 17 00:00:00 2001 From: zelzhan Date: Tue, 25 Aug 2020 13:33:54 +0600 Subject: [PATCH 05/15] feat(api): adjustment of samples model in respect to the test-entry library --- .../lib/api-implementation-samples.module.ts | 4 +++- .../samples/src/lib/samples.controller.ts | 14 +++++++++++-- .../src/lib/services/samples.service.ts | 21 +++++++++++++++++++ .../test-entry/src/lib/dto/test-entry.dto.ts | 1 + .../src/lib/services/test-entry.service.ts | 18 +++++++++++++--- .../src/lib/test-entry.controller.ts | 1 + 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/libs/api-implementation/samples/src/lib/api-implementation-samples.module.ts b/libs/api-implementation/samples/src/lib/api-implementation-samples.module.ts index 6d1cc39..680bf0f 100644 --- a/libs/api-implementation/samples/src/lib/api-implementation-samples.module.ts +++ b/libs/api-implementation/samples/src/lib/api-implementation-samples.module.ts @@ -1,9 +1,11 @@ import { Module } from '@nestjs/common'; -import { SamplesController } from './samples.controller' +import { SamplesController } from './samples.controller'; import { SamplesService } from './services/samples.service'; +import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; @Module({ + imports: [ApiImplementationDatabaseModule], controllers: [SamplesController], providers: [SamplesService], exports: [], diff --git a/libs/api-implementation/samples/src/lib/samples.controller.ts b/libs/api-implementation/samples/src/lib/samples.controller.ts index 8f9c207..e98a0b2 100644 --- a/libs/api-implementation/samples/src/lib/samples.controller.ts +++ b/libs/api-implementation/samples/src/lib/samples.controller.ts @@ -3,6 +3,7 @@ import { Post, UseInterceptors, UploadedFile, + Get, } from '@nestjs/common'; import { FileInterceptor } from '@nestjs/platform-express'; import { SamplesService } from './services/samples.service'; @@ -17,8 +18,17 @@ export class SamplesController { try { this.service.writeToBucket(file); } catch (error) { - return 'Error while writing the file to the bucket' + return 'Error while writing the file to the bucket'; + } + return 200; + } + + @Get() + getAllSampleNames() { + try { + return this.service.getAllSampleNames(); + } catch (error) { + return 'Error while fetching sample names'; } - return 200 } } diff --git a/libs/api-implementation/samples/src/lib/services/samples.service.ts b/libs/api-implementation/samples/src/lib/services/samples.service.ts index 1007e69..6d0e326 100644 --- a/libs/api-implementation/samples/src/lib/services/samples.service.ts +++ b/libs/api-implementation/samples/src/lib/services/samples.service.ts @@ -1,6 +1,8 @@ import { Injectable } from '@nestjs/common'; import { writeFileSync } from 'fs'; import { AppConfig } from '../../../../../../config'; +import { SampleModel } from '../../../../models/samples/sample.models'; + @Injectable() export class SamplesService { async writeToBucket(file) { @@ -9,10 +11,29 @@ export class SamplesService { AppConfig.PATH_TO_MOUNTED_BUCKET + file.originalname, file.buffer ); + await this.addSampleToDB(file.originalname); } catch (error) { console.error(`Error occured while writing the file to the bucket`); + // tslint:disable-next-line: no-console console.debug(error.stack); throw error; } } + + async getAllSampleNames() { + try { + return await SampleModel.find({}); + } catch (error) { + console.error('Error occured while fetching the sample names'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + throw error; + } + } + + private async addSampleToDB(filename: string) { + await SampleModel.create({ + filename: filename, + }); + } } diff --git a/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts b/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts index c577bc9..2fccadd 100644 --- a/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts +++ b/libs/api-implementation/test-entry/src/lib/dto/test-entry.dto.ts @@ -1,4 +1,5 @@ export class TestEntryDTO { category: string; command: string; + sample: string; } diff --git a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts index e3f5aa7..cb92cfc 100644 --- a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts +++ b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts @@ -1,17 +1,29 @@ import { Injectable } from '@nestjs/common'; -import { TestEntryModel } from '../../../../models/regression-tests/test-entry.models'; +import { TestEntryModel } from '../../../../models/test-entries/test-entry.models'; @Injectable() export class TestEntryService { async getAll() { - return await TestEntryModel.find({}); + try { + } catch (error) { + console.error('Error while fetching the test entries'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + return await TestEntryModel.find({}); + } } - async create(category: string, new_command: string, files: Buffer[]) { + async create( + category: string, + new_command: string, + sample: string, + files: Buffer[] + ) { try { return await TestEntryModel.create({ command: new_command, category: category, + sample: sample, correctFiles: files, }); } catch (error) { diff --git a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts index c768b2b..a8f9ddf 100644 --- a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts +++ b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts @@ -14,6 +14,7 @@ export class TestEntryController { return await this.service.create( testEntryDTO.category, testEntryDTO.command, + testEntryDTO.sample, files ); } catch (error) { From 171e241bce8bdf9f182ebf537476bb0fd35fe553 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Wed, 26 Aug 2020 14:46:18 +0600 Subject: [PATCH 06/15] feat(sample-platform): Added view for creation of the test-entry with autocomplete of samples --- angular.json | 32 ++++++ apps/api/src/app/app.module.ts | 2 + apps/api/tsconfig.json | 2 +- apps/github-interactions-api/tsconfig.json | 2 +- apps/sample-platform/proxy.conf.json | 2 +- .../sample-platform/src/app/routing.module.ts | 7 ++ ccextractor-277307-b36fffc9a6cb.json | 12 -- .../src/lib/services/orchestration.service.ts | 1 - .../src/lib/services/test-entry.service.ts | 2 +- .../src/lib/test-entry.controller.ts | 9 +- .../regression-test/tsconfig.lib.json | 2 +- libs/frontend/samples/tsconfig.lib.json | 2 +- libs/frontend/test-entry/README.md | 7 ++ libs/frontend/test-entry/jest.config.js | 10 ++ libs/frontend/test-entry/src/index.ts | 1 + .../create-test-entry.component.html | 69 ++++++++++++ .../create-test-entry.component.scss | 10 ++ .../create-test-entry.component.spec.ts | 25 +++++ .../create-test-entry.component.ts | 105 ++++++++++++++++++ .../upload-page/upload-page.component.html | 1 + .../upload-page/upload-page.component.scss | 0 .../upload-page/upload-page.component.spec.ts | 25 +++++ .../upload-page/upload-page.component.ts | 15 +++ .../lib/frontend-test-entry.module.spec.ts | 14 +++ .../src/lib/frontend-test-entry.module.ts | 34 ++++++ .../test-entry/src/lib/routing.module.ts | 14 +++ .../src/lib/services/upload.service.ts | 15 +++ libs/frontend/test-entry/src/test-setup.ts | 1 + libs/frontend/test-entry/tsconfig.json | 7 ++ libs/frontend/test-entry/tsconfig.lib.json | 17 +++ libs/frontend/test-entry/tsconfig.spec.json | 10 ++ libs/frontend/test-entry/tslint.json | 10 ++ libs/testing/tsconfig.lib.json | 2 +- nx.json | 3 + package-lock.json | 11 ++ package.json | 2 + tools/tsconfig.tools.json | 2 +- tsconfig.json | 5 +- typings.json | 6 + 39 files changed, 468 insertions(+), 28 deletions(-) delete mode 100644 ccextractor-277307-b36fffc9a6cb.json create mode 100644 libs/frontend/test-entry/README.md create mode 100644 libs/frontend/test-entry/jest.config.js create mode 100644 libs/frontend/test-entry/src/index.ts create mode 100644 libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html create mode 100644 libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.scss create mode 100644 libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts create mode 100644 libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts create mode 100644 libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html create mode 100644 libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss create mode 100644 libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.spec.ts create mode 100644 libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.ts create mode 100644 libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts create mode 100644 libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts create mode 100644 libs/frontend/test-entry/src/lib/routing.module.ts create mode 100644 libs/frontend/test-entry/src/lib/services/upload.service.ts create mode 100644 libs/frontend/test-entry/src/test-setup.ts create mode 100644 libs/frontend/test-entry/tsconfig.json create mode 100644 libs/frontend/test-entry/tsconfig.lib.json create mode 100644 libs/frontend/test-entry/tsconfig.spec.json create mode 100644 libs/frontend/test-entry/tslint.json create mode 100644 typings.json diff --git a/angular.json b/angular.json index 855ebe0..b4b6b6d 100644 --- a/angular.json +++ b/angular.json @@ -588,6 +588,38 @@ } } } + }, + "frontend-test-entry": { + "projectType": "library", + "root": "libs/frontend/test-entry", + "sourceRoot": "libs/frontend/test-entry/src", + "prefix": "frontend", + "architect": { + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "libs/frontend/test-entry/tsconfig.lib.json", + "libs/frontend/test-entry/tsconfig.spec.json" + ], + "exclude": ["**/node_modules/**", "!libs/frontend/test-entry/**"] + } + }, + "test": { + "builder": "@nrwl/jest:jest", + "options": { + "jestConfig": "libs/frontend/test-entry/jest.config.js", + "tsConfig": "libs/frontend/test-entry/tsconfig.spec.json", + "passWithNoTests": true, + "setupFile": "libs/frontend/test-entry/src/test-setup.ts" + } + } + }, + "schematics": { + "@nrwl/angular:component": { + "style": "scss" + } + } } }, "cli": { diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index b661a4e..ce13081 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -7,12 +7,14 @@ import { ApiImplementationRegressionTestsModule } from '@new-sample-platform/api import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; import { ApiImplementationSamplesModule } from '@new-sample-platform/api-implementation/samples' import { ApiImplementationReportModule } from '@new-sample-platform/api-implementation/report' +import { ApiImplementationTestEntryModule } from '@new-sample-platform/api-implementation/test-entry' import { HttpAdapterHost } from '@nestjs/core'; @Module({ imports: [ HttpAdapterHost, VMOrchestrationModule, + ApiImplementationTestEntryModule, ApiImplementationReportModule, ApiImplementationRegressionTestsModule, ApiImplementationDatabaseModule, diff --git a/apps/api/tsconfig.json b/apps/api/tsconfig.json index 4d5dcd9..cdafb1f 100644 --- a/apps/api/tsconfig.json +++ b/apps/api/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "types": ["node", "jest"], "emitDecoratorMetadata": true, - "target": "es2015" + "target": "es6" }, "include": ["**/*.ts"] } diff --git a/apps/github-interactions-api/tsconfig.json b/apps/github-interactions-api/tsconfig.json index 4d5dcd9..cdafb1f 100644 --- a/apps/github-interactions-api/tsconfig.json +++ b/apps/github-interactions-api/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "types": ["node", "jest"], "emitDecoratorMetadata": true, - "target": "es2015" + "target": "es6" }, "include": ["**/*.ts"] } diff --git a/apps/sample-platform/proxy.conf.json b/apps/sample-platform/proxy.conf.json index 37da373..9a1dea2 100644 --- a/apps/sample-platform/proxy.conf.json +++ b/apps/sample-platform/proxy.conf.json @@ -1,5 +1,5 @@ { - "/api/*": { + "/api": { "target": "http://localhost:3333", "secure": false, "changeOrigin": true, diff --git a/apps/sample-platform/src/app/routing.module.ts b/apps/sample-platform/src/app/routing.module.ts index 40e1a61..91f39e0 100644 --- a/apps/sample-platform/src/app/routing.module.ts +++ b/apps/sample-platform/src/app/routing.module.ts @@ -19,6 +19,13 @@ const routes: Routes = [ import('@new-sample-platform/frontend/samples').then( (mod) => mod.FrontendSamplesModule ) + }, + { + path: 'test-entry', + loadChildren: () => + import('@new-sample-platform/frontend/test-entry').then( + (mod) => mod.FrontendTestEntryModule + ) } ]; diff --git a/ccextractor-277307-b36fffc9a6cb.json b/ccextractor-277307-b36fffc9a6cb.json deleted file mode 100644 index b49a3f7..0000000 --- a/ccextractor-277307-b36fffc9a6cb.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "service_account", - "project_id": "ccextractor-277307", - "private_key_id": "b36fffc9a6cb067f369c5330e644fda3bde953cc", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC6C56o0AmMk+We\nJyWNWLpM5cHK9JDnP9hefbqnBF4hwnCawMG4bxVCo/fgYPvRDcyAZ9CeMVlIdMOE\nXT0H3fy52A5h8R4Ysiq/m6dIRnnEW0HbtnZvjgR0wnmqlxhpsMuQGWea0arcHjWd\nWcVLjDD+3xpZndf9VjwKSqcRgMMv5KPC51ClKVJoibE1I1NDi5EZ/WziPsY5quwi\n4pQMDIuY06Mn5lvuDLwcOFWqDBPSJBFYlUUXn7ekMjDhCv1O91Y+W8OXzFoNiwkb\nE4AX65y3JHYVauoeONgUy8GeZ47fyN+D75xhpgR4XqzuazDSxDCT+0alHulW7JZb\n0wYvCzuDAgMBAAECggEAEu/i2Z5kvRqYHpsvzy2PDQu9SETQ87uZG7PNiiQ/gU0y\n5rWkd6Wq8tUQ1+ssm/tnwPw64myggL0N4mJr4hSeSGZtvwTALQBZqeuUlp6XKhL7\nPFDcHlUaLq5VnF/JMYeNjjXfyK+l0MZXFmn6/fUfpERzq1fjPTCyvNNwzQR1Gbc4\nlxL4gSF2CpOafchECNesP0TU51aGbTONIileuwOU5ZpGrs6M9/n/twY7bQ/mW4kw\nGCSbX1UnxzvkrMeIoL60dEzF+JQCS9OSmmEcIejICMJIZcc2fEqYfJNzO0LFGGLx\nCLKc8k6QeOh70F5UeSBTdqG9AAoICPcS/2e9lWC93QKBgQD1tHUHIk8iilOCd6Qx\n6CK3b4JuzRvNesnRreaFlieoNKne+S12kdOV8lVtUDMnrQll1nouA6RU7vvZ6civ\nmfyimOZStQRHA0TEaqPEG0ZGPrzwNXxyTh+wBf2YfMfOMpqmPSpxVpwxxJVGNu18\n84EB0mOGCtetnRd1WCKKYHL2rwKBgQDB1zo3fwDTNSqIaQB/GWAsgLfJSjNZGwIY\nB/bv+0vcZLM+bRZMih2lMzuihv2ZptoL0BwyMWpR6oxgNtiwneiweUXYJGlkjPtZ\nJuA4afuAID4VaVbIeQN55P2dFTCtxTI2JLma4v4Z7D71J68mWXWZULO16sVO9xh8\nl9mcP9e9bQKBgGFPy1m7+OORLWnqwJkTe0xzWZFQosZK70ugOECIK8Sutuicf6kK\nMGaex763mMsJ+ULgIxu+TYNl81FnChiiQDCVpgLztnH5lW7FXX753mdLycDJLjSH\nRH2OodWW9ftwh1d3uiuRReNgHE7mykBGoL17+fbIrIsSQIw1D9kGQgH5AoGAGupT\nvxj3eFxNh5ts4jkXzZYh7uVKs/i4FbYlZ7UxF200JlrnWcFj1GiEw1CTLh6o8DL5\nd069QJqc209CT2Pdx4NPW2/S4o9g50QqpiqxLV1MwZRa5INJJEfTn1gt5jMXgcUf\nsI4MUnUnWMsl2uFZHuzBx2TN+OT+lW5QXQ3QWxECgYAtaUQZZCQI4MbmyutDUp4i\ni/ZM22hsgNbBJ74y5EdOjm3JPoDJDDE6u04Uujyi+5Ki2rtxtgg96ZouHIv1pLaq\n3/i2bT+33enxXfDHXnvY2btNQ9xQRXBKFUl+o/A4dtVSJSkizEpR5dTXb+ePV2cp\njjJq46h1bas64uWzhwB+3Q==\n-----END PRIVATE KEY-----\n", - "client_email": "elzhan-service@ccextractor-277307.iam.gserviceaccount.com", - "client_id": "107305404303111498344", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/elzhan-service%40ccextractor-277307.iam.gserviceaccount.com" -} diff --git a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts index e684743..460f8b3 100644 --- a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts +++ b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts @@ -70,7 +70,6 @@ export class VMOrchestrationService implements VMOrchestrationInterface { async reset(name: string) { try { const response = await this.machines[name].getInstance().reset(); - console.log(response); } catch (error) { console.error(`Error occured while reseting the machine ${name}`) console.debug(error.stack) diff --git a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts index cb92cfc..8e0a7fe 100644 --- a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts +++ b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts @@ -5,11 +5,11 @@ import { TestEntryModel } from '../../../../models/test-entries/test-entry.model export class TestEntryService { async getAll() { try { + return await TestEntryModel.find({}); } catch (error) { console.error('Error while fetching the test entries'); // tslint:disable-next-line: no-console console.debug(error.stack); - return await TestEntryModel.find({}); } } diff --git a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts index a8f9ddf..ae1064d 100644 --- a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts +++ b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts @@ -10,13 +10,10 @@ export class TestEntryController { @UseInterceptors(AnyFilesInterceptor()) @Post() async createRegressionTest(@UploadedFiles() files, @Body() testEntryDTO: TestEntryDTO) { + console.log("files", files) + console.log("===========================") + console.log("Payload", testEntryDTO) try { - return await this.service.create( - testEntryDTO.category, - testEntryDTO.command, - testEntryDTO.sample, - files - ); } catch (error) { return `Error creating the test entry`; } diff --git a/libs/frontend/regression-test/tsconfig.lib.json b/libs/frontend/regression-test/tsconfig.lib.json index f0e13d4..fed3242 100644 --- a/libs/frontend/regression-test/tsconfig.lib.json +++ b/libs/frontend/regression-test/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../../dist/out-tsc", - "target": "es2015", + "target": "es6", "declaration": true, "inlineSources": true, "types": [], diff --git a/libs/frontend/samples/tsconfig.lib.json b/libs/frontend/samples/tsconfig.lib.json index f0e13d4..fed3242 100644 --- a/libs/frontend/samples/tsconfig.lib.json +++ b/libs/frontend/samples/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../../dist/out-tsc", - "target": "es2015", + "target": "es6", "declaration": true, "inlineSources": true, "types": [], diff --git a/libs/frontend/test-entry/README.md b/libs/frontend/test-entry/README.md new file mode 100644 index 0000000..dcfedca --- /dev/null +++ b/libs/frontend/test-entry/README.md @@ -0,0 +1,7 @@ +# frontend-test-entry + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test frontend-test-entry` to execute the unit tests. diff --git a/libs/frontend/test-entry/jest.config.js b/libs/frontend/test-entry/jest.config.js new file mode 100644 index 0000000..7097fdb --- /dev/null +++ b/libs/frontend/test-entry/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + name: 'frontend-test-entry', + preset: '../../../jest.config.js', + coverageDirectory: '../../../coverage/libs/frontend/test-entry', + snapshotSerializers: [ + 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js', + 'jest-preset-angular/build/AngularSnapshotSerializer.js', + 'jest-preset-angular/build/HTMLCommentSerializer.js', + ], +}; diff --git a/libs/frontend/test-entry/src/index.ts b/libs/frontend/test-entry/src/index.ts new file mode 100644 index 0000000..68ace84 --- /dev/null +++ b/libs/frontend/test-entry/src/index.ts @@ -0,0 +1 @@ +export * from './lib/frontend-test-entry.module'; diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html new file mode 100644 index 0000000..ea80f7f --- /dev/null +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html @@ -0,0 +1,69 @@ +

Create Test Entry

+ +
+
+ + +
+
Command is required.
+
+ Command should be 3 character. +
+
+
+ + + +
+ + Category + + + {{category.viewValue}} + + + + +
+ +
+ + + + + + {{option}} + + + +
+
+
Sample is required.
+
+
+ + + + +
+ + +
\ No newline at end of file diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.scss b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.scss new file mode 100644 index 0000000..dc3cd90 --- /dev/null +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.scss @@ -0,0 +1,10 @@ +.mat-success { + background-color: green; + color: #fff; +} + + +.category { + background-color: black; + border-radius: 10px; +} diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts new file mode 100644 index 0000000..d7f4265 --- /dev/null +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateTestEntryComponent } from './create-test-entry.component'; + +describe('CreateTestEntryComponent', () => { + let component: CreateTestEntryComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateTestEntryComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateTestEntryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts new file mode 100644 index 0000000..05c54df --- /dev/null +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts @@ -0,0 +1,105 @@ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { UploadService } from '../../services/upload.service'; +import { Observable } from 'rxjs'; +import { map, startWith } from 'rxjs/operators'; + +@Component({ + selector: 'frontend-create-test-entry', + templateUrl: './create-test-entry.component.html', + styleUrls: ['./create-test-entry.component.scss'], +}) +export class CreateTestEntryComponent implements OnInit { + myForm = new FormGroup({ + command: new FormControl('', [ + Validators.required, + Validators.minLength(3), + ]), + category: new FormControl('', [Validators.required]), + sample: new FormControl('', [Validators.required]), + }); + + public selectedValue: string; + //TODO: it should not be hardcoded! + public categories = [ + { value: 'broken', viewValue: 'Broken' }, + { value: 'cea-708', viewValue: 'CEA-708' }, + { value: 'dvb', viewValue: 'DVB' }, + { value: 'dvd', viewValue: 'DVR-MS' }, + { value: 'general', viewValue: 'General' }, + { value: 'hauppage', viewValue: 'Hauppage' }, + { value: 'mp4', viewValue: 'MP4' }, + { value: 'nocc', viewValue: 'NoCC' }, + { value: 'options', viewValue: 'Options' }, + { value: 'teletext', viewValue: 'Teletext' }, + { value: 'wtv', viewValue: 'WTV' }, + { value: 'xds', viewValue: 'XDS' }, + ]; + + public options: string[] = []; + public filteredOptions: Observable; + + private selectedFiles: File[] = []; + private formD: FormData; + + constructor(private service: UploadService) {} + + ngOnInit() { + this.service.getSamples().subscribe((samples: any[]) => { + this.options = samples.map((sample) => sample.filename); + this.filteredOptions = this.myForm.valueChanges.pipe( + startWith(''), + map((value) => { + return this._filter(value); + }) + ); + }); + + + } + + private _filter(value: unknown): string[] { + const filterValue = (value as string).toLowerCase(); + + return this.options.filter( + (option) => option.toLowerCase().indexOf(filterValue) === 0 + ); + } + + openInput() { + document.getElementById('uploadFile').click(); + } + + fileAdded(event) { + if (event.target.files.length) { + for (let i = 0; i < event.target.files.length; i++) { + this.selectedFiles.push(event.target.files[i]); + } + } + } + + private upload() { + this.formD = new FormData(); + this.formD.append('command', this.myForm.value.command); + this.formD.append('sample', this.myForm.value.sample); + this.formD.append('category', this.selectedValue); + + if (this.selectedFiles.length) { + for (let i = 0; i < this.selectedFiles.length; i++) + this.formD.append( + 'files[]', + this.selectedFiles[i], + this.selectedFiles[i].name + ); + } + } + + get f() { + return this.myForm.controls; + } + + submitToService() { + this.upload(); + this.service.upload(this.formD); + } +} diff --git a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html new file mode 100644 index 0000000..3289887 --- /dev/null +++ b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html @@ -0,0 +1 @@ +

upload-page works!

diff --git a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.spec.ts b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.spec.ts new file mode 100644 index 0000000..9549e1a --- /dev/null +++ b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UploadPageComponent } from './upload-page.component'; + +describe('UploadPageComponent', () => { + let component: UploadPageComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ UploadPageComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(UploadPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.ts b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.ts new file mode 100644 index 0000000..5cbc5ed --- /dev/null +++ b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'frontend-upload-page', + templateUrl: './upload-page.component.html', + styleUrls: ['./upload-page.component.scss'] +}) +export class UploadPageComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts new file mode 100644 index 0000000..df98f84 --- /dev/null +++ b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts @@ -0,0 +1,14 @@ +import { async, TestBed } from '@angular/core/testing'; +import { FrontendTestEntryModule } from './frontend-test-entry.module'; + +describe('FrontendTestEntryModule', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [FrontendTestEntryModule], + }).compileComponents(); + })); + + it('should create', () => { + expect(FrontendTestEntryModule).toBeDefined(); + }); +}); diff --git a/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts new file mode 100644 index 0000000..ccebc20 --- /dev/null +++ b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts @@ -0,0 +1,34 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { UploadPageComponent } from './containers/upload-page/upload-page.component'; +import { CreateTestEntryComponent } from './components/create-test-entry/create-test-entry.component'; +import { HttpClientModule } from '@angular/common/http'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { RoutingModule } from './routing.module'; +import { UploadService } from './services/upload.service'; +import { MatButtonModule } from '@angular/material/button'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatIconModule } from '@angular/material/icon' +import { MaterialFileInputModule } from 'ngx-material-file-input'; +import { MatSelectModule } from '@angular/material/select' +import { MatAutocompleteModule } from '@angular/material/autocomplete' + +@NgModule({ + imports: [ + MatAutocompleteModule, + MatSelectModule, + MatIconModule, + MaterialFileInputModule, + MatFormFieldModule, + MatButtonModule, + RoutingModule, + CommonModule, + HttpClientModule, + FormsModule, + ReactiveFormsModule, + ], + declarations: [UploadPageComponent, CreateTestEntryComponent], + + providers: [UploadService], +}) +export class FrontendTestEntryModule {} diff --git a/libs/frontend/test-entry/src/lib/routing.module.ts b/libs/frontend/test-entry/src/lib/routing.module.ts new file mode 100644 index 0000000..0fad8ad --- /dev/null +++ b/libs/frontend/test-entry/src/lib/routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { CreateTestEntryComponent } from './components/create-test-entry/create-test-entry.component'; +import { UploadService } from './services/upload.service'; + +const routes: Routes = [ + { path: 'create-test-entry', component: CreateTestEntryComponent }, +]; +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] + +}) +export class RoutingModule {} diff --git a/libs/frontend/test-entry/src/lib/services/upload.service.ts b/libs/frontend/test-entry/src/lib/services/upload.service.ts new file mode 100644 index 0000000..680b804 --- /dev/null +++ b/libs/frontend/test-entry/src/lib/services/upload.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpEventType, HttpResponse } from '@angular/common/http'; + +@Injectable({ providedIn: 'root' }) +export class UploadService { + constructor(private http: HttpClient) {} + + public upload(form: FormData) { + this.http.post('api/test-entry', form).subscribe(); + } + + public getSamples() { + return this.http.get('api/samples') + } +} diff --git a/libs/frontend/test-entry/src/test-setup.ts b/libs/frontend/test-entry/src/test-setup.ts new file mode 100644 index 0000000..8d88704 --- /dev/null +++ b/libs/frontend/test-entry/src/test-setup.ts @@ -0,0 +1 @@ +import 'jest-preset-angular'; diff --git a/libs/frontend/test-entry/tsconfig.json b/libs/frontend/test-entry/tsconfig.json new file mode 100644 index 0000000..08c7db8 --- /dev/null +++ b/libs/frontend/test-entry/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"] + }, + "include": ["**/*.ts"] +} diff --git a/libs/frontend/test-entry/tsconfig.lib.json b/libs/frontend/test-entry/tsconfig.lib.json new file mode 100644 index 0000000..fed3242 --- /dev/null +++ b/libs/frontend/test-entry/tsconfig.lib.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "target": "es6", + "declaration": true, + "inlineSources": true, + "types": [], + "lib": ["dom", "es2018"] + }, + "angularCompilerOptions": { + "skipTemplateCodegen": true, + "strictMetadataEmit": true, + "enableResourceInlining": true + }, + "exclude": ["src/test-setup.ts", "**/*.spec.ts"] +} diff --git a/libs/frontend/test-entry/tsconfig.spec.json b/libs/frontend/test-entry/tsconfig.spec.json new file mode 100644 index 0000000..fd405a6 --- /dev/null +++ b/libs/frontend/test-entry/tsconfig.spec.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "files": ["src/test-setup.ts"], + "include": ["**/*.spec.ts", "**/*.d.ts"] +} diff --git a/libs/frontend/test-entry/tslint.json b/libs/frontend/test-entry/tslint.json new file mode 100644 index 0000000..b205ad0 --- /dev/null +++ b/libs/frontend/test-entry/tslint.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tslint.json", + "rules": { + "directive-selector": [true, "attribute", "frontend", "camelCase"], + "component-selector": [true, "element", "frontend", "kebab-case"] + }, + "linterOptions": { + "exclude": ["!**/*"] + } +} diff --git a/libs/testing/tsconfig.lib.json b/libs/testing/tsconfig.lib.json index 0bb76e3..9b7ad62 100644 --- a/libs/testing/tsconfig.lib.json +++ b/libs/testing/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "target": "es2015", + "target": "es6", "declaration": true, "inlineSources": true, "types": [], diff --git a/nx.json b/nx.json index 57b01fd..8e13f37 100644 --- a/nx.json +++ b/nx.json @@ -73,6 +73,9 @@ }, "api-implementation-test-entry": { "tags": [] + }, + "frontend-test-entry": { + "tags": [] } } } diff --git a/package-lock.json b/package-lock.json index f90228c..2012656 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4248,6 +4248,12 @@ "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" }, + "@types/core-js": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/@types/core-js/-/core-js-2.5.3.tgz", + "integrity": "sha512-F9RHpjuPSit4dCCRXgi7XcqA01DAjy9QY+v9yICoxXsjXD9cgQpyZyL2eSZnTkBGXGaQnea8waZOZTogLDB+rA==", + "dev": true + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", @@ -12708,6 +12714,11 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, + "ngx-material-file-input": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ngx-material-file-input/-/ngx-material-file-input-2.1.1.tgz", + "integrity": "sha512-FbaIjiJnL6BZtZYWLvMSn9aSaM62AZaJegloTUphmLz5jopXPzE5W+3aC+dsf9h1IIqHSCLcyv0w+qH0ypBhMA==" + }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", diff --git a/package.json b/package.json index abe1f94..ee5220d 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "formidable": "^1.2.2", "mongodb": "^3.5.8", "mongoose": "^5.9.26", + "ngx-material-file-input": "^2.1.1", "reflect-metadata": "^0.1.13", "request": "^2.88.2", "request-promise": "^4.2.5", @@ -76,6 +77,7 @@ "@nrwl/nest": "9.3.0", "@nrwl/node": "9.3.0", "@nrwl/workspace": "9.3.0", + "@types/core-js": "^2.5.3", "@types/jest": "25.1.4", "@types/node": "~8.9.4", "@types/request-promise": "^4.1.46", diff --git a/tools/tsconfig.tools.json b/tools/tsconfig.tools.json index 82bd1f0..4a53476 100644 --- a/tools/tsconfig.tools.json +++ b/tools/tsconfig.tools.json @@ -4,7 +4,7 @@ "outDir": "../dist/out-tsc/tools", "rootDir": ".", "module": "commonjs", - "target": "es5", + "target": "es6", "types": ["node"] }, "include": ["**/*.ts"] diff --git a/tsconfig.json b/tsconfig.json index bb12f0c..9b0682f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "importHelpers": true, - "target": "es2015", + "target": "es6", "module": "esnext", "typeRoots": ["node_modules/@types"], "lib": ["es2017", "dom"], @@ -49,6 +49,9 @@ ], "@new-sample-platform/api-implementation/test-entry": [ "libs/api-implementation/test-entry/src/index.ts" + ], + "@new-sample-platform/frontend/test-entry": [ + "libs/frontend/test-entry/src/index.ts" ] } }, diff --git a/typings.json b/typings.json new file mode 100644 index 0000000..58a647e --- /dev/null +++ b/typings.json @@ -0,0 +1,6 @@ +{ + "globalDependencies": { + "es6-collections": "registry:dt/es6-collections#0.5.1+20160510002910", + "es6-promise": "registry:dt/es6-promise#0.0.0+20160726191732" + } +} From 6f0fdaedbb3e2221a55a0dfc8d025cb97175a676 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Thu, 27 Aug 2020 10:17:45 +0600 Subject: [PATCH 07/15] feat(api, sample-platform): Improved UI for the creation of test entry and fix problem with file storage --- apps/sample-platform/src/styles.css | 2 +- .../models/file/file.models.ts | 4 ++++ .../models/file/file.schema.ts | 13 +++++++++++ .../models/file/file.types.ts | 10 ++++++++ .../models/test-entries/test-entry.schema.ts | 4 ++-- .../src/lib/services/test-entry.service.ts | 14 +++++++++-- .../src/lib/test-entry.controller.ts | 23 +++++++++++++++---- .../create-test-entry.component.html | 2 +- .../create-test-entry.component.ts | 2 +- .../upload-page/upload-page.component.html | 5 +++- .../upload-page/upload-page.component.scss | 5 ++++ .../src/lib/frontend-test-entry.module.ts | 3 +++ .../test-entry/src/lib/routing.module.ts | 3 ++- .../src/lib/services/upload.service.ts | 4 ++-- 14 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 libs/api-implementation/models/file/file.models.ts create mode 100644 libs/api-implementation/models/file/file.schema.ts create mode 100644 libs/api-implementation/models/file/file.types.ts diff --git a/apps/sample-platform/src/styles.css b/apps/sample-platform/src/styles.css index 23894ad..f45d671 100644 --- a/apps/sample-platform/src/styles.css +++ b/apps/sample-platform/src/styles.css @@ -1,4 +1,4 @@ /* You can add global styles to this file, and also import other style files */ html, body { height: 100%; } -body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; background-color: aliceblue;} +body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; background-color: white;} diff --git a/libs/api-implementation/models/file/file.models.ts b/libs/api-implementation/models/file/file.models.ts new file mode 100644 index 0000000..0e3296e --- /dev/null +++ b/libs/api-implementation/models/file/file.models.ts @@ -0,0 +1,4 @@ +import { model } from 'mongoose'; +import { IFileDocument } from './file.types'; +import FileSchema from './file.schema'; +export const FileModel: model = model('file', FileSchema); diff --git a/libs/api-implementation/models/file/file.schema.ts b/libs/api-implementation/models/file/file.schema.ts new file mode 100644 index 0000000..7c74bb6 --- /dev/null +++ b/libs/api-implementation/models/file/file.schema.ts @@ -0,0 +1,13 @@ +import { Schema } from 'mongoose'; + +const FileSchema = new Schema({ + filename: { + type: String, + required: true, + }, + buffer: { + type: Buffer, + required: true, + }, +}); +export default FileSchema; diff --git a/libs/api-implementation/models/file/file.types.ts b/libs/api-implementation/models/file/file.types.ts new file mode 100644 index 0000000..590f841 --- /dev/null +++ b/libs/api-implementation/models/file/file.types.ts @@ -0,0 +1,10 @@ +import { Document, Model } from 'mongoose'; + +export interface IFile { + filename: String; + dateOfEntry?: Date; + lastUpdated?: Date; +} + +export interface IFileDocument extends IFile, Document {} +export interface IFileModel extends Model {} diff --git a/libs/api-implementation/models/test-entries/test-entry.schema.ts b/libs/api-implementation/models/test-entries/test-entry.schema.ts index 0fb1209..e764c7d 100644 --- a/libs/api-implementation/models/test-entries/test-entry.schema.ts +++ b/libs/api-implementation/models/test-entries/test-entry.schema.ts @@ -21,12 +21,12 @@ const TestEntrySchema = new Schema({ required: true, }, correctFiles: { - type: [Buffer], + type: [Object], required: true, }, sample: { type: String, - required: true + required: true, }, command: { type: String, diff --git a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts index 8e0a7fe..d231ded 100644 --- a/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts +++ b/libs/api-implementation/test-entry/src/lib/services/test-entry.service.ts @@ -3,6 +3,7 @@ import { TestEntryModel } from '../../../../models/test-entries/test-entry.model @Injectable() export class TestEntryService { + async getAll() { try { return await TestEntryModel.find({}); @@ -17,14 +18,23 @@ export class TestEntryService { category: string, new_command: string, sample: string, - files: Buffer[] + files: any[] ) { + const correctFiles = [] + + files.forEach(file => { + correctFiles.push({ + filename: file.originalname, + buffer: file.buffer + }) + }) + try { return await TestEntryModel.create({ command: new_command, category: category, sample: sample, - correctFiles: files, + correctFiles: correctFiles, }); } catch (error) { console.error('Error while creating the test entry'); diff --git a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts index ae1064d..9d719cf 100644 --- a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts +++ b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts @@ -1,4 +1,11 @@ -import { Controller, Post, Body, Get, UseInterceptors, UploadedFiles } from '@nestjs/common'; +import { + Controller, + Post, + Body, + Get, + UseInterceptors, + UploadedFiles, +} from '@nestjs/common'; import { TestEntryDTO } from './dto/test-entry.dto'; import { TestEntryService } from './services/test-entry.service'; import { AnyFilesInterceptor } from '@nestjs/platform-express'; @@ -9,11 +16,17 @@ export class TestEntryController { @UseInterceptors(AnyFilesInterceptor()) @Post() - async createRegressionTest(@UploadedFiles() files, @Body() testEntryDTO: TestEntryDTO) { - console.log("files", files) - console.log("===========================") - console.log("Payload", testEntryDTO) + async createTestEntry( + @UploadedFiles() files, + @Body() testEntryDTO: TestEntryDTO + ) { try { + this.service.create( + testEntryDTO.category, + testEntryDTO.command, + testEntryDTO.sample, + files + ); } catch (error) { return `Error creating the test entry`; } diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html index ea80f7f..a15bad6 100644 --- a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html @@ -59,7 +59,7 @@

Create Test Entry

Sample is required.
- +
{{f.name}}
diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts index 05c54df..e02baeb 100644 --- a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.ts @@ -39,7 +39,7 @@ export class CreateTestEntryComponent implements OnInit { public options: string[] = []; public filteredOptions: Observable; - private selectedFiles: File[] = []; + public selectedFiles: File[] = []; private formD: FormData; constructor(private service: UploadService) {} diff --git a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html index 3289887..264ceca 100644 --- a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html +++ b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.html @@ -1 +1,4 @@ -

upload-page works!

+ + diff --git a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss index e69de29..4f33869 100644 --- a/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss +++ b/libs/frontend/test-entry/src/lib/containers/upload-page/upload-page.component.scss @@ -0,0 +1,5 @@ +mat-card { + width: 50%; + margin-left: auto; + margin-right: auto; +} \ No newline at end of file diff --git a/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts index ccebc20..83ce0c7 100644 --- a/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts +++ b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.ts @@ -13,8 +13,11 @@ import { MaterialFileInputModule } from 'ngx-material-file-input'; import { MatSelectModule } from '@angular/material/select' import { MatAutocompleteModule } from '@angular/material/autocomplete' +import { MatCardModule } from '@angular/material/card' + @NgModule({ imports: [ + MatCardModule, MatAutocompleteModule, MatSelectModule, MatIconModule, diff --git a/libs/frontend/test-entry/src/lib/routing.module.ts b/libs/frontend/test-entry/src/lib/routing.module.ts index 0fad8ad..2809712 100644 --- a/libs/frontend/test-entry/src/lib/routing.module.ts +++ b/libs/frontend/test-entry/src/lib/routing.module.ts @@ -2,9 +2,10 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { CreateTestEntryComponent } from './components/create-test-entry/create-test-entry.component'; import { UploadService } from './services/upload.service'; +import { UploadPageComponent } from './containers/upload-page/upload-page.component'; const routes: Routes = [ - { path: 'create-test-entry', component: CreateTestEntryComponent }, + { path: 'create', component: UploadPageComponent }, ]; @NgModule({ imports: [RouterModule.forChild(routes)], diff --git a/libs/frontend/test-entry/src/lib/services/upload.service.ts b/libs/frontend/test-entry/src/lib/services/upload.service.ts index 680b804..36d7e02 100644 --- a/libs/frontend/test-entry/src/lib/services/upload.service.ts +++ b/libs/frontend/test-entry/src/lib/services/upload.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { HttpClient, HttpEventType, HttpResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class UploadService { @@ -10,6 +10,6 @@ export class UploadService { } public getSamples() { - return this.http.get('api/samples') + return this.http.get('api/samples'); } } From 1613b6ced369c87329fca79e952d2f8848711a11 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Fri, 28 Aug 2020 13:18:07 +0600 Subject: [PATCH 08/15] feat(api): added the generation of the xml files, when admin adds the test entry --- apps/api/src/app/app.module.ts | 14 +-- .../api-implementation-test-entry.module.ts | 3 +- .../src/lib/test-entry.controller.ts | 9 +- libs/api-implementation/xml/src/index.ts | 1 + .../src/lib/api-implementation-xml.module.ts | 10 +- .../lib/services/xml-generation.service.ts | 93 ++++++++++++++++++- .../xml/src/lib/xml.controller.ts | 19 ++++ 7 files changed, 133 insertions(+), 16 deletions(-) create mode 100644 libs/api-implementation/xml/src/lib/xml.controller.ts diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index ce13081..7d3a96e 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -5,24 +5,24 @@ import { AppController } from './app.controller'; import { VMOrchestrationModule } from '../../../../libs/api-implementation/orchestration/src'; import { ApiImplementationRegressionTestsModule } from '@new-sample-platform/api-implementation/regression-tests'; import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; -import { ApiImplementationSamplesModule } from '@new-sample-platform/api-implementation/samples' -import { ApiImplementationReportModule } from '@new-sample-platform/api-implementation/report' -import { ApiImplementationTestEntryModule } from '@new-sample-platform/api-implementation/test-entry' +import { ApiImplementationSamplesModule } from '@new-sample-platform/api-implementation/samples'; +import { ApiImplementationReportModule } from '@new-sample-platform/api-implementation/report'; +import { ApiImplementationTestEntryModule } from '@new-sample-platform/api-implementation/test-entry'; +import { ApiImplementationXmlModule } from '@new-sample-platform/api-implementation/xml'; import { HttpAdapterHost } from '@nestjs/core'; @Module({ imports: [ HttpAdapterHost, VMOrchestrationModule, + ApiImplementationXmlModule, ApiImplementationTestEntryModule, ApiImplementationReportModule, ApiImplementationRegressionTestsModule, ApiImplementationDatabaseModule, - ApiImplementationSamplesModule + ApiImplementationSamplesModule, ], controllers: [AppController], providers: [], }) -export class AppModule { -} - +export class AppModule {} diff --git a/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts b/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts index 688a5ce..facb66f 100644 --- a/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts +++ b/libs/api-implementation/test-entry/src/lib/api-implementation-test-entry.module.ts @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common'; import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; import { TestEntryController } from './test-entry.controller'; import { TestEntryService } from './services/test-entry.service'; +import { ApiImplementationXmlModule } from '@new-sample-platform/api-implementation/xml'; @Module({ - imports: [ApiImplementationDatabaseModule], + imports: [ApiImplementationDatabaseModule, ApiImplementationXmlModule], controllers: [TestEntryController], providers: [TestEntryService], exports: [], diff --git a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts index 9d719cf..ee91ac2 100644 --- a/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts +++ b/libs/api-implementation/test-entry/src/lib/test-entry.controller.ts @@ -9,10 +9,14 @@ import { import { TestEntryDTO } from './dto/test-entry.dto'; import { TestEntryService } from './services/test-entry.service'; import { AnyFilesInterceptor } from '@nestjs/platform-express'; +import { XmlGenerationService } from '@new-sample-platform/api-implementation/xml'; @Controller('test-entry') export class TestEntryController { - constructor(private service: TestEntryService) {} + constructor( + private service: TestEntryService, + private xmlService: XmlGenerationService + ) {} @UseInterceptors(AnyFilesInterceptor()) @Post() @@ -21,12 +25,13 @@ export class TestEntryController { @Body() testEntryDTO: TestEntryDTO ) { try { - this.service.create( + await this.service.create( testEntryDTO.category, testEntryDTO.command, testEntryDTO.sample, files ); + await this.xmlService.generateXML(); } catch (error) { return `Error creating the test entry`; } diff --git a/libs/api-implementation/xml/src/index.ts b/libs/api-implementation/xml/src/index.ts index 2272a0e..ba1916c 100644 --- a/libs/api-implementation/xml/src/index.ts +++ b/libs/api-implementation/xml/src/index.ts @@ -1 +1,2 @@ export * from './lib/api-implementation-xml.module'; +export * from './lib/services/xml-generation.service' \ No newline at end of file diff --git a/libs/api-implementation/xml/src/lib/api-implementation-xml.module.ts b/libs/api-implementation/xml/src/lib/api-implementation-xml.module.ts index 5ccd23e..7c37d2b 100644 --- a/libs/api-implementation/xml/src/lib/api-implementation-xml.module.ts +++ b/libs/api-implementation/xml/src/lib/api-implementation-xml.module.ts @@ -1,8 +1,12 @@ import { Module } from '@nestjs/common'; +import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; +import { XMLController } from './xml.controller'; +import { XmlGenerationService } from './services/xml-generation.service'; @Module({ - controllers: [], - providers: [], - exports: [], + imports: [ApiImplementationDatabaseModule], + controllers: [XMLController], + providers: [XmlGenerationService], + exports: [XmlGenerationService], }) export class ApiImplementationXmlModule {} diff --git a/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts b/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts index e44352d..99a1183 100644 --- a/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts +++ b/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts @@ -1,10 +1,97 @@ -import { } from 'xmlbuilder' +import * as builder from 'xmlbuilder'; import { Injectable } from '@nestjs/common'; +import { writeFileSync } from 'fs'; + +import { TestEntryModel } from '../../../../models/test-entries/test-entry.models'; +import { AppConfig } from 'config'; +import * as xmlbuilder from 'xmlbuilder'; @Injectable() export class XmlGenerationService { - - constructor() { + private categories = [ + 'broken', + 'cea-708', + 'dvb', + 'dvd', + 'dvr-ms', + 'general', + 'hauppage', + 'mp4', + 'nocc', + 'options', + 'teletext', + 'wtv', + 'xds', + ]; + + constructor() {} + + async generateXML() { + let multitest: any = { + multitest: { + testfile: [], + }, + }; + await Promise.all( + this.categories.map(async (category) => { + const numOfEntries = await this.buildXML(category); + + if (numOfEntries > 0) { + multitest.multitest.testfile.push({ + location: category + '.xml', + }); + } + }) + ); + multitest = builder.create(multitest, { encoding: 'utf-8' }); + writeFileSync( + AppConfig.PATH_TO_MOUNTED_BUCKET + '/xml/tests.xml', + multitest.end({ pretty: true }) + ); } + private async buildXML(category: string) { + let xml: any = { + tests: { + entry: [], + }, + }; + let entries: any[]; + + entries = await TestEntryModel.find({ + category: category, + }); + + for (const entry of entries) { + xml.tests.entry.push({ + '@id': entry._id, + command: entry.command, + input: { + '@type': 'file', + '#text': entry.sample, + }, + output: 'file', + compare: { + file: { + '@ignore': 'false', + '@id': entry.sample, + correct: 'wrong.txt', + expected: + entry.sample.split('.')[0] + + '.' + + entry.correctFiles[0].filename.split('.')[1], + }, + }, + }); + } + + xml = builder.create(xml, { encoding: 'utf-8' }); + + writeFileSync( + AppConfig.PATH_TO_MOUNTED_BUCKET + '/xml/' + category + '.xml', + xml.end({ pretty: true }) + ); + + return entries.length; + } } diff --git a/libs/api-implementation/xml/src/lib/xml.controller.ts b/libs/api-implementation/xml/src/lib/xml.controller.ts new file mode 100644 index 0000000..29446f1 --- /dev/null +++ b/libs/api-implementation/xml/src/lib/xml.controller.ts @@ -0,0 +1,19 @@ +import { + Controller, + Get, +} from '@nestjs/common'; +import { XmlGenerationService } from './services/xml-generation.service'; + +@Controller('xml') +export class XMLController { + constructor(private service: XmlGenerationService) {} + + @Get() + getAllSampleNames() { + try { + this.service.generateXML(); + } catch (error) { + return 'Error while fetching sample names'; + } + } +} From dab35fc0b95c23218b218dcef49ca55c93525084 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Sun, 30 Aug 2020 15:40:00 +0600 Subject: [PATCH 09/15] feat(api): comparision of files in report handler --- .../regression-test.models.ts | 11 +- .../models/test-entries/test-entry.schema.ts | 90 +++++++------ .../models/test-entries/test-entry.types.ts | 2 +- .../models/test-run/test-run.models.ts | 7 + .../models/test-run/test-run.schema.ts | 32 +++++ .../models/test-run/test-run.types.ts | 11 ++ .../lib/api-implementation-report.module.ts | 6 +- .../report/src/lib/report.controller.ts | 30 ++++- .../report/src/lib/services/report.service.ts | 122 ++++++++++++++++++ .../lib/services/xml-generation.service.ts | 2 +- package-lock.json | 10 +- package.json | 3 + 12 files changed, 274 insertions(+), 52 deletions(-) create mode 100644 libs/api-implementation/models/test-run/test-run.models.ts create mode 100644 libs/api-implementation/models/test-run/test-run.schema.ts create mode 100644 libs/api-implementation/models/test-run/test-run.types.ts create mode 100644 libs/api-implementation/report/src/lib/services/report.service.ts diff --git a/libs/api-implementation/models/regression-tests/regression-test.models.ts b/libs/api-implementation/models/regression-tests/regression-test.models.ts index 122e0db..76acbe2 100644 --- a/libs/api-implementation/models/regression-tests/regression-test.models.ts +++ b/libs/api-implementation/models/regression-tests/regression-test.models.ts @@ -1,4 +1,7 @@ -import { model } from "mongoose"; -import { IRegressionTestDocument } from "./regression-test.types"; -import RegressionTestSchema from "./regression-test.schema"; -export const RegressionTestModel:model = model("regression-test", RegressionTestSchema); +import { model } from 'mongoose'; +import { IRegressionTestDocument } from './regression-test.types'; +import RegressionTestSchema from './regression-test.schema'; +export const RegressionTestModel: model = model( + 'regression-test', + RegressionTestSchema +); diff --git a/libs/api-implementation/models/test-entries/test-entry.schema.ts b/libs/api-implementation/models/test-entries/test-entry.schema.ts index e764c7d..431f97e 100644 --- a/libs/api-implementation/models/test-entries/test-entry.schema.ts +++ b/libs/api-implementation/models/test-entries/test-entry.schema.ts @@ -1,44 +1,54 @@ +import * as mongoose from 'mongoose'; import { Schema } from 'mongoose'; +import * as mongoose_sequence from 'mongoose-sequence'; -const TestEntrySchema = new Schema({ - category: { - type: String, - enum: [ - 'broken', - 'cea-708', - 'dvb', - 'dvd', - 'dvr-ms', - 'general', - 'hauppage', - 'mp4', - 'nocc', - 'options', - 'teletext', - 'wtv', - 'xds', - ], - required: true, - }, - correctFiles: { - type: [Object], - required: true, - }, - sample: { - type: String, - required: true, - }, - command: { - type: String, - required: true, - }, - dateOfEntry: { - type: Date, - default: new Date(), - }, - lastUpdated: { - type: Date, - default: new Date(), +const AutoIncrement = mongoose_sequence(mongoose); + +const TestEntrySchema = new Schema( + { + _id: Number, + category: { + type: String, + enum: [ + 'broken', + 'cea-708', + 'dvb', + 'dvd', + 'dvr-ms', + 'general', + 'hauppage', + 'mp4', + 'nocc', + 'options', + 'teletext', + 'wtv', + 'xds', + ], + required: true, + }, + correctFiles: { + type: [Object], + required: true, + }, + sample: { + type: String, + required: true, + }, + command: { + type: String, + required: true, + }, + dateOfEntry: { + type: Date, + default: new Date(), + }, + lastUpdated: { + type: Date, + default: new Date(), + }, }, -}); + { _id: false } +); + +TestEntrySchema.plugin(AutoIncrement); export default TestEntrySchema; diff --git a/libs/api-implementation/models/test-entries/test-entry.types.ts b/libs/api-implementation/models/test-entries/test-entry.types.ts index 47cc0d1..1f6e50e 100644 --- a/libs/api-implementation/models/test-entries/test-entry.types.ts +++ b/libs/api-implementation/models/test-entries/test-entry.types.ts @@ -2,7 +2,7 @@ import { Document, Model } from "mongoose"; export interface ITestEntry { category: string; - correctFiles: Buffer[]; + correctFiles: Object[]; command: string; sample: string; dateOfEntry?: Date; diff --git a/libs/api-implementation/models/test-run/test-run.models.ts b/libs/api-implementation/models/test-run/test-run.models.ts new file mode 100644 index 0000000..479b670 --- /dev/null +++ b/libs/api-implementation/models/test-run/test-run.models.ts @@ -0,0 +1,7 @@ +import { model } from 'mongoose'; +import { ITestRunDocument } from './test-run.types'; +import TestRunSchema from './test-run.schema'; +export const TestRunModel: model = model( + 'test-run', + TestRunSchema +); diff --git a/libs/api-implementation/models/test-run/test-run.schema.ts b/libs/api-implementation/models/test-run/test-run.schema.ts new file mode 100644 index 0000000..73ea05f --- /dev/null +++ b/libs/api-implementation/models/test-run/test-run.schema.ts @@ -0,0 +1,32 @@ +import { Schema } from 'mongoose'; + +const TestRunSchema = new Schema({ + githubNumber: { + type: Number, + required: true, + }, + results: [ + { + id: { + type: Number, + required: true, + }, + success: { + type: Boolean, + required: true, + }, + runTime: Number, + exitCode: Number, + }, + ], + dateOfEntry: { + type: Date, + default: new Date(), + }, + lastUpdated: { + type: Date, + default: new Date(), + }, +}); + +export default TestRunSchema; diff --git a/libs/api-implementation/models/test-run/test-run.types.ts b/libs/api-implementation/models/test-run/test-run.types.ts new file mode 100644 index 0000000..7df50b2 --- /dev/null +++ b/libs/api-implementation/models/test-run/test-run.types.ts @@ -0,0 +1,11 @@ +import { Document, Model } from 'mongoose'; + +export interface ITestRun { + githubNumber: Number; + results: Object[]; + dateOfEntry?: Date; + lastUpdated?: Date; +} + +export interface ITestRunDocument extends ITestRun, Document {} +export interface ITestRunModel extends Model {} diff --git a/libs/api-implementation/report/src/lib/api-implementation-report.module.ts b/libs/api-implementation/report/src/lib/api-implementation-report.module.ts index 154c506..07bb0bd 100644 --- a/libs/api-implementation/report/src/lib/api-implementation-report.module.ts +++ b/libs/api-implementation/report/src/lib/api-implementation-report.module.ts @@ -2,11 +2,13 @@ import { Module, HttpModule } from '@nestjs/common'; import { ReportController } from './report.controller'; import { HttpAdapterHost } from '@nestjs/core'; +import { ReportService } from './services/report.service'; +import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database' @Module({ - imports: [HttpAdapterHost], + imports: [HttpAdapterHost, ApiImplementationDatabaseModule], controllers: [ReportController], - providers: [], + providers: [ReportService], exports: [], }) export class ApiImplementationReportModule {} diff --git a/libs/api-implementation/report/src/lib/report.controller.ts b/libs/api-implementation/report/src/lib/report.controller.ts index 5268efe..81df17c 100644 --- a/libs/api-implementation/report/src/lib/report.controller.ts +++ b/libs/api-implementation/report/src/lib/report.controller.ts @@ -7,14 +7,38 @@ import { } from '@nestjs/common'; import { AnyFilesInterceptor } from '@nestjs/platform-express'; +import { ReportService } from './services/report.service'; @Controller('report') export class ReportController { - constructor() {} + constructor(private service: ReportService) {} @Post() @UseInterceptors(AnyFilesInterceptor()) - async processReport(@UploadedFiles() files, @Body() body) { - console.log(files, body); + async processReport(@UploadedFiles() files: any[], @Body() body) { + try { + const githubNumberPlaceholder = 42; + + if (body.type === 'upload') { + const isSuccess = await this.service.fileIsCorrect( + files[0], + body.test_id + ); + await this.service.createResult( + Number(body.test_id), + isSuccess, + githubNumberPlaceholder + ); + } else if (body.type === 'finish') { + await this.service.updateResult( + Number(body.test_id), + Number(body.runTime), + Number(body.exitCode), + githubNumberPlaceholder + ); + } + } catch (error) { + return 'Error while processing the report'; + } } } diff --git a/libs/api-implementation/report/src/lib/services/report.service.ts b/libs/api-implementation/report/src/lib/services/report.service.ts new file mode 100644 index 0000000..e526860 --- /dev/null +++ b/libs/api-implementation/report/src/lib/services/report.service.ts @@ -0,0 +1,122 @@ +import { Injectable } from '@nestjs/common'; +import { TestEntryModel } from '../../../../models/test-entries/test-entry.models'; +import { TestRunModel } from '../../../../models/test-run/test-run.models'; +import * as crypto from 'crypto'; + +@Injectable() +export class ReportService { + private sha256(data: string | Buffer | DataView) { + return crypto.createHash('sha256').update(data, 'utf8').digest('base64'); + } + + async fileIsCorrect(file: { buffer: Buffer }, test_id: string) { + try { + const testEntry = await TestEntryModel.findOne({ + _id: test_id, + }); + + const fileHash = this.sha256(file.buffer); + + for (const file of testEntry.correctFiles) { + if (fileHash === this.sha256(file.buffer.buffer)) { + return true; + } + } + + return false; + } catch (error) { + console.error('Error while comparing the hash of files'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + throw error; + } + } + + async createResult( + test_id: number, + isSuccess: boolean, + githubNumber: number + ) { + try { + const currentTestRun = await this.getTestRun(githubNumber); + if (currentTestRun) { + await this.addToTestRun(currentTestRun, test_id, isSuccess); + } else { + await this.createTestRun(githubNumber, test_id, isSuccess); + } + } catch (error) { + console.error('Error while creating the rest run instance'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + throw error; + } + } + + async updateResult( + test_id: number, + runTime: number, + exitCode: number, + githubNumber: number + ) { + try { + const currentTestRun = await this.getTestRun(githubNumber); + const indexOfTest = currentTestRun.results.findIndex( + (result) => result.id === test_id + ); + + currentTestRun.results[indexOfTest].runTime = runTime; + currentTestRun.results[indexOfTest].exitCode = exitCode; + await this.updateTestRun(githubNumber, currentTestRun); + } catch (error) { + console.error('Error while updating the test run instance'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + throw error; + } + } + + private async updateTestRun(githubNumber, testRun) { + await TestRunModel.findOneAndUpdate( + { githubNumber: githubNumber }, + testRun, + { upsert: true } + ); + } + + private async addToTestRun(currentTestRun, test_id, isSuccess) { + currentTestRun.results.push({ + id: test_id, + success: isSuccess, + }); + await TestRunModel.findOneAndUpdate( + { + githubNumber: currentTestRun.githubNumber, + }, + { + results: currentTestRun.results, + } + ); + } + + private async createTestRun( + githubNumber: number, + test_id: number, + isSuccess: boolean + ) { + await TestRunModel.create({ + githubNumber: githubNumber, + results: [ + { + id: test_id, + success: isSuccess, + }, + ], + }); + } + + private async getTestRun(githubNumber) { + return await TestRunModel.findOne({ + githubNumber: githubNumber, + }); + } +} diff --git a/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts b/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts index 99a1183..b2a7d61 100644 --- a/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts +++ b/libs/api-implementation/xml/src/lib/services/xml-generation.service.ts @@ -74,7 +74,7 @@ export class XmlGenerationService { compare: { file: { '@ignore': 'false', - '@id': entry.sample, + '@id': entry._id, correct: 'wrong.txt', expected: entry.sample.split('.')[0] + diff --git a/package-lock.json b/package-lock.json index 2012656..ce327d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5004,7 +5004,6 @@ "version": "2.6.3", "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", - "dev": true, "requires": { "lodash": "^4.17.14" } @@ -12520,6 +12519,15 @@ "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==" }, + "mongoose-sequence": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/mongoose-sequence/-/mongoose-sequence-5.2.2.tgz", + "integrity": "sha512-gtN33C4fXVgOH8SSQvwSf8+DcFtxw1n/Wk1RHEs+W3A/cqYgLjvjMalq/0q/TDboeapNi6RBymBnyw3fDoaDlg==", + "requires": { + "async": "^2.5.0", + "lodash": "^4.17.11" + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/package.json b/package.json index ee5220d..710dc90 100644 --- a/package.json +++ b/package.json @@ -52,11 +52,14 @@ "bootstrap": "^4.4.0", "connect-multiparty": "^2.2.0", "core-js": "^2.5.4", + "crypto": "^1.0.1", "doasync": "^2.0.1", "express-fileupload": "^1.2.0", "formidable": "^1.2.2", + "hash-files": "^1.1.1", "mongodb": "^3.5.8", "mongoose": "^5.9.26", + "mongoose-sequence": "^5.2.2", "ngx-material-file-input": "^2.1.1", "reflect-metadata": "^0.1.13", "request": "^2.88.2", From dd20fe283cd3506353f2db2c400ffc4818fa220c Mon Sep 17 00:00:00 2001 From: zelzhan Date: Mon, 31 Aug 2020 00:17:35 +0600 Subject: [PATCH 10/15] feat(api): added type of test run and id of the test to the report handler --- apps/api/src/app/app.module.ts | 2 ++ .../models/test-run/test-run.schema.ts | 9 +++++- .../src/lib/dto/create-machine.dto.ts | 10 +++++++ .../interfaces/vm-orchestration-interface.ts | 27 +++++++++--------- .../src/lib/orchestration.controller.ts | 5 +++- .../services/orchestration.service.spec.ts | 28 +++++++++---------- .../report/src/lib/report.controller.ts | 14 ++++++---- .../report/src/lib/services/report.service.ts | 13 +++++---- libs/api-implementation/test-run/README.md | 7 +++++ .../test-run/jest.config.js | 10 +++++++ libs/api-implementation/test-run/src/index.ts | 1 + .../lib/api-implementation-test-run.module.ts | 12 ++++++++ .../src/lib/services/test-run.service.ts | 15 ++++++++++ .../test-run/src/lib/test-run.controller.ts | 16 +++++++++++ .../api-implementation/test-run/tsconfig.json | 8 ++++++ .../test-run/tsconfig.lib.json | 12 ++++++++ .../test-run/tsconfig.spec.json | 15 ++++++++++ libs/api-implementation/test-run/tslint.json | 5 ++++ 18 files changed, 169 insertions(+), 40 deletions(-) create mode 100644 libs/api-implementation/test-run/README.md create mode 100644 libs/api-implementation/test-run/jest.config.js create mode 100644 libs/api-implementation/test-run/src/index.ts create mode 100644 libs/api-implementation/test-run/src/lib/api-implementation-test-run.module.ts create mode 100644 libs/api-implementation/test-run/src/lib/services/test-run.service.ts create mode 100644 libs/api-implementation/test-run/src/lib/test-run.controller.ts create mode 100644 libs/api-implementation/test-run/tsconfig.json create mode 100644 libs/api-implementation/test-run/tsconfig.lib.json create mode 100644 libs/api-implementation/test-run/tsconfig.spec.json create mode 100644 libs/api-implementation/test-run/tslint.json diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 7d3a96e..e10b977 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -9,12 +9,14 @@ import { ApiImplementationSamplesModule } from '@new-sample-platform/api-impleme import { ApiImplementationReportModule } from '@new-sample-platform/api-implementation/report'; import { ApiImplementationTestEntryModule } from '@new-sample-platform/api-implementation/test-entry'; import { ApiImplementationXmlModule } from '@new-sample-platform/api-implementation/xml'; +import { ApiImplementationTestRunModule } from '@new-sample-platform/api-implementation/test-run'; import { HttpAdapterHost } from '@nestjs/core'; @Module({ imports: [ HttpAdapterHost, VMOrchestrationModule, + ApiImplementationTestRunModule, ApiImplementationXmlModule, ApiImplementationTestEntryModule, ApiImplementationReportModule, diff --git a/libs/api-implementation/models/test-run/test-run.schema.ts b/libs/api-implementation/models/test-run/test-run.schema.ts index 73ea05f..e81d13a 100644 --- a/libs/api-implementation/models/test-run/test-run.schema.ts +++ b/libs/api-implementation/models/test-run/test-run.schema.ts @@ -2,9 +2,16 @@ import { Schema } from 'mongoose'; const TestRunSchema = new Schema({ githubNumber: { - type: Number, + type: String, required: true, }, + + type: { + type: String, + enum: ['Commit', 'Pull Request'], + required: true, + }, + results: [ { id: { diff --git a/libs/api-implementation/orchestration/src/lib/dto/create-machine.dto.ts b/libs/api-implementation/orchestration/src/lib/dto/create-machine.dto.ts index 708c6e2..6d1069f 100644 --- a/libs/api-implementation/orchestration/src/lib/dto/create-machine.dto.ts +++ b/libs/api-implementation/orchestration/src/lib/dto/create-machine.dto.ts @@ -1,3 +1,13 @@ +import { IsEnum } from 'class-validator'; + +export enum Type { + PullRequest = 'PullRequest', + Commit = 'Commit', +} + export class CreateMachineDTO { name: string; + + @IsEnum(Type) + type: Type; } diff --git a/libs/api-implementation/orchestration/src/lib/interfaces/vm-orchestration-interface.ts b/libs/api-implementation/orchestration/src/lib/interfaces/vm-orchestration-interface.ts index 02303b8..930985f 100644 --- a/libs/api-implementation/orchestration/src/lib/interfaces/vm-orchestration-interface.ts +++ b/libs/api-implementation/orchestration/src/lib/interfaces/vm-orchestration-interface.ts @@ -1,23 +1,22 @@ -import { VMInterface } from "../../../../util/src/lib/interfaces/vm-interface"; +import { VMInterface } from '../../../../util/src/lib/interfaces/vm-interface'; +import { Type } from '../dto/create-machine.dto'; export interface VMOrchestrationInterface { - - createMachine(name: string): void; - + createMachine(name: string, type: Type): void; + reset(name: string): void; - + start(name: string): void; - + stop(name: string): void; - + deleteMachine(name: string): void; - - getNumberOfRunningInstances(): number - getNumberOfTotalInstances(): number + getNumberOfRunningInstances(): number; + + getNumberOfTotalInstances(): number; - getRunningInstances(): VMInterface[] + getRunningInstances(): VMInterface[]; - getAllInstances(): VMInterface[] -} - \ No newline at end of file + getAllInstances(): VMInterface[]; +} diff --git a/libs/api-implementation/orchestration/src/lib/orchestration.controller.ts b/libs/api-implementation/orchestration/src/lib/orchestration.controller.ts index 21d95f8..94158d5 100644 --- a/libs/api-implementation/orchestration/src/lib/orchestration.controller.ts +++ b/libs/api-implementation/orchestration/src/lib/orchestration.controller.ts @@ -9,7 +9,10 @@ export class VMOrchestrationController { @Post('create') async createMachine(@Body() createMachineDTO: CreateMachineDTO) { try { - await this.orchestrationService.createMachine(createMachineDTO.name); + await this.orchestrationService.createMachine( + createMachineDTO.name, + createMachineDTO.type + ); return `Machine ${createMachineDTO.name} successfuly created`; } catch (error) { return `Error while creating the machine`; diff --git a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.spec.ts b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.spec.ts index 6b86b2a..9d0b1f7 100644 --- a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.spec.ts +++ b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.spec.ts @@ -1,32 +1,32 @@ -import { VMOrchestrationService } from './orchestration.service' -import { CreateMachineDTO } from '../dto/create-machine.dto'; -import { instantiateMocked } from '../../../../../testing/src/lib/testing.util' +import { VMOrchestrationService } from './orchestration.service'; +import { CreateMachineDTO, Type } from '../dto/create-machine.dto'; +import { instantiateMocked } from '../../../../../testing/src/lib/testing.util'; import { Compute } from './compute.service'; - describe('Orchestration service', () => { - const compute = instantiateMocked(Compute) + const compute = instantiateMocked(Compute); let vmOrchestrationService: VMOrchestrationService; beforeEach(() => { vmOrchestrationService = new VMOrchestrationService(compute); - }) - + }); + describe('createMachine', () => { it('should be created', () => { expect(vmOrchestrationService).toBeTruthy(); }); it('should successfully create a machine', async () => { - const createMachineDTO = new CreateMachineDTO(); - createMachineDTO.name = "test"; - - jest.spyOn(vmOrchestrationService, 'createVM').mockImplementation((name): any => { - return ["", ""] - }) - await vmOrchestrationService.createMachine('test'); + createMachineDTO.name = 'test'; + + jest + .spyOn(vmOrchestrationService, 'createVM') + .mockImplementation((name): any => { + return ['', '']; + }); + await vmOrchestrationService.createMachine('test', Type.Commit); expect(vmOrchestrationService.createVM).toHaveBeenCalledTimes(1); expect(vmOrchestrationService.getNumberOfRunningInstances()).toEqual(1); diff --git a/libs/api-implementation/report/src/lib/report.controller.ts b/libs/api-implementation/report/src/lib/report.controller.ts index 81df17c..d017779 100644 --- a/libs/api-implementation/report/src/lib/report.controller.ts +++ b/libs/api-implementation/report/src/lib/report.controller.ts @@ -4,6 +4,7 @@ import { UseInterceptors, UploadedFiles, Body, + Query, } from '@nestjs/common'; import { AnyFilesInterceptor } from '@nestjs/platform-express'; @@ -15,10 +16,12 @@ export class ReportController { @Post() @UseInterceptors(AnyFilesInterceptor()) - async processReport(@UploadedFiles() files: any[], @Body() body) { + async processReport( + @UploadedFiles() files: any[], + @Query() query, + @Body() body + ) { try { - const githubNumberPlaceholder = 42; - if (body.type === 'upload') { const isSuccess = await this.service.fileIsCorrect( files[0], @@ -27,14 +30,15 @@ export class ReportController { await this.service.createResult( Number(body.test_id), isSuccess, - githubNumberPlaceholder + query.id, + query.type ); } else if (body.type === 'finish') { await this.service.updateResult( Number(body.test_id), Number(body.runTime), Number(body.exitCode), - githubNumberPlaceholder + query.id ); } } catch (error) { diff --git a/libs/api-implementation/report/src/lib/services/report.service.ts b/libs/api-implementation/report/src/lib/services/report.service.ts index e526860..3c85ace 100644 --- a/libs/api-implementation/report/src/lib/services/report.service.ts +++ b/libs/api-implementation/report/src/lib/services/report.service.ts @@ -35,14 +35,15 @@ export class ReportService { async createResult( test_id: number, isSuccess: boolean, - githubNumber: number + githubNumber: string, + type: string ) { try { const currentTestRun = await this.getTestRun(githubNumber); if (currentTestRun) { await this.addToTestRun(currentTestRun, test_id, isSuccess); } else { - await this.createTestRun(githubNumber, test_id, isSuccess); + await this.createTestRun(githubNumber, test_id, isSuccess, type); } } catch (error) { console.error('Error while creating the rest run instance'); @@ -56,7 +57,7 @@ export class ReportService { test_id: number, runTime: number, exitCode: number, - githubNumber: number + githubNumber: string ) { try { const currentTestRun = await this.getTestRun(githubNumber); @@ -99,12 +100,14 @@ export class ReportService { } private async createTestRun( - githubNumber: number, + githubNumber: string, test_id: number, - isSuccess: boolean + isSuccess: boolean, + type: string ) { await TestRunModel.create({ githubNumber: githubNumber, + type: type, results: [ { id: test_id, diff --git a/libs/api-implementation/test-run/README.md b/libs/api-implementation/test-run/README.md new file mode 100644 index 0000000..3f48193 --- /dev/null +++ b/libs/api-implementation/test-run/README.md @@ -0,0 +1,7 @@ +# api-implementation-test-run + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `ng test api-implementation-test-run` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/api-implementation/test-run/jest.config.js b/libs/api-implementation/test-run/jest.config.js new file mode 100644 index 0000000..77222f7 --- /dev/null +++ b/libs/api-implementation/test-run/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + name: 'api-implementation-test-run', + preset: '../../../jest.config.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]sx?$': 'ts-jest', + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], + coverageDirectory: '../../../coverage/libs/api-implementation/test-run', +}; diff --git a/libs/api-implementation/test-run/src/index.ts b/libs/api-implementation/test-run/src/index.ts new file mode 100644 index 0000000..d000d5d --- /dev/null +++ b/libs/api-implementation/test-run/src/index.ts @@ -0,0 +1 @@ +export * from './lib/api-implementation-test-run.module'; diff --git a/libs/api-implementation/test-run/src/lib/api-implementation-test-run.module.ts b/libs/api-implementation/test-run/src/lib/api-implementation-test-run.module.ts new file mode 100644 index 0000000..6432d36 --- /dev/null +++ b/libs/api-implementation/test-run/src/lib/api-implementation-test-run.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; +import { ApiImplementationDatabaseModule } from '@new-sample-platform/api-implementation/database'; +import { TestRunController } from './test-run.controller'; +import { TestRunService } from './services/test-run.service'; + +@Module({ + imports: [ApiImplementationDatabaseModule], + controllers: [TestRunController], + providers: [TestRunService], + exports: [], +}) +export class ApiImplementationTestRunModule {} diff --git a/libs/api-implementation/test-run/src/lib/services/test-run.service.ts b/libs/api-implementation/test-run/src/lib/services/test-run.service.ts new file mode 100644 index 0000000..5e1c656 --- /dev/null +++ b/libs/api-implementation/test-run/src/lib/services/test-run.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@nestjs/common'; +import { TestRunModel } from '../../../../models/test-run/test-run.models'; + +@Injectable() +export class TestRunService { + async getAll() { + try { + return await TestRunModel.find({}); + } catch (error) { + console.error('Error while fetching the test entries'); + // tslint:disable-next-line: no-console + console.debug(error.stack); + } + } +} diff --git a/libs/api-implementation/test-run/src/lib/test-run.controller.ts b/libs/api-implementation/test-run/src/lib/test-run.controller.ts new file mode 100644 index 0000000..6003600 --- /dev/null +++ b/libs/api-implementation/test-run/src/lib/test-run.controller.ts @@ -0,0 +1,16 @@ +import { Controller, Get } from '@nestjs/common'; +import { TestRunService } from './services/test-run.service'; + +@Controller('test-run') +export class TestRunController { + constructor(private service: TestRunService) {} + + @Get() + async getAllTestRuns() { + try { + return await this.service.getAll(); + } catch (error) { + return `Error while fetching the regression tests`; + } + } +} diff --git a/libs/api-implementation/test-run/tsconfig.json b/libs/api-implementation/test-run/tsconfig.json new file mode 100644 index 0000000..e65708f --- /dev/null +++ b/libs/api-implementation/test-run/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"], + "target": "es6" + }, + "include": ["**/*.ts"] +} diff --git a/libs/api-implementation/test-run/tsconfig.lib.json b/libs/api-implementation/test-run/tsconfig.lib.json new file mode 100644 index 0000000..9c463b5 --- /dev/null +++ b/libs/api-implementation/test-run/tsconfig.lib.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../../dist/out-tsc", + "declaration": true, + "rootDir": "./src", + "types": ["node"] + }, + "exclude": ["**/*.spec.ts"], + "include": ["**/*.ts"] +} diff --git a/libs/api-implementation/test-run/tsconfig.spec.json b/libs/api-implementation/test-run/tsconfig.spec.json new file mode 100644 index 0000000..1798b37 --- /dev/null +++ b/libs/api-implementation/test-run/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts" + ] +} diff --git a/libs/api-implementation/test-run/tslint.json b/libs/api-implementation/test-run/tslint.json new file mode 100644 index 0000000..2cdd298 --- /dev/null +++ b/libs/api-implementation/test-run/tslint.json @@ -0,0 +1,5 @@ +{ + "extends": "../../../tslint.json", + "linterOptions": { "exclude": ["!**/*"] }, + "rules": {} +} From 653ba1c4a79fe5c26d15c05bbc527857a2990e3b Mon Sep 17 00:00:00 2001 From: zelzhan Date: Mon, 31 Aug 2020 00:18:17 +0600 Subject: [PATCH 11/15] feat(api): now generated vm can communicate with the orchestration machine --- .../src/lib/services/orchestration.service.ts | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts index 460f8b3..22ec738 100644 --- a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts +++ b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts @@ -5,10 +5,11 @@ import { Injectable } from '@nestjs/common'; import { HashTable } from '../../../../util/src/lib/interfaces/hashtable-interface'; import { VM } from '../../../../util/src/lib/vm.impl'; import { Status } from '../../../../util/src/lib/interfaces/status-enum'; -import { AppConfig } from '../../../../../../config' +import { AppConfig } from '../../../../../../config'; import * as fs from 'fs'; import * as doAsync from 'doasync'; -import * as path from 'path'; +import * as path from 'path'; +import { Type } from '../dto/create-machine.dto'; @Injectable() export class VMOrchestrationService implements VMOrchestrationInterface { @@ -20,39 +21,48 @@ export class VMOrchestrationService implements VMOrchestrationInterface { constructor(compute: Compute) { this.compute = compute; + //TODO: put the zone in config file this.zone = this.compute.zone('us-central1-c'); this.numOfTotalInstances = 0; this.runningMachines = []; this.machines = {}; } - async createMachine(name: string) { + async createMachine(name: string, type: Type) { try { - const [vm, operation] = await this.createVM(name); + const [vm, operation] = await this.createVM(name, type); this.runningMachines.push(vm); this.numOfTotalInstances++; } catch (error) { - console.error("Error while machine creation:") - console.debug(error.stack) - throw(error) + console.error('Error while machine creation:'); + console.debug(error.stack); + throw error; } } - async createVM(name: string) { + async createVM(name: string, type: Type) { let vm, operation; - const config = await this.getConfigFile(); + const config = await this.getConfigFile(name, type); [vm, operation] = await this.zone.createVM(name, config); this.machines[name] = new VM(name, Status.Running, vm); return [this.machines[name], operation]; } - private async getConfigFile() { - - const script = await doAsync(fs).readFile( + private async getConfigFile(name: string, type: Type) { + let script = await doAsync(fs).readFile( //TODO make it more flexible path.resolve(__dirname, `../../../${AppConfig.EXECUTABLE_SCRIPT}`) ); + script = script.toString() + + script = script.replace(/EXTERNAL_IP/g, AppConfig.EXTERNAL_IP) + script = script.replace(/GITHUB_EVENT/g, type) + script = script.replace(/EVENT_IDENTIFICATOR/g, name) + + console.log("HIBLJDAD" + script); + + return return { os: 'ubuntu-1804', http: true, @@ -69,11 +79,11 @@ export class VMOrchestrationService implements VMOrchestrationInterface { async reset(name: string) { try { - const response = await this.machines[name].getInstance().reset(); + await this.machines[name].getInstance().reset(); } catch (error) { - console.error(`Error occured while reseting the machine ${name}`) - console.debug(error.stack) - throw(error) + console.error(`Error occured while reseting the machine ${name}`); + console.debug(error.stack); + throw error; } } @@ -82,9 +92,9 @@ export class VMOrchestrationService implements VMOrchestrationInterface { await this.machines[name].getInstance().start(); this.runningMachines.push(this.machines[name]); } catch (error) { - console.error(`Error occured while starting the machine ${name}`) - console.debug(error.stack) - throw(error) + console.error(`Error occured while starting the machine ${name}`); + console.debug(error.stack); + throw error; } } @@ -99,8 +109,8 @@ export class VMOrchestrationService implements VMOrchestrationInterface { } } catch (error) { console.error(`Error occured while stopping machine`); - console.debug(error.stack) - throw(error) + console.debug(error.stack); + throw error; } } @@ -116,11 +126,11 @@ export class VMOrchestrationService implements VMOrchestrationInterface { await this.machines[name].getInstance().delete(); } catch (error) { console.error(`Error occured while deleting the machine ${name}`); - console.debug(error.stack) - throw(error) + console.debug(error.stack); + throw error; } } - + getNumberOfRunningInstances(): number { return this.runningMachines.length; } From 33a27042c9f517547696cd6eea2cd3191cb2cf36 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Mon, 31 Aug 2020 01:03:04 +0600 Subject: [PATCH 12/15] feat(sample-platform): added library component to list test runs --- angular.json | 61 +++++++++++++++++++ .../sample-platform/src/app/routing.module.ts | 21 ++++--- .../models/test-run/test-run.schema.ts | 10 +-- .../models/test-run/test-run.types.ts | 1 + .../report/src/lib/services/report.service.ts | 2 +- libs/frontend/test-runs/README.md | 7 +++ libs/frontend/test-runs/jest.config.js | 10 +++ libs/frontend/test-runs/src/index.ts | 1 + .../list-test-runs.component.html | 44 +++++++++++++ .../list-test-runs.component.scss | 4 ++ .../list-test-runs.component.spec.ts | 25 ++++++++ .../list-test-runs.component.ts | 24 ++++++++ .../src/lib/frontend-test-runs.module.spec.ts | 14 +++++ .../src/lib/frontend-test-runs.module.ts | 25 ++++++++ .../test-runs/src/lib/routing.module.ts | 10 +++ libs/frontend/test-runs/src/test-setup.ts | 1 + libs/frontend/test-runs/tsconfig.json | 7 +++ libs/frontend/test-runs/tsconfig.lib.json | 17 ++++++ libs/frontend/test-runs/tsconfig.spec.json | 10 +++ libs/frontend/test-runs/tslint.json | 10 +++ nx.json | 6 ++ package-lock.json | 26 ++++++++ package.json | 1 + script.sh | 3 +- tsconfig.json | 6 ++ 25 files changed, 330 insertions(+), 16 deletions(-) create mode 100644 libs/frontend/test-runs/README.md create mode 100644 libs/frontend/test-runs/jest.config.js create mode 100644 libs/frontend/test-runs/src/index.ts create mode 100644 libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.html create mode 100644 libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.scss create mode 100644 libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts create mode 100644 libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts create mode 100644 libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts create mode 100644 libs/frontend/test-runs/src/lib/frontend-test-runs.module.ts create mode 100644 libs/frontend/test-runs/src/lib/routing.module.ts create mode 100644 libs/frontend/test-runs/src/test-setup.ts create mode 100644 libs/frontend/test-runs/tsconfig.json create mode 100644 libs/frontend/test-runs/tsconfig.lib.json create mode 100644 libs/frontend/test-runs/tsconfig.spec.json create mode 100644 libs/frontend/test-runs/tslint.json diff --git a/angular.json b/angular.json index b4b6b6d..6c8a883 100644 --- a/angular.json +++ b/angular.json @@ -620,6 +620,67 @@ "style": "scss" } } + }, + "api-implementation-test-run": { + "root": "libs/api-implementation/test-run", + "sourceRoot": "libs/api-implementation/test-run/src", + "projectType": "library", + "schematics": {}, + "architect": { + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "libs/api-implementation/test-run/tsconfig.lib.json", + "libs/api-implementation/test-run/tsconfig.spec.json" + ], + "exclude": [ + "**/node_modules/**", + "!libs/api-implementation/test-run/**" + ] + } + }, + "test": { + "builder": "@nrwl/jest:jest", + "options": { + "jestConfig": "libs/api-implementation/test-run/jest.config.js", + "tsConfig": "libs/api-implementation/test-run/tsconfig.spec.json", + "passWithNoTests": true + } + } + } + }, + "frontend-test-runs": { + "projectType": "library", + "root": "libs/frontend/test-runs", + "sourceRoot": "libs/frontend/test-runs/src", + "prefix": "frontend", + "architect": { + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "libs/frontend/test-runs/tsconfig.lib.json", + "libs/frontend/test-runs/tsconfig.spec.json" + ], + "exclude": ["**/node_modules/**", "!libs/frontend/test-runs/**"] + } + }, + "test": { + "builder": "@nrwl/jest:jest", + "options": { + "jestConfig": "libs/frontend/test-runs/jest.config.js", + "tsConfig": "libs/frontend/test-runs/tsconfig.spec.json", + "passWithNoTests": true, + "setupFile": "libs/frontend/test-runs/src/test-setup.ts" + } + } + }, + "schematics": { + "@nrwl/angular:component": { + "style": "scss" + } + } } }, "cli": { diff --git a/apps/sample-platform/src/app/routing.module.ts b/apps/sample-platform/src/app/routing.module.ts index 91f39e0..2dfe9ac 100644 --- a/apps/sample-platform/src/app/routing.module.ts +++ b/apps/sample-platform/src/app/routing.module.ts @@ -1,9 +1,5 @@ import { NgModule } from '@angular/core'; -import { - PreloadAllModules, - RouterModule, - Routes, -} from '@angular/router'; +import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; const routes: Routes = [ { @@ -11,22 +7,29 @@ const routes: Routes = [ loadChildren: () => import('@new-sample-platform/frontend/regression-test').then( (mod) => mod.FrontendRegressionTestModule - ) + ), }, { path: 'samples', loadChildren: () => import('@new-sample-platform/frontend/samples').then( (mod) => mod.FrontendSamplesModule - ) + ), }, { path: 'test-entry', loadChildren: () => import('@new-sample-platform/frontend/test-entry').then( (mod) => mod.FrontendTestEntryModule - ) - } + ), + }, + { + path: 'test-runs', + loadChildren: () => + import('@new-sample-platform/frontend/test-runs').then( + (mod) => mod.FrontendTestRunsModule + ), + }, ]; @NgModule({ diff --git a/libs/api-implementation/models/test-run/test-run.schema.ts b/libs/api-implementation/models/test-run/test-run.schema.ts index e81d13a..ebcfde3 100644 --- a/libs/api-implementation/models/test-run/test-run.schema.ts +++ b/libs/api-implementation/models/test-run/test-run.schema.ts @@ -8,20 +8,20 @@ const TestRunSchema = new Schema({ type: { type: String, - enum: ['Commit', 'Pull Request'], + enum: ['Commit', 'PullRequest'], required: true, }, + success: { + type: Boolean, + required: true, + }, results: [ { id: { type: Number, required: true, }, - success: { - type: Boolean, - required: true, - }, runTime: Number, exitCode: Number, }, diff --git a/libs/api-implementation/models/test-run/test-run.types.ts b/libs/api-implementation/models/test-run/test-run.types.ts index 7df50b2..f34f47f 100644 --- a/libs/api-implementation/models/test-run/test-run.types.ts +++ b/libs/api-implementation/models/test-run/test-run.types.ts @@ -3,6 +3,7 @@ import { Document, Model } from 'mongoose'; export interface ITestRun { githubNumber: Number; results: Object[]; + success: Boolean; dateOfEntry?: Date; lastUpdated?: Date; } diff --git a/libs/api-implementation/report/src/lib/services/report.service.ts b/libs/api-implementation/report/src/lib/services/report.service.ts index 3c85ace..d78eab0 100644 --- a/libs/api-implementation/report/src/lib/services/report.service.ts +++ b/libs/api-implementation/report/src/lib/services/report.service.ts @@ -108,10 +108,10 @@ export class ReportService { await TestRunModel.create({ githubNumber: githubNumber, type: type, + success: isSuccess, results: [ { id: test_id, - success: isSuccess, }, ], }); diff --git a/libs/frontend/test-runs/README.md b/libs/frontend/test-runs/README.md new file mode 100644 index 0000000..a4f7002 --- /dev/null +++ b/libs/frontend/test-runs/README.md @@ -0,0 +1,7 @@ +# frontend-test-runs + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test frontend-test-runs` to execute the unit tests. diff --git a/libs/frontend/test-runs/jest.config.js b/libs/frontend/test-runs/jest.config.js new file mode 100644 index 0000000..d0e98a8 --- /dev/null +++ b/libs/frontend/test-runs/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + name: 'frontend-test-runs', + preset: '../../../jest.config.js', + coverageDirectory: '../../../coverage/libs/frontend/test-runs', + snapshotSerializers: [ + 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js', + 'jest-preset-angular/build/AngularSnapshotSerializer.js', + 'jest-preset-angular/build/HTMLCommentSerializer.js', + ], +}; diff --git a/libs/frontend/test-runs/src/index.ts b/libs/frontend/test-runs/src/index.ts new file mode 100644 index 0000000..dedf69b --- /dev/null +++ b/libs/frontend/test-runs/src/index.ts @@ -0,0 +1 @@ +export * from './lib/frontend-test-runs.module'; diff --git a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.html b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.html new file mode 100644 index 0000000..8a5a731 --- /dev/null +++ b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.html @@ -0,0 +1,44 @@ + + + + PR/Commit + {{ element.type }} + + + + + Success + {{ element.success }} + + + + + + Date of Entry + + + + {{ element.dateOfEntry }} + + + + + + Number of used tests + + {{ element.results.length }} + + + + + + diff --git a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.scss b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.scss new file mode 100644 index 0000000..c9c1d67 --- /dev/null +++ b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.scss @@ -0,0 +1,4 @@ +mat-table { + width: 100%; + align-content: center; +} \ No newline at end of file diff --git a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts new file mode 100644 index 0000000..a0922be --- /dev/null +++ b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ListTestRunsComponent } from './list-test-runs.component'; + +describe('ListTestRunsComponent', () => { + let component: ListTestRunsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ListTestRunsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ListTestRunsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts new file mode 100644 index 0000000..147ace7 --- /dev/null +++ b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts @@ -0,0 +1,24 @@ +import { Component, OnInit } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +@Component({ + selector: 'frontend-list-test-runs', + templateUrl: './list-test-runs.component.html', + styleUrls: ['./list-test-runs.component.scss'], +}) +export class ListTestRunsComponent implements OnInit { + displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; + dataSource = []; + + constructor(private http: HttpClient) { + this.getData().subscribe((data: any) => { + this.dataSource = data; + }); + } + + ngOnInit(): void {} + + getData() { + return this.http.get('/api/test-run'); + } +} diff --git a/libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts b/libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts new file mode 100644 index 0000000..970d631 --- /dev/null +++ b/libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts @@ -0,0 +1,14 @@ +import { async, TestBed } from '@angular/core/testing'; +import { FrontendTestRunsModule } from './frontend-test-runs.module'; + +describe('FrontendTestRunsModule', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [FrontendTestRunsModule], + }).compileComponents(); + })); + + it('should create', () => { + expect(FrontendTestRunsModule).toBeDefined(); + }); +}); diff --git a/libs/frontend/test-runs/src/lib/frontend-test-runs.module.ts b/libs/frontend/test-runs/src/lib/frontend-test-runs.module.ts new file mode 100644 index 0000000..562ca9f --- /dev/null +++ b/libs/frontend/test-runs/src/lib/frontend-test-runs.module.ts @@ -0,0 +1,25 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ListTestRunsComponent } from './containers/list-test-runs/list-test-runs.component'; +import { RoutingModule } from './routing.module'; +import { MatTableModule } from '@angular/material/table'; +import { MatInputModule } from '@angular/material/input'; +import { MatIconModule } from '@angular/material/icon'; +import { MatButtonModule } from '@angular/material/button'; +import { FormsModule } from '@angular/forms'; +import { ReactiveFormsModule } from '@angular/forms'; + +@NgModule({ + imports: [ + CommonModule, + RoutingModule, + MatTableModule, + MatInputModule, + MatIconModule, + MatButtonModule, + FormsModule, + ReactiveFormsModule, + ], + declarations: [ListTestRunsComponent], +}) +export class FrontendTestRunsModule {} diff --git a/libs/frontend/test-runs/src/lib/routing.module.ts b/libs/frontend/test-runs/src/lib/routing.module.ts new file mode 100644 index 0000000..69886f0 --- /dev/null +++ b/libs/frontend/test-runs/src/lib/routing.module.ts @@ -0,0 +1,10 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { ListTestRunsComponent } from './containers/list-test-runs/list-test-runs.component'; + +const routes: Routes = [{ path: 'list', component: ListTestRunsComponent }]; +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class RoutingModule {} diff --git a/libs/frontend/test-runs/src/test-setup.ts b/libs/frontend/test-runs/src/test-setup.ts new file mode 100644 index 0000000..8d88704 --- /dev/null +++ b/libs/frontend/test-runs/src/test-setup.ts @@ -0,0 +1 @@ +import 'jest-preset-angular'; diff --git a/libs/frontend/test-runs/tsconfig.json b/libs/frontend/test-runs/tsconfig.json new file mode 100644 index 0000000..08c7db8 --- /dev/null +++ b/libs/frontend/test-runs/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"] + }, + "include": ["**/*.ts"] +} diff --git a/libs/frontend/test-runs/tsconfig.lib.json b/libs/frontend/test-runs/tsconfig.lib.json new file mode 100644 index 0000000..f0e13d4 --- /dev/null +++ b/libs/frontend/test-runs/tsconfig.lib.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "target": "es2015", + "declaration": true, + "inlineSources": true, + "types": [], + "lib": ["dom", "es2018"] + }, + "angularCompilerOptions": { + "skipTemplateCodegen": true, + "strictMetadataEmit": true, + "enableResourceInlining": true + }, + "exclude": ["src/test-setup.ts", "**/*.spec.ts"] +} diff --git a/libs/frontend/test-runs/tsconfig.spec.json b/libs/frontend/test-runs/tsconfig.spec.json new file mode 100644 index 0000000..fd405a6 --- /dev/null +++ b/libs/frontend/test-runs/tsconfig.spec.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "files": ["src/test-setup.ts"], + "include": ["**/*.spec.ts", "**/*.d.ts"] +} diff --git a/libs/frontend/test-runs/tslint.json b/libs/frontend/test-runs/tslint.json new file mode 100644 index 0000000..b205ad0 --- /dev/null +++ b/libs/frontend/test-runs/tslint.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tslint.json", + "rules": { + "directive-selector": [true, "attribute", "frontend", "camelCase"], + "component-selector": [true, "element", "frontend", "kebab-case"] + }, + "linterOptions": { + "exclude": ["!**/*"] + } +} diff --git a/nx.json b/nx.json index 8e13f37..deb650b 100644 --- a/nx.json +++ b/nx.json @@ -76,6 +76,12 @@ }, "frontend-test-entry": { "tags": [] + }, + "api-implementation-test-run": { + "tags": [] + }, + "frontend-test-runs": { + "tags": [] } } } diff --git a/package-lock.json b/package-lock.json index ce327d4..f4a0dee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4432,6 +4432,11 @@ "integrity": "sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==", "dev": true }, + "@types/validator": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.0.0.tgz", + "integrity": "sha512-WAy5txG7aFX8Vw3sloEKp5p/t/Xt8jD3GRD9DacnFv6Vo8ubudAsRTXgxpQwU0mpzY/H8U4db3roDuCMjShBmw==" + }, "@types/webpack-sources": { "version": "0.1.8", "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-0.1.8.tgz", @@ -5973,6 +5978,17 @@ } } }, + "class-validator": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.12.2.tgz", + "integrity": "sha512-TDzPzp8BmpsbPhQpccB3jMUE/3pK0TyqamrK0kcx+ZeFytMA+O6q87JZZGObHHnoo9GM8vl/JppIyKWeEA/EVw==", + "requires": { + "@types/validator": "13.0.0", + "google-libphonenumber": "^3.2.8", + "tslib": ">=1.9.0", + "validator": "13.0.0" + } + }, "clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -9112,6 +9128,11 @@ } } }, + "google-libphonenumber": { + "version": "3.2.12", + "resolved": "https://registry.npmjs.org/google-libphonenumber/-/google-libphonenumber-3.2.12.tgz", + "integrity": "sha512-vuDYnYNlCDQpIo5j7QDJTz2FNVAAuJZtbQ/khZgT6UBuRJV5GVQIQbOAdjTgu2uH4OFVChKAHQl8a2rgMnezOQ==" + }, "google-p12-pem": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-2.0.4.tgz", @@ -17585,6 +17606,11 @@ "builtins": "^1.0.3" } }, + "validator": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.0.0.tgz", + "integrity": "sha512-anYx5fURbgF04lQV18nEQWZ/3wHGnxiKdG4aL8J+jEDsm98n/sU/bey+tYk6tnGJzm7ioh5FoqrAiQ6m03IgaA==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 710dc90..8c62984 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "@nrwl/angular": "9.3.0", "@octokit/auth-app": "^2.4.7", "bootstrap": "^4.4.0", + "class-validator": "^0.12.2", "connect-multiparty": "^2.2.0", "core-js": "^2.5.4", "crypto": "^1.0.1", diff --git a/script.sh b/script.sh index 08f73fe..d88942f 100755 --- a/script.sh +++ b/script.sh @@ -68,5 +68,6 @@ mkdir results mkdir report cd /root/tester -sudo /root/tester/ccextractortester --entries "/root/bucket/tests.xml" --executable "/root/ccextractor" --tempfolder "/root/tmpFiles" --timeout 3000 --resultfolder "/root/results" --samplefolder "/root/bucket/samples" --reportfolder "/root/report" +sudo /root/tester/ccextractortester --method Server --entries "/root/bucket/tests.xml" --executable "/root/ccextractor" --tempfolder "/root/tmpFiles" --timeout 3000 --resultfolder "/root/results" --samplefolder "/root/bucket/samples" --reportfolder "/root/report" -u "EXTERNAL_IP/api/report?type=GITHUB_EVENT&id=EVENT_IDENTIFICATOR" + diff --git a/tsconfig.json b/tsconfig.json index 9b0682f..04332e9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -52,6 +52,12 @@ ], "@new-sample-platform/frontend/test-entry": [ "libs/frontend/test-entry/src/index.ts" + ], + "@new-sample-platform/api-implementation/test-run": [ + "libs/api-implementation/test-run/src/index.ts" + ], + "@new-sample-platform/frontend/test-runs": [ + "libs/frontend/test-runs/src/index.ts" ] } }, From 062bb7e73bb4ee3d2feed00127c1ceece679877a Mon Sep 17 00:00:00 2001 From: zelzhan Date: Mon, 31 Aug 2020 01:57:11 +0600 Subject: [PATCH 13/15] feat(sample-platform): added UI and navbar for basic navigation --- angular.json | 14 +++- .../sample-platform/src/app/app.component.css | 5 ++ .../src/app/app.component.html | 37 ++++++++++ apps/sample-platform/src/app/app.module.ts | 2 + .../src/{styles.css => styles.scss} | 0 config.ts | 3 +- .../frontend-regression-test.module.spec.ts | 14 ---- .../containers/upload/upload.component.html | 6 +- .../containers/upload/upload.component.scss | 6 ++ .../src/lib/frontend-samples.module.ts | 4 +- .../create-test-entry.component.html | 4 +- .../create-test-entry.component.spec.ts | 25 ------- .../lib/frontend-test-entry.module.spec.ts | 14 ---- .../list-test-runs.component.spec.ts | 25 ------- .../src/lib/frontend-test-runs.module.spec.ts | 14 ---- package-lock.json | 72 ++++++++++++++++++- package.json | 6 ++ 17 files changed, 150 insertions(+), 101 deletions(-) rename apps/sample-platform/src/{styles.css => styles.scss} (100%) delete mode 100644 libs/frontend/regression-test/src/lib/frontend-regression-test.module.spec.ts delete mode 100644 libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts delete mode 100644 libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts delete mode 100644 libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts delete mode 100644 libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts diff --git a/angular.json b/angular.json index 6c8a883..dbfc862 100644 --- a/angular.json +++ b/angular.json @@ -24,9 +24,19 @@ "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css", - "apps/sample-platform/src/styles.css" + "apps/sample-platform/src/styles.scss", + "node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss", + "node_modules/@fortawesome/fontawesome-free/scss/solid.scss", + "node_modules/@fortawesome/fontawesome-free/scss/regular.scss", + "node_modules/@fortawesome/fontawesome-free/scss/brands.scss", + "node_modules/angular-bootstrap-md/assets/scss/bootstrap/bootstrap.scss", + "node_modules/angular-bootstrap-md/assets/scss/mdb.scss", + "node_modules/animate.css/animate.css" ], - "scripts": [] + "scripts": [ + "node_modules/chart.js/dist/Chart.js", + "node_modules/hammerjs/hammer.min.js" + ] }, "configurations": { "production": { diff --git a/apps/sample-platform/src/app/app.component.css b/apps/sample-platform/src/app/app.component.css index e69de29..df99981 100644 --- a/apps/sample-platform/src/app/app.component.css +++ b/apps/sample-platform/src/app/app.component.css @@ -0,0 +1,5 @@ +.logo { + /* height: 10%; */ + width: 10%; + /* float: right; */ +} \ No newline at end of file diff --git a/apps/sample-platform/src/app/app.component.html b/apps/sample-platform/src/app/app.component.html index b7c7904..e1b7e9c 100644 --- a/apps/sample-platform/src/app/app.component.html +++ b/apps/sample-platform/src/app/app.component.html @@ -1,3 +1,40 @@ + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/apps/sample-platform/src/app/app.module.ts b/apps/sample-platform/src/app/app.module.ts index 34e18d4..ee9ab06 100644 --- a/apps/sample-platform/src/app/app.module.ts +++ b/apps/sample-platform/src/app/app.module.ts @@ -12,6 +12,7 @@ import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; import { FormsModule } from '@angular/forms'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; +import { MDBBootstrapModule } from 'angular-bootstrap-md'; @NgModule({ declarations: [AppComponent], @@ -27,6 +28,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; MatButtonModule, FormsModule, NgbModule, + MDBBootstrapModule.forRoot(), ], providers: [], bootstrap: [AppComponent], diff --git a/apps/sample-platform/src/styles.css b/apps/sample-platform/src/styles.scss similarity index 100% rename from apps/sample-platform/src/styles.css rename to apps/sample-platform/src/styles.scss diff --git a/config.ts b/config.ts index f349d03..7b7318d 100644 --- a/config.ts +++ b/config.ts @@ -5,5 +5,6 @@ export enum AppConfig { CCEXTRACTOR_REPO_NAME = "ccextractor", CCEXTRACTOR_REPO_OWNER = "zelzhan", MONGO_CONNECTION_STRING = "mongodb://mongo:27017/test", - PATH_TO_MOUNTED_BUCKET = "/path/to/bucket/" + PATH_TO_MOUNTED_BUCKET = "/path/to/bucket/", + EXTERNAL_IP = "http://192.168.0.1:2000" } diff --git a/libs/frontend/regression-test/src/lib/frontend-regression-test.module.spec.ts b/libs/frontend/regression-test/src/lib/frontend-regression-test.module.spec.ts deleted file mode 100644 index 92a1da6..0000000 --- a/libs/frontend/regression-test/src/lib/frontend-regression-test.module.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { async, TestBed } from '@angular/core/testing'; -import { FrontendRegressionTestModule } from './frontend-regression-test.module'; - -describe('FrontendRegressionTestModule', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [FrontendRegressionTestModule], - }).compileComponents(); - })); - - it('should create', () => { - expect(FrontendRegressionTestModule).toBeDefined(); - }); -}); diff --git a/libs/frontend/samples/src/lib/containers/upload/upload.component.html b/libs/frontend/samples/src/lib/containers/upload/upload.component.html index 07898ba..69e46a0 100644 --- a/libs/frontend/samples/src/lib/containers/upload/upload.component.html +++ b/libs/frontend/samples/src/lib/containers/upload/upload.component.html @@ -1 +1,5 @@ - \ No newline at end of file +
+ + Please select samples and wait until the upload is complete + +
diff --git a/libs/frontend/samples/src/lib/containers/upload/upload.component.scss b/libs/frontend/samples/src/lib/containers/upload/upload.component.scss index e69de29..62a0dc4 100644 --- a/libs/frontend/samples/src/lib/containers/upload/upload.component.scss +++ b/libs/frontend/samples/src/lib/containers/upload/upload.component.scss @@ -0,0 +1,6 @@ +.main-div{ + height: 100vh; + display: flex; + justify-content: center; + align-items: center; + } \ No newline at end of file diff --git a/libs/frontend/samples/src/lib/frontend-samples.module.ts b/libs/frontend/samples/src/lib/frontend-samples.module.ts index f7931b1..5315291 100644 --- a/libs/frontend/samples/src/lib/frontend-samples.module.ts +++ b/libs/frontend/samples/src/lib/frontend-samples.module.ts @@ -9,10 +9,12 @@ import { MatListModule } from '@angular/material/list'; import { FlexLayoutModule } from '@angular/flex-layout'; import { DialogComponent } from './components/dialog/dialog.component'; import { UploadService } from './services/upload.service'; +import { MatCardModule } from '@angular/material/card'; @NgModule({ imports: [ CommonModule, + MatCardModule, RoutingModule, MatButtonModule, MatDialogModule, @@ -21,6 +23,6 @@ import { UploadService } from './services/upload.service'; MatProgressBarModule, ], declarations: [UploadComponent, DialogComponent], - providers: [UploadService] + providers: [UploadService], }) export class FrontendSamplesModule {} diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html index a15bad6..19f8881 100644 --- a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html +++ b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.html @@ -37,7 +37,7 @@

Create Test Entry

Create Test Entry
{{f.name}}
- +
diff --git a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts b/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts deleted file mode 100644 index d7f4265..0000000 --- a/libs/frontend/test-entry/src/lib/components/create-test-entry/create-test-entry.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { CreateTestEntryComponent } from './create-test-entry.component'; - -describe('CreateTestEntryComponent', () => { - let component: CreateTestEntryComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ CreateTestEntryComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(CreateTestEntryComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts b/libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts deleted file mode 100644 index df98f84..0000000 --- a/libs/frontend/test-entry/src/lib/frontend-test-entry.module.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { async, TestBed } from '@angular/core/testing'; -import { FrontendTestEntryModule } from './frontend-test-entry.module'; - -describe('FrontendTestEntryModule', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [FrontendTestEntryModule], - }).compileComponents(); - })); - - it('should create', () => { - expect(FrontendTestEntryModule).toBeDefined(); - }); -}); diff --git a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts deleted file mode 100644 index a0922be..0000000 --- a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ListTestRunsComponent } from './list-test-runs.component'; - -describe('ListTestRunsComponent', () => { - let component: ListTestRunsComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ ListTestRunsComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(ListTestRunsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts b/libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts deleted file mode 100644 index 970d631..0000000 --- a/libs/frontend/test-runs/src/lib/frontend-test-runs.module.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { async, TestBed } from '@angular/core/testing'; -import { FrontendTestRunsModule } from './frontend-test-runs.module'; - -describe('FrontendTestRunsModule', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [FrontendTestRunsModule], - }).compileComponents(); - })); - - it('should create', () => { - expect(FrontendTestRunsModule).toBeDefined(); - }); -}); diff --git a/package-lock.json b/package-lock.json index f4a0dee..5d908dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2509,6 +2509,11 @@ } } }, + "@fortawesome/fontawesome-free": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.14.0.tgz", + "integrity": "sha512-OfdMsF+ZQgdKHP9jUbmDcRrP0eX90XXrsXIdyjLbkmSBzmMXPABB8eobUJtivaupucYaByz6WNe1PI1JuYm3qA==" + }, "@google-cloud/common": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@google-cloud/common/-/common-2.4.0.tgz", @@ -4243,6 +4248,14 @@ "integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==", "dev": true }, + "@types/chart.js": { + "version": "2.9.24", + "resolved": "https://registry.npmjs.org/@types/chart.js/-/chart.js-2.9.24.tgz", + "integrity": "sha512-AQI7X+ow3SaONl44JrHoL/5B+lCsJyG31UHZ5RP98Uh15hI/zjEkDsAb4EIm4P9TGfNhZLXw/nMc5w0u10+/fQ==", + "requires": { + "moment": "^2.10.2" + } + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", @@ -4773,6 +4786,16 @@ "integrity": "sha1-l6ERlkmyEa0zaR2fn0hqjsn74KM=", "dev": true }, + "angular-bootstrap-md": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/angular-bootstrap-md/-/angular-bootstrap-md-9.3.1.tgz", + "integrity": "sha512-wQ7BzIce8HLs5tMjUXliHA+ePZFshs+5My/dYZ3imbKMKVbn6OMjEUNGc1q7iInHq+Rr5RHSz7ev8+J+NU/GYw==" + }, + "animate.css": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/animate.css/-/animate.css-4.1.0.tgz", + "integrity": "sha512-0aVcfWDeU9ykV6vjn1P67ZSs01jxoUQZCGaYbkk0SIIelIG8kUdLrIkua1+VabHfTtsSivDRMMn0ILPvZum2gw==" + }, "ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -5899,6 +5922,47 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, + "chart.js": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.5.0.tgz", + "integrity": "sha1-/m51Gok3afVucr7lrZEgfhxZKVc=", + "requires": { + "chartjs-color": "^2.0.0", + "moment": "^2.10.6" + } + }, + "chartjs-color": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.4.1.tgz", + "integrity": "sha512-haqOg1+Yebys/Ts/9bLo/BqUcONQOdr/hoEr2LLTRl6C5LXctUdHxsCYfvQVg5JIxITrfCNUDr4ntqmQk9+/0w==", + "requires": { + "chartjs-color-string": "^0.6.0", + "color-convert": "^1.9.3" + }, + "dependencies": { + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + } + } + }, + "chartjs-color-string": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/chartjs-color-string/-/chartjs-color-string-0.6.0.tgz", + "integrity": "sha512-TIB5OKn1hPJvO7JcteW4WY/63v6KwEdt6udfnDE9iCAZgy+V4SrbSxoIbTw/xkUIapjEI4ExGtD0+6D3KyFd7A==", + "requires": { + "color-name": "^1.0.0" + } + }, "check-more-types": { "version": "2.24.0", "resolved": "https://registry.npmjs.org/check-more-types/-/check-more-types-2.24.0.tgz", @@ -9171,6 +9235,11 @@ } } }, + "hammerjs": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/hammerjs/-/hammerjs-2.0.8.tgz", + "integrity": "sha1-BO93hiz/K7edMPdpIJWTAiK/YPE=" + }, "handle-thing": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/handle-thing/-/handle-thing-2.0.1.tgz", @@ -12481,8 +12550,7 @@ "moment": { "version": "2.24.0", "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==", - "dev": true + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" }, "mongodb": { "version": "3.5.8", diff --git a/package.json b/package.json index 8c62984..250dd22 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@angular/platform-browser-dynamic": "^9.1.0", "@angular/router": "^9.1.0", "@commitlint/config-conventional": "^8.3.4", + "@fortawesome/fontawesome-free": "^5.14.0", "@google-cloud/compute": "^1.2.0", "@nestjs/common": "^6.8.3", "@nestjs/core": "^6.8.3", @@ -49,7 +50,11 @@ "@ng-bootstrap/ng-bootstrap": "^6.2.0", "@nrwl/angular": "9.3.0", "@octokit/auth-app": "^2.4.7", + "@types/chart.js": "^2.9.24", + "angular-bootstrap-md": "^9.3.1", + "animate.css": "^4.1.0", "bootstrap": "^4.4.0", + "chart.js": "^2.5.0", "class-validator": "^0.12.2", "connect-multiparty": "^2.2.0", "core-js": "^2.5.4", @@ -57,6 +62,7 @@ "doasync": "^2.0.1", "express-fileupload": "^1.2.0", "formidable": "^1.2.2", + "hammerjs": "^2.0.8", "hash-files": "^1.1.1", "mongodb": "^3.5.8", "mongoose": "^5.9.26", From a9984781d60d70481e9e2800009e840b270411e8 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Sun, 6 Sep 2020 16:36:00 +0600 Subject: [PATCH 14/15] fix(sample-platform): now sample platform properly outputs whether the run of the tests was successful. --- libs/api-implementation/models/test-run/test-run.schema.ts | 7 +++++-- .../report/src/lib/services/report.service.ts | 2 +- .../containers/list-test-runs/list-test-runs.component.ts | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/api-implementation/models/test-run/test-run.schema.ts b/libs/api-implementation/models/test-run/test-run.schema.ts index ebcfde3..d470808 100644 --- a/libs/api-implementation/models/test-run/test-run.schema.ts +++ b/libs/api-implementation/models/test-run/test-run.schema.ts @@ -12,9 +12,8 @@ const TestRunSchema = new Schema({ required: true, }, - success: { + succeed: { type: Boolean, - required: true, }, results: [ { @@ -22,6 +21,10 @@ const TestRunSchema = new Schema({ type: Number, required: true, }, + success: { + type: Boolean, + required: true, + }, runTime: Number, exitCode: Number, }, diff --git a/libs/api-implementation/report/src/lib/services/report.service.ts b/libs/api-implementation/report/src/lib/services/report.service.ts index d78eab0..1d80470 100644 --- a/libs/api-implementation/report/src/lib/services/report.service.ts +++ b/libs/api-implementation/report/src/lib/services/report.service.ts @@ -108,9 +108,9 @@ export class ReportService { await TestRunModel.create({ githubNumber: githubNumber, type: type, - success: isSuccess, results: [ { + success: isSuccess, id: test_id, }, ], diff --git a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts index 147ace7..2c036d6 100644 --- a/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts +++ b/libs/frontend/test-runs/src/lib/containers/list-test-runs/list-test-runs.component.ts @@ -12,6 +12,10 @@ export class ListTestRunsComponent implements OnInit { constructor(private http: HttpClient) { this.getData().subscribe((data: any) => { + data = data.map((entry) => { + entry.success = entry.results.every((obj) => obj.success); + return entry; + }); this.dataSource = data; }); } From 167d6bfd8996bf7e007a2ee7ac38b94e6faeea96 Mon Sep 17 00:00:00 2001 From: zelzhan Date: Sun, 6 Sep 2020 16:45:14 +0600 Subject: [PATCH 15/15] feat(api): now the vm_zone in the config file. --- config.ts | 3 ++- .../orchestration/src/lib/services/orchestration.service.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config.ts b/config.ts index 7b7318d..c097f5d 100644 --- a/config.ts +++ b/config.ts @@ -6,5 +6,6 @@ export enum AppConfig { CCEXTRACTOR_REPO_OWNER = "zelzhan", MONGO_CONNECTION_STRING = "mongodb://mongo:27017/test", PATH_TO_MOUNTED_BUCKET = "/path/to/bucket/", - EXTERNAL_IP = "http://192.168.0.1:2000" + EXTERNAL_IP = "http://192.168.0.1:2000", + VM_ZONE = "us-central1-c" } diff --git a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts index 22ec738..591f83b 100644 --- a/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts +++ b/libs/api-implementation/orchestration/src/lib/services/orchestration.service.ts @@ -22,7 +22,7 @@ export class VMOrchestrationService implements VMOrchestrationInterface { constructor(compute: Compute) { this.compute = compute; //TODO: put the zone in config file - this.zone = this.compute.zone('us-central1-c'); + this.zone = this.compute.zone(AppConfig.VM_ZONE); this.numOfTotalInstances = 0; this.runningMachines = []; this.machines = {};