-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(microservices): a few minor tweaks
- Loading branch information
1 parent
0a6853c
commit 8d08184
Showing
6 changed files
with
64 additions
and
62 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
...roservices/errors/invalid-grpc-package-definition-missing-package-definition.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception'; | ||
|
||
export class InvalidGrpcPackageDefinitionMissingPacakgeDefinitionException extends RuntimeException { | ||
export class InvalidGrpcPackageDefinitionMissingPackageDefinitionException extends RuntimeException { | ||
constructor() { | ||
super('protoPath or packageDefinition must be defined'); | ||
super( | ||
`Invalid gRPC configuration. protoPath or packageDefinition must be defined.`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,64 @@ | ||
import { expect } from 'chai'; | ||
import { getGrpcPackageDefinition } from '../../helpers/grpc-helpers'; | ||
import { InvalidGrpcPackageDefinitionMissingPackageDefinitionException } from '../../errors/invalid-grpc-package-definition-missing-package-definition.exception'; | ||
import { InvalidGrpcPackageDefinitionMutexException } from '../../errors/invalid-grpc-package-definition-mutex.exception'; | ||
import { InvalidGrpcPackageDefinitionMissingPacakgeDefinitionException } from '../../errors/invalid-grpc-package-definition-missing-package-definition.exception'; | ||
import { getGrpcPackageDefinition } from '../../helpers/grpc-helpers'; | ||
|
||
const grpcProtoLoaderPackage = { loadSync: (a, b) => 'withLoader' }; | ||
|
||
describe('getGrpcPackageDefinition', () => { | ||
it('missing both protoPath and packageDefinition', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.throw(InvalidGrpcPackageDefinitionMissingPacakgeDefinitionException); | ||
describe('when missing both protoPath and packageDefinition', () => { | ||
it('should throw InvalidGrpcPackageDefinitionMissingPackageDefinitionException', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.throw(InvalidGrpcPackageDefinitionMissingPackageDefinitionException); | ||
}); | ||
}); | ||
|
||
it('got both protoPath and packageDefinition', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
protoPath: 'some/path', | ||
packageDefinition: {}, | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.throw(InvalidGrpcPackageDefinitionMutexException); | ||
describe('when both protoPath and packageDefinition are defined', () => { | ||
it('should throw InvalidGrpcPackageDefinitionMutexException', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
protoPath: 'some/path', | ||
packageDefinition: {}, | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.throw(InvalidGrpcPackageDefinitionMutexException); | ||
}); | ||
}); | ||
|
||
it('success with protoPath', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
protoPath: 'some/path', | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.not.throw(Error); | ||
describe('when only protoPath is defined', () => { | ||
it('should not throw any exception', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
protoPath: 'some/path', | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.not.throw(Error); | ||
}); | ||
}); | ||
|
||
it('success with packageDef', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
packageDefinition: {}, | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.not.throw(Error); | ||
describe('when only packageDefinition is defined', () => { | ||
it('should not throw any exception', () => { | ||
expect(() => | ||
getGrpcPackageDefinition( | ||
{ | ||
package: 'somePackage', | ||
packageDefinition: {}, | ||
}, | ||
grpcProtoLoaderPackage, | ||
), | ||
).to.not.throw(Error); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters