Skip to content

Commit ebe8091

Browse files
committed
Fix unit and blackbox tests
1 parent de75ea9 commit ebe8091

File tree

7 files changed

+65
-75
lines changed

7 files changed

+65
-75
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
},
129129
"jest": {
130130
"transform": {
131-
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
131+
".(ts|tsx)": "<rootDir>/test/preprocessor.js"
132132
},
133133
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
134134
"moduleFileExtensions": [

src/console/DatabaseResetCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Logger } from '../core/Logger';
22

33
import * as Knex from 'knex';
44
import { AbstractCommand } from './lib/AbstractCommand';
5-
import * as options from '../../knexfile.ts';
5+
import * as options from './../../knexfile';
66

77
const log = new Logger(__filename);
88

test/black-box/api-info.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { api } from './lib/api';
22

33

44
describe('API-Info', () => {
5-
test('GET /v1/info Should return the api info as a json', async () => {
6-
const res = await api('GET', '/api/v1/info');
5+
test('GET /info Should return the api info as a json', async () => {
6+
const res = await api('GET', '/api/info');
77
res.expectJson();
88
res.expectStatusCode(200);
99

test/black-box/lib/ApiResponeTest.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ export class ApiResponeTest {
66
constructor(private error: any, private res: any) {
77
}
88

9-
getBody<T>(): T {
9+
public getBody<T>(): T {
1010
return this.res['body'];
1111
}
1212

13-
getData<T>(): T {
13+
public getData<T>(): T {
1414
return this.getBody()['data'];
1515
}
1616

17-
getHeaders<T>(): T {
17+
public getHeaders<T>(): T {
1818
if (this.res) {
1919
return this.res['headers'];
2020
} else {
2121
return this.error['response']['headers'];
2222
}
2323
}
2424

25-
expectStatusCode(code: number): ApiResponeTest {
25+
public expectStatusCode(code: number): ApiResponeTest {
2626
if (this.res) {
2727
expect(this.res['statusCode']).toBe(code);
2828
} else {
@@ -31,12 +31,12 @@ export class ApiResponeTest {
3131
return this;
3232
}
3333

34-
expectJson(): ApiResponeTest {
34+
public expectJson(): ApiResponeTest {
3535
expect(this.getHeaders()['content-type']).toContain('json');
3636
return this;
3737
}
3838

39-
expectData(keys: string[]): ApiResponeTest {
39+
public expectData(keys: string[]): ApiResponeTest {
4040
const a = keys.sort();
4141
const d = _.isArray(this.getData()) ? this.getData()[0] : this.getData();
4242
const b = Object.keys(d).sort();
@@ -45,11 +45,11 @@ export class ApiResponeTest {
4545
return this;
4646
}
4747

48-
printResponse(): void {
48+
public printResponse(): void {
4949
console.log(this.res);
5050
}
5151

52-
printError(): void {
52+
public printError(): void {
5353
console.log(this.error);
5454
}
5555

test/black-box/lib/api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
require('dotenv').config();
1+
import * as dotenv from 'dotenv';
2+
dotenv.config();
23
import * as request from 'request-promise';
34
import { Options } from 'request-promise';
45
import { ApiResponeTest } from './ApiResponeTest';
@@ -11,9 +12,9 @@ export interface ApiOptions<T> {
1112
}
1213

1314

14-
export const api = async <T>(method: string, path: string, options: ApiOptions<T> = {}) => {
15+
export const api = async <T> (method: string, path: string, options: ApiOptions<T> = {}) => {
1516
const o: Options = {
16-
method: method,
17+
method,
1718
uri: `${process.env.APP_HOST}:${process.env.APP_PORT}${path}`,
1819
resolveWithFullResponse: true,
1920
headers: options.headers,
@@ -26,7 +27,7 @@ export const api = async <T>(method: string, path: string, options: ApiOptions<T
2627
o.headers['authorization'] = `Bearer ${options.token}`;
2728
}
2829

29-
let res = undefined;
30+
let res;
3031
let error = null;
3132
try {
3233
res = await request(o);

test/black-box/user.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ describe('User', () => {
2929
await createAdminUser();
3030
token = getToken();
3131
auth = {
32-
token: token
32+
token
3333
};
3434
});
3535

36-
test('POST /v1/user Should create a new user', async () => {
37-
const res = await api('POST', '/api/v1/user', {
38-
token: token,
36+
test('POST /users Should create a new user', async () => {
37+
const res = await api('POST', '/api/users', {
38+
token,
3939
body: testUser
4040
});
4141
res.expectJson();
@@ -44,17 +44,17 @@ describe('User', () => {
4444
createdId = res.getData()['id'];
4545
});
4646

47-
test('POST /v1/user Should fail because we want to create a empty user', async () => {
48-
const res = await api('POST', '/api/v1/user', {
49-
token: token,
47+
test('POST /users Should fail because we want to create a empty user', async () => {
48+
const res = await api('POST', '/api/users', {
49+
token,
5050
body: {}
5151
});
5252
res.expectJson();
5353
res.expectStatusCode(400);
5454
});
5555

56-
test('GET /v1/user Should list of users with our new create one', async () => {
57-
const res = await api('GET', '/api/v1/user', auth);
56+
test('GET /users Should list of users with our new create one', async () => {
57+
const res = await api('GET', '/api/users', auth);
5858
res.expectJson();
5959
res.expectStatusCode(200);
6060
res.expectData(userKeys);
@@ -67,8 +67,8 @@ describe('User', () => {
6767
expect(user.email).toBe(testUser.email);
6868
});
6969

70-
test('GET /v1/user/:id Should return one user', async () => {
71-
const res = await api('GET', `/api/v1/user/${createdId}`, auth);
70+
test('GET /users/:id Should return one user', async () => {
71+
const res = await api('GET', `/api/users/${createdId}`, auth);
7272
res.expectJson();
7373
res.expectStatusCode(200);
7474
res.expectData(userKeys);
@@ -79,9 +79,9 @@ describe('User', () => {
7979
expect(user.email).toBe(testUser.email);
8080
});
8181

82-
test('PUT /v1/user/:id Should update the user', async () => {
83-
const res = await api('PUT', `/api/v1/user/${createdId}`, {
84-
token: token,
82+
test('PUT /users/:id Should update the user', async () => {
83+
const res = await api('PUT', `/api/users/${createdId}`, {
84+
token,
8585
body: testUserUpdated
8686
});
8787
res.expectJson();
@@ -94,9 +94,9 @@ describe('User', () => {
9494
expect(user.email).toBe(testUserUpdated.email);
9595
});
9696

97-
test('PUT /v1/user/:id Should fail because we want to update the user with a invalid email', async () => {
98-
const res = await api('PUT', `/api/v1/user/${createdId}`, {
99-
token: token,
97+
test('PUT /users/:id Should fail because we want to update the user with a invalid email', async () => {
98+
const res = await api('PUT', `/api/users/${createdId}`, {
99+
token,
100100
body: {
101101
email: 'abc'
102102
}
@@ -105,28 +105,28 @@ describe('User', () => {
105105
res.expectStatusCode(400);
106106
});
107107

108-
test('DELETE /v1/user/:id Should delete the user', async () => {
109-
const res = await api('DELETE', `/api/v1/user/${createdId}`, auth);
108+
test('DELETE /users/:id Should delete the user', async () => {
109+
const res = await api('DELETE', `/api/users/${createdId}`, auth);
110110
res.expectStatusCode(200);
111111
});
112112

113113
/**
114114
* 404 - NotFound Testing
115115
*/
116-
test('GET /v1/user/:id Should return with a 404, because we just deleted the user', async () => {
117-
const res = await api('GET', `/api/v1/user/${createdId}`, auth);
116+
test('GET /users/:id Should return with a 404, because we just deleted the user', async () => {
117+
const res = await api('GET', `/api/users/${createdId}`, auth);
118118
res.expectJson();
119119
res.expectStatusCode(404);
120120
});
121121

122-
test('DELETE /v1/user/:id Should return with a 404, because we just deleted the user', async () => {
123-
const res = await api('DELETE', `/api/v1/user/${createdId}`, auth);
122+
test('DELETE /users/:id Should return with a 404, because we just deleted the user', async () => {
123+
const res = await api('DELETE', `/api/users/${createdId}`, auth);
124124
res.expectJson();
125125
res.expectStatusCode(404);
126126
});
127127

128-
test('PUT /v1/user/:id Should return with a 404, because we just deleted the user', async () => {
129-
const res = await api('PUT', `/api/v1/user/${createdId}`, auth);
128+
test('PUT /users/:id Should return with a 404, because we just deleted the user', async () => {
129+
const res = await api('PUT', `/api/users/${createdId}`, auth);
130130
res.expectJson();
131131
res.expectStatusCode(404);
132132
});

tsconfig.json

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,35 @@
11
{
22
"compilerOptions": {
3-
4-
/* Basic Options */
5-
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
6-
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
7-
"sourceMap": true, /* Generates corresponding '.map' file. */
8-
"outDir": "dist", /* Redirect output structure to the directory. */
9-
"importHelpers": true, /* Import emit helpers from 'tslib'. */
10-
11-
/* Strict Type-Checking Options */
12-
"strict": true, /* Enable all strict type-checking options. */
13-
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
14-
"strictNullChecks": true, /* Enable strict null checks. */
15-
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
16-
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
17-
18-
/* Additional Checks */
19-
"noUnusedLocals": true, /* Report errors on unused locals. */
20-
"noUnusedParameters": false, /* Report errors on unused parameters. */
21-
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
22-
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
23-
24-
/* Module Resolution Options */
25-
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
26-
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
27-
"paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
3+
"target": "es6",
4+
"module": "commonjs",
5+
"sourceMap": true,
6+
"outDir": "dist",
7+
"importHelpers": true,
8+
"strict": true,
9+
"noImplicitAny": false,
10+
"strictNullChecks": true,
11+
"noImplicitThis": true,
12+
"alwaysStrict": true,
13+
"noUnusedLocals": true,
14+
"noUnusedParameters": false,
15+
"noImplicitReturns": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"moduleResolution": "node",
18+
"baseUrl": "./",
19+
"paths": {
2820
"*": [
2921
"./node_modules/*",
3022
"./src/types/*"
3123
]
3224
},
33-
"rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
34-
"typeRoots": [ /* List of folders to include type definitions from. */
25+
"rootDirs": [],
26+
"typeRoots": [
3527
"./src/types"
3628
],
37-
"types": [ /* Type declaration files to be included in compilation. */
38-
],
39-
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
40-
41-
/* Experimental Options */
42-
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
43-
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
29+
"types": [],
30+
"allowSyntheticDefaultImports": true,
31+
"experimentalDecorators": true,
32+
"emitDecoratorMetadata": true
4433
},
4534
"include": [
4635
"./src/**/*"

0 commit comments

Comments
 (0)