-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: update libraries to support Nest 8 (#342)
- Upgrade NestJS dependencies - Refactored code to work with new rxjs 6 dependency - The RabbitMQ integration project now shares the same @nestjs/* packages and has fewer dependencies - Small cleanup and improvements around the code/JSDoc BREAKING CHANGE: Nest dependencies have been bumped from 6.x -> 8.x and we will no longer be supporting versions older than 8.x for future development Co-authored-by: Christophe BLIN <[email protected]> Co-authored-by: danocmx <[email protected]> Co-authored-by: Rodrigo <[email protected]> Co-authored-by: Jesse Carter <[email protected]>
- Loading branch information
1 parent
ef9c36f
commit de7cd35
Showing
41 changed files
with
7,206 additions
and
7,576 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
AmqpConnection, | ||
RabbitMQModule, | ||
RabbitSubscribe, | ||
} from '@golevelup/nestjs-rabbitmq'; | ||
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common'; | ||
import { INestApplication, Injectable } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
|
||
const validRmqTypeHandler = jest.fn(); | ||
|
||
const exchange = 'contextExchange'; | ||
const queue = 'contextQueue'; | ||
|
||
@Injectable() | ||
class TestInterceptor implements NestInterceptor { | ||
intercept(context: ExecutionContext, next: CallHandler<any>) { | ||
if ((context.getType() as string) !== 'rmq') { | ||
return next.handle(); | ||
} | ||
|
||
validRmqTypeHandler('invoked'); | ||
return next.handle(); | ||
} | ||
} | ||
|
||
@Injectable() | ||
class SubscribeService { | ||
@RabbitSubscribe({ | ||
exchange, | ||
routingKey: '#', | ||
queue, | ||
}) | ||
handleSubscribe(message: object) { | ||
// tslint:disable-next-line:no-console | ||
console.log(`RECEIVED MESSAGE: ${message}`); | ||
} | ||
} | ||
|
||
describe('RMQ Context in Global interceptor', () => { | ||
let app: INestApplication; | ||
let amqpConnection: AmqpConnection; | ||
|
||
const rabbitHost = | ||
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_HOST : 'localhost'; | ||
const rabbitPort = | ||
process.env.NODE_ENV === 'ci' ? process.env.RABBITMQ_PORT : '5672'; | ||
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:${rabbitPort}`; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture = await Test.createTestingModule({ | ||
providers: [SubscribeService, TestInterceptor], | ||
imports: [ | ||
RabbitMQModule.forRoot(RabbitMQModule, { | ||
exchanges: [ | ||
{ | ||
name: exchange, | ||
type: 'topic', | ||
}, | ||
], | ||
uri, | ||
connectionInitOptions: { wait: true, reject: true, timeout: 3000 }, | ||
}), | ||
], | ||
}).compile(); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
amqpConnection = app.get<AmqpConnection>(AmqpConnection); | ||
app.useGlobalInterceptors(new TestInterceptor()); | ||
await app.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it('should recognize as rmq context type and not the default (HTTP)', (done) => { | ||
amqpConnection.publish(exchange, 'x', `test-message`); | ||
expect.assertions(1); | ||
|
||
setTimeout(() => { | ||
expect(validRmqTypeHandler).toHaveBeenCalled(); | ||
done(); | ||
}, 100); | ||
}); | ||
}); |
Oops, something went wrong.