@soapjs/integr8-nestjs
v1.0.3
Published
[](https://badge.fury.io/js/@soapjs%2Fintegr8-nestjs) [](https://opensource.org/licenses/MIT)
Downloads
6
Maintainers
Readme
@soapjs/integr8-nestjs
Runtime method patching for NestJS applications. Override any service method AFTER application startup via HTTP API - perfect for integration testing with @soapjs/integr8.
Key Features
- Runtime Override - Patch methods after app starts (no DI restart needed)
- HTTP API - Send code as strings via REST endpoints
- VM Sandbox - Secure code execution (no eval)
- Auto-Discovery - Wraps all providers automatically
- Factory Support - Replace entire providers
- Fully Tested - 124 tests including 26 E2E
Installation
npm install @soapjs/integr8-nestjs
npm install @nestjs/core @nestjs/common @nestjs/platform-expressQuick Start
1. Enable in Your App
// app.module.ts
import { TestOverridesModule } from '@soapjs/integr8-nestjs';
const testModules = TestOverridesModule.isEnabled()
? [TestOverridesModule]
: [];
@Module({
imports: [...testModules, YourOtherModules],
})
export class AppModule {}2. Set Environment
export INTEGR8_OVERRIDES_ENABLED=1
export INTEGR8_OVERRIDES_TOKEN=your-secret-token3. Start & Override
# Start your app
npm start
# Override a method via HTTP
curl -X POST http://localhost:3000/__integr8__/override/UsersService \
-H "Authorization: Bearer your-secret-token" \
-H "Content-Type: application/json" \
-d '{
"methods": {
"findAll": {
"type": "fn",
"body": "return [{ id: 999, name: \"Mocked User\" }];"
}
}
}'
# Test it
curl http://localhost:3000/users
# Returns: [{"id":999,"name":"Mocked User"}]📖 Examples
Override Single Method
POST /__integr8__/override/UsersService
{
"methods": {
"findOne": {
"type": "fn",
"args": ["id"],
"body": "return { id, name: \"User \" + id };"
}
}
}Replace Entire Provider (Factory)
POST /__integr8__/override/UsersService
{
"factory": {
"body": "return { findAll: () => [], findOne: (id) => null };"
}
}Reset Override
POST /__integr8__/override/UsersService
{ "reset": true }
# Or reset all
POST /__integr8__/override/reset-allList Active Overrides
GET /__integr8__/overrides🧪 Using in Tests
import axios from 'axios';
const api = axios.create({
baseURL: 'http://localhost:3000',
headers: { 'Authorization': 'Bearer your-secret-token' }
});
describe('Users API', () => {
beforeEach(async () => {
// Apply override
await api.post('/__integr8__/override/UsersService', {
methods: {
findAll: {
type: 'fn',
body: 'return [{ id: 1, name: "Test User" }];'
}
}
});
});
afterEach(async () => {
// Reset
await api.post('/__integr8__/override/reset-all');
});
it('returns mocked data', async () => {
const res = await axios.get('http://localhost:3000/users');
expect(res.data[0].name).toBe('Test User');
});
});Security
⚠️ Only for test environments!
Protection layers:
- Environment gate:
INTEGR8_OVERRIDES_ENABLED=1 - Bearer token auth:
INTEGR8_OVERRIDES_TOKEN - VM sandbox: No access to require/process
- Execution timeout: 5000ms
Documentation
- TestOverridesModule Guide - Complete documentation
- Examples - Working code samples
License
MIT © Radoslaw Kamysz
Related
- @soapjs/integr8 - Core testing framework
- @soapjs/soap - SOAP framework
Made with ❤️ by the SoapJS team
