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

Commit

Permalink
feat: convert id to string (#180)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
wesleygrimes authored Sep 9, 2020
1 parent 85104c0 commit 8303e26
Show file tree
Hide file tree
Showing 95 changed files with 13,675 additions and 5,825 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/**
**/*.spec.ts
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
};
20 changes: 5 additions & 15 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ on:
- master

jobs:
test-8:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 8
- run: npm ci
- run: npm run test

test-10:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run test

Expand All @@ -32,18 +22,18 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run e2e

publish:
needs: [test-8, test-10, e2e]
needs: [test, e2e]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run build
- run: npx semantic-release
Expand Down
34 changes: 7 additions & 27 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,17 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run lint

test-8:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 8
- run: npm ci
- run: npm run test

test-10:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run test

Expand All @@ -42,7 +32,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run e2e

Expand All @@ -52,26 +42,16 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run format:verify

build-8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 8
- run: npm ci
- run: npm run build

build-10:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 12
- run: npm ci
- run: npm run build
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ npm-debug.log
# schematics
/schematics/**/*.js
/schematics/**/*.d.ts

# jest snapshots
__snapshots__/
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"trailingComma": "all",
"arrowParens": "always",
"singleQuote": true
}
}
9 changes: 0 additions & 9 deletions e2e/jest.config.js

This file was deleted.

14 changes: 0 additions & 14 deletions e2e/test-app/src/customer/customer.controller.ts

This file was deleted.

33 changes: 0 additions & 33 deletions e2e/test-app/src/product/product.controller.ts

This file was deleted.

8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module.exports = {
lines: 80,
},
},
"testPathIgnorePatterns": [
"<rootDir>/build/",
"<rootDir>/node_modules/",
"<rootDir>/e2e/"
testPathIgnorePatterns: [
'<rootDir>/build/',
'<rootDir>/node_modules/',
'<rootDir>/tests/',
],
};
1 change: 1 addition & 0 deletions lib/common/in-memory-db.decorators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Inject } from '@nestjs/common';
import { getInMemoryDBServiceToken } from './in-memory-db.utils';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const InjectInMemoryDBService = (featureName: string) =>
Inject(getInMemoryDBServiceToken(featureName));
2 changes: 1 addition & 1 deletion lib/common/in-memory-db.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IN_MEMORY_DB_SERVICE } from './in-memory-db.constants';

export function getInMemoryDBServiceToken(featureName?: string) {
export function getInMemoryDBServiceToken(featureName?: string): string {
return featureName && featureName !== IN_MEMORY_DB_SERVICE
? `${featureName}${IN_MEMORY_DB_SERVICE}`
: IN_MEMORY_DB_SERVICE;
Expand Down
22 changes: 11 additions & 11 deletions lib/controllers/in-memory-db-async.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('In Memory DB Async Controller', () => {
let service: InMemoryDBService<TestEntity>;

const sampleRecords: TestEntity[] = [
{ id: 1, someField: 'AAA' },
{ id: 2, someField: 'BBB' },
{ id: 3, someField: 'CCC' },
{ id: '1', someField: 'AAA' },
{ id: '2', someField: 'BBB' },
{ id: '3', someField: 'CCC' },
];

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

test('should call service getAsync spy when given valid id', () => {
// act
controller.get(1);
controller.get('1');
// assert
expect(spy).toHaveBeenCalledWith(1);
expect(spy).toHaveBeenCalledWith('1');
});
});

describe('getMany', () => {
test('should call service getManyAsync spy when given list of ids', () => {
// arrange
const spy = spyOn(service, 'getManyAsync');
const testEntityMock = [1, 2, 3];
const testEntityMock = ['1', '2', '3'];
// act
controller.getMany(testEntityMock);
// assert
Expand Down Expand Up @@ -96,9 +96,9 @@ describe('In Memory DB Async Controller', () => {
// arrange
const testEntityMock = { someField: 'DDD' };
// act
controller.update(1, testEntityMock);
controller.update('1', testEntityMock);
// assert
expect(spy).toHaveBeenCalledWith({ id: 1, ...testEntityMock });
expect(spy).toHaveBeenCalledWith({ id: '1', ...testEntityMock });
});
});

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

test('should call deleteAsync when give a valid id', () => {
// act
controller.delete(1);
controller.delete('1');
// assert
expect(spy).toHaveBeenCalledWith(1);
expect(spy).toHaveBeenCalledWith('1');
});
});

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

test('should call deleteManyAsync when given valid ids list', () => {
// arrange
const testEntityMock = [1, 2, 3];
const testEntityMock = ['1', '2', '3'];
// act
controller.deleteMany(testEntityMock);
// assert
Expand Down
24 changes: 12 additions & 12 deletions lib/controllers/in-memory-db.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('In Memory DB Controller', () => {
let service: InMemoryDBService<TestEntity>;

const sampleRecords: TestEntity[] = [
{ id: 1, someField: 'AAA' },
{ id: 2, someField: 'BBB' },
{ id: 3, someField: 'CCC' },
{ id: '1', someField: 'AAA' },
{ id: '2', someField: 'BBB' },
{ id: '3', someField: 'CCC' },
];

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

test('should call service get spy when given valid id', () => {
// act
controller.get(1);
controller.get('1');
// assert
expect(spy).toHaveBeenCalledWith(1);
expect(spy).toHaveBeenCalledWith('1');
});
});

describe('getMany', () => {
test('should call service getMany spy when given list of ids', () => {
// arrange
const spy = spyOn(service, 'getMany');
const testEntityMock = [1, 2, 3];
const testEntityMock = ['1', '2', '3'];
// act
controller.getMany(testEntityMock);
// assert
Expand Down Expand Up @@ -96,9 +96,9 @@ describe('In Memory DB Controller', () => {
// arrange
const testEntityMock = { someField: 'DDD' };
// act
controller.update(1, testEntityMock);
controller.update('1', testEntityMock);
// assert
expect(spy).toHaveBeenCalledWith({ id: 1, ...testEntityMock });
expect(spy).toHaveBeenCalledWith({ id: '1', ...testEntityMock });
});
});

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

test('should call delete when give a valid id', () => {
test('should call delete when given a valid id', () => {
// act
controller.delete(1);
controller.delete('1');
// assert
expect(spy).toHaveBeenCalledWith(1);
expect(spy).toHaveBeenCalledWith('1');
});
});

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

test('should call delete many when given valid ids list', () => {
// arrange
const testEntityMock = [1, 2, 3];
const testEntityMock = ['1', '2', '3'];
// act
controller.deleteMany(testEntityMock);
// assert
Expand Down
4 changes: 2 additions & 2 deletions lib/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './in-memory-db-async.controller';
export * from './in-memory-db.controller';
export { InMemoryDBEntityAsyncController } from './in-memory-db-async.controller';
export { InMemoryDBEntityController } from './in-memory-db.controller';
Loading

0 comments on commit 8303e26

Please sign in to comment.