Skip to content

Commit

Permalink
The examples are unified on one side
Browse files Browse the repository at this point in the history
  • Loading branch information
manueltais-cp committed Jan 15, 2020
1 parent f69b260 commit 99739f6
Show file tree
Hide file tree
Showing 25 changed files with 203 additions and 645 deletions.
35 changes: 1 addition & 34 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@
"preLaunchTask": "compile",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Tests samples2",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/dist/samples2/tests"
],
"preLaunchTask": "compile",
"internalConsoleOptions": "openOnSessionStart"
},
{
"args": [],
"cwd": "${workspaceRoot}",
Expand All @@ -52,23 +36,6 @@
"sourceMaps": true,
"stopOnEntry": false,
"type": "node"
},
{
"args": [],
"cwd": "${workspaceRoot}",
"externalConsole": false,
"name": "DEBUG samples 2",
"outDir": "${workspaceRoot}/dist",
"program": "${workspaceRoot}/dist/samples2/server.js",
"request": "launch",
"runtimeArgs": [
"--nolazy"
],
"preLaunchTask": "compile",
"runtimeExecutable": null,
"sourceMaps": true,
"stopOnEntry": false,
"type": "node"
},
}
]
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ gulp.task('copy', () => {
});

gulp.task('execute-tests', function () {
return gulp.src(['dist/samples2/tests/*.test.js'], { read: false })
return gulp.src(['dist/samples/tests/*.test.js'], { read: false })
.pipe(mocha({
reporter: 'spec'
}));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"compile": "tsc",
"test-load": "node ./tests/load.test.js",
"test": "tsc && nyc mocha ./dist/samples2/tests && nyc report --reporter=text-lcov | coveralls"
"test": "tsc && nyc mocha ./dist/samples/tests && nyc report --reporter=text-lcov | coveralls"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class TestController {
@Get('/queryparam/:id')
public queryparam(@QueryParam() object: UserModel, @Param('id') id: string, @HeaderParam('token1') token1: string,
@HeaderParam('token2') token2: string) {
this.utils.print();
return object;
}

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Get, Post, Put, JsonController, Param, Body, QueryParam, Authorize, HeaderParam, Delete } from '../../src/index';
import { UserModel } from '../models/models';
import { Get, Post, Put, JsonController, Param, Body, QueryParam, Authorize, HeaderParam, Delete } from '../../../src/index';
import { UserModel } from '../../models/models';
import { isNil } from 'lodash';
import { Utils } from '../utils';
import { Utils } from '../../utils';

@JsonController('/user')
export class UserController {
Expand Down
12 changes: 0 additions & 12 deletions samples/middleware/sampleMiddleware.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IMiddleware } from '../../src/middlewares/middleware';
import { MiddlewareAfter } from '../../src/decorators/middlewareAfter';
import * as http from 'http';

@MiddlewareAfter(1)
@MiddlewareAfter(2)
export class TestMiddleware2 implements IMiddleware{

execute(request: http.IncomingMessage, response: http.ServerResponse, next: any){
Expand Down
12 changes: 8 additions & 4 deletions samples/server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { createKiwiServer, IKiwiOptions, AuthorizeResponse } from '../src/index';
import * as http from 'http';
import { environment } from './environments/environment';
import { UserController } from './user/user-controller';
import { SampleMiddleware } from './middleware/sampleMiddleware';
import { UserController } from './controllers/user/user-controller';
import { TestController } from './controllers/test-controller';
import { TestController2 } from './controllers/test-controller2';
import { TestController3 } from './controllers/test-controller3';
import { TestMiddleware } from './middlewares/test-middlware';
import { TestMiddleware2 } from './middlewares/test-middlware2';

async function validateAuthentication(request: http.IncomingMessage, roles: Array<string>): Promise<AuthorizeResponse | boolean> {
console.log(roles);
return true;
}

const options: IKiwiOptions = {
controllers: [UserController],
controllers: [UserController, TestController, TestController2, TestController3],
authorization: validateAuthentication,
middlewares: [SampleMiddleware],
middlewares: [TestMiddleware2, TestMiddleware],
cors: {
enabled: true,
domains: environment.domains
Expand Down
17 changes: 2 additions & 15 deletions samples/tests/authentication.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { suite, test } from "mocha-typescript";
import { assert } from 'chai';
import { IKiwiOptions, createKiwiServer, processRequest } from '../../src/index';
import { UserController } from '../user/user-controller';
import { SampleMiddleware } from '../middleware/sampleMiddleware';
import { UserController } from '../controllers/user/user-controller';
import { KiwiMetadataStorage } from '../../src/metadata/metadataStorage';
import * as http from 'http';
var sinon = require('sinon');
Expand All @@ -16,7 +15,7 @@ var options: IKiwiOptions = {
callback();
return true;
},
middlewares: [SampleMiddleware],
middlewares: [],
cors: {
enabled: true
},
Expand All @@ -37,18 +36,6 @@ var options: IKiwiOptions = {
before() {
}

// @test async 'It must call validateAuthentication method'() {
// var request = httpMocks.createRequest({
// method: 'GET',
// url: `/v1/testcontroller2/getAction`
// });

// var response = httpMocks.createResponse();
// await processRequest(request, response);
// assert.equal(response.statusCode, 200);
// assert.isTrue(callback.calledOnce);
// }

static after() {

}
Expand Down
Loading

0 comments on commit 99739f6

Please sign in to comment.