Skip to content
This repository was archived by the owner on Feb 7, 2021. It is now read-only.

Commit 8303e26

Browse files
authored
feat: convert id to string (#180)
* feat: convert id to string BREAKING CHANGE: InMemoryDBEntity now uses string for id V1* versions of service, controller, module, entity have been provided for backwards compatibility. Please update your imports if you wish to continue to use number as id.
1 parent 85104c0 commit 8303e26

File tree

95 files changed

+13675
-5825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+13675
-5825
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests/**
2+
**/*.spec.ts

.eslintrc.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
module.exports = {
3+
parser: '@typescript-eslint/parser',
4+
parserOptions: {
5+
project: 'tsconfig.json',
6+
sourceType: 'module',
7+
},
8+
plugins: ['@typescript-eslint/eslint-plugin'],
9+
extends: [
10+
'plugin:@typescript-eslint/eslint-recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
'prettier',
13+
'prettier/@typescript-eslint',
14+
],
15+
root: true,
16+
env: {
17+
node: true,
18+
jest: true,
19+
},
20+
rules: {
21+
'@typescript-eslint/interface-name-prefix': 'off',
22+
'@typescript-eslint/explicit-function-return-type': 'off',
23+
'@typescript-eslint/no-explicit-any': 'off',
24+
'@typescript-eslint/no-use-before-define': 'off',
25+
'@typescript-eslint/no-non-null-assertion': 'off',
26+
},
27+
};

.github/workflows/master.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@ on:
66
- master
77

88
jobs:
9-
test-8:
9+
test:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v1
1313
- uses: actions/setup-node@v1
1414
with:
15-
node-version: 8
16-
- run: npm ci
17-
- run: npm run test
18-
19-
test-10:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: actions/checkout@v1
23-
- uses: actions/setup-node@v1
24-
with:
25-
node-version: 10
15+
node-version: 12
2616
- run: npm ci
2717
- run: npm run test
2818

@@ -32,18 +22,18 @@ jobs:
3222
- uses: actions/checkout@v1
3323
- uses: actions/setup-node@v1
3424
with:
35-
node-version: 10
25+
node-version: 12
3626
- run: npm ci
3727
- run: npm run e2e
3828

3929
publish:
40-
needs: [test-8, test-10, e2e]
30+
needs: [test, e2e]
4131
runs-on: ubuntu-latest
4232
steps:
4333
- uses: actions/checkout@v1
4434
- uses: actions/setup-node@v1
4535
with:
46-
node-version: 10
36+
node-version: 12
4737
- run: npm ci
4838
- run: npm run build
4939
- run: npx semantic-release

.github/workflows/pull-requests.yml

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,17 @@ jobs:
1212
- uses: actions/checkout@v1
1313
- uses: actions/setup-node@v1
1414
with:
15-
node-version: 10
15+
node-version: 12
1616
- run: npm ci
1717
- run: npm run lint
1818

19-
test-8:
19+
test:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v1
2323
- uses: actions/setup-node@v1
2424
with:
25-
node-version: 8
26-
- run: npm ci
27-
- run: npm run test
28-
29-
test-10:
30-
runs-on: ubuntu-latest
31-
steps:
32-
- uses: actions/checkout@v1
33-
- uses: actions/setup-node@v1
34-
with:
35-
node-version: 10
25+
node-version: 12
3626
- run: npm ci
3727
- run: npm run test
3828

@@ -42,7 +32,7 @@ jobs:
4232
- uses: actions/checkout@v1
4333
- uses: actions/setup-node@v1
4434
with:
45-
node-version: 10
35+
node-version: 12
4636
- run: npm ci
4737
- run: npm run e2e
4838

@@ -52,26 +42,16 @@ jobs:
5242
- uses: actions/checkout@v1
5343
- uses: actions/setup-node@v1
5444
with:
55-
node-version: 10
45+
node-version: 12
5646
- run: npm ci
5747
- run: npm run format:verify
5848

59-
build-8:
60-
runs-on: ubuntu-latest
61-
steps:
62-
- uses: actions/checkout@v1
63-
- uses: actions/setup-node@v1
64-
with:
65-
node-version: 8
66-
- run: npm ci
67-
- run: npm run build
68-
69-
build-10:
49+
build:
7050
runs-on: ubuntu-latest
7151
steps:
7252
- uses: actions/checkout@v1
7353
- uses: actions/setup-node@v1
7454
with:
75-
node-version: 10
55+
node-version: 12
7656
- run: npm ci
7757
- run: npm run build

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ npm-debug.log
2121
# schematics
2222
/schematics/**/*.js
2323
/schematics/**/*.d.ts
24-
25-
# jest snapshots
26-
__snapshots__/

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"trailingComma": "all",
3+
"arrowParens": "always",
34
"singleQuote": true
4-
}
5+
}

e2e/jest.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

e2e/test-app/src/customer/customer.controller.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

e2e/test-app/src/product/product.controller.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ module.exports = {
2020
lines: 80,
2121
},
2222
},
23-
"testPathIgnorePatterns": [
24-
"<rootDir>/build/",
25-
"<rootDir>/node_modules/",
26-
"<rootDir>/e2e/"
23+
testPathIgnorePatterns: [
24+
'<rootDir>/build/',
25+
'<rootDir>/node_modules/',
26+
'<rootDir>/tests/',
2727
],
2828
};

lib/common/in-memory-db.decorators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Inject } from '@nestjs/common';
22
import { getInMemoryDBServiceToken } from './in-memory-db.utils';
33

4+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
45
export const InjectInMemoryDBService = (featureName: string) =>
56
Inject(getInMemoryDBServiceToken(featureName));

lib/common/in-memory-db.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IN_MEMORY_DB_SERVICE } from './in-memory-db.constants';
22

3-
export function getInMemoryDBServiceToken(featureName?: string) {
3+
export function getInMemoryDBServiceToken(featureName?: string): string {
44
return featureName && featureName !== IN_MEMORY_DB_SERVICE
55
? `${featureName}${IN_MEMORY_DB_SERVICE}`
66
: IN_MEMORY_DB_SERVICE;

lib/controllers/in-memory-db-async.controller.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ describe('In Memory DB Async Controller', () => {
1212
let service: InMemoryDBService<TestEntity>;
1313

1414
const sampleRecords: TestEntity[] = [
15-
{ id: 1, someField: 'AAA' },
16-
{ id: 2, someField: 'BBB' },
17-
{ id: 3, someField: 'CCC' },
15+
{ id: '1', someField: 'AAA' },
16+
{ id: '2', someField: 'BBB' },
17+
{ id: '3', someField: 'CCC' },
1818
];
1919

2020
class MockController extends InMemoryDBEntityAsyncController<TestEntity> {
@@ -37,17 +37,17 @@ describe('In Memory DB Async Controller', () => {
3737

3838
test('should call service getAsync spy when given valid id', () => {
3939
// act
40-
controller.get(1);
40+
controller.get('1');
4141
// assert
42-
expect(spy).toHaveBeenCalledWith(1);
42+
expect(spy).toHaveBeenCalledWith('1');
4343
});
4444
});
4545

4646
describe('getMany', () => {
4747
test('should call service getManyAsync spy when given list of ids', () => {
4848
// arrange
4949
const spy = spyOn(service, 'getManyAsync');
50-
const testEntityMock = [1, 2, 3];
50+
const testEntityMock = ['1', '2', '3'];
5151
// act
5252
controller.getMany(testEntityMock);
5353
// assert
@@ -96,9 +96,9 @@ describe('In Memory DB Async Controller', () => {
9696
// arrange
9797
const testEntityMock = { someField: 'DDD' };
9898
// act
99-
controller.update(1, testEntityMock);
99+
controller.update('1', testEntityMock);
100100
// assert
101-
expect(spy).toHaveBeenCalledWith({ id: 1, ...testEntityMock });
101+
expect(spy).toHaveBeenCalledWith({ id: '1', ...testEntityMock });
102102
});
103103
});
104104

@@ -128,9 +128,9 @@ describe('In Memory DB Async Controller', () => {
128128

129129
test('should call deleteAsync when give a valid id', () => {
130130
// act
131-
controller.delete(1);
131+
controller.delete('1');
132132
// assert
133-
expect(spy).toHaveBeenCalledWith(1);
133+
expect(spy).toHaveBeenCalledWith('1');
134134
});
135135
});
136136

@@ -143,7 +143,7 @@ describe('In Memory DB Async Controller', () => {
143143

144144
test('should call deleteManyAsync when given valid ids list', () => {
145145
// arrange
146-
const testEntityMock = [1, 2, 3];
146+
const testEntityMock = ['1', '2', '3'];
147147
// act
148148
controller.deleteMany(testEntityMock);
149149
// assert

lib/controllers/in-memory-db.controller.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ describe('In Memory DB Controller', () => {
1212
let service: InMemoryDBService<TestEntity>;
1313

1414
const sampleRecords: TestEntity[] = [
15-
{ id: 1, someField: 'AAA' },
16-
{ id: 2, someField: 'BBB' },
17-
{ id: 3, someField: 'CCC' },
15+
{ id: '1', someField: 'AAA' },
16+
{ id: '2', someField: 'BBB' },
17+
{ id: '3', someField: 'CCC' },
1818
];
1919

2020
class MockController extends InMemoryDBEntityController<TestEntity> {
@@ -37,17 +37,17 @@ describe('In Memory DB Controller', () => {
3737

3838
test('should call service get spy when given valid id', () => {
3939
// act
40-
controller.get(1);
40+
controller.get('1');
4141
// assert
42-
expect(spy).toHaveBeenCalledWith(1);
42+
expect(spy).toHaveBeenCalledWith('1');
4343
});
4444
});
4545

4646
describe('getMany', () => {
4747
test('should call service getMany spy when given list of ids', () => {
4848
// arrange
4949
const spy = spyOn(service, 'getMany');
50-
const testEntityMock = [1, 2, 3];
50+
const testEntityMock = ['1', '2', '3'];
5151
// act
5252
controller.getMany(testEntityMock);
5353
// assert
@@ -96,9 +96,9 @@ describe('In Memory DB Controller', () => {
9696
// arrange
9797
const testEntityMock = { someField: 'DDD' };
9898
// act
99-
controller.update(1, testEntityMock);
99+
controller.update('1', testEntityMock);
100100
// assert
101-
expect(spy).toHaveBeenCalledWith({ id: 1, ...testEntityMock });
101+
expect(spy).toHaveBeenCalledWith({ id: '1', ...testEntityMock });
102102
});
103103
});
104104

@@ -126,11 +126,11 @@ describe('In Memory DB Controller', () => {
126126
spy = jest.spyOn(service, 'delete');
127127
});
128128

129-
test('should call delete when give a valid id', () => {
129+
test('should call delete when given a valid id', () => {
130130
// act
131-
controller.delete(1);
131+
controller.delete('1');
132132
// assert
133-
expect(spy).toHaveBeenCalledWith(1);
133+
expect(spy).toHaveBeenCalledWith('1');
134134
});
135135
});
136136

@@ -143,7 +143,7 @@ describe('In Memory DB Controller', () => {
143143

144144
test('should call delete many when given valid ids list', () => {
145145
// arrange
146-
const testEntityMock = [1, 2, 3];
146+
const testEntityMock = ['1', '2', '3'];
147147
// act
148148
controller.deleteMany(testEntityMock);
149149
// assert

lib/controllers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './in-memory-db-async.controller';
2-
export * from './in-memory-db.controller';
1+
export { InMemoryDBEntityAsyncController } from './in-memory-db-async.controller';
2+
export { InMemoryDBEntityController } from './in-memory-db.controller';

0 commit comments

Comments
 (0)