From 5cee35090fdaa103760e8c3820bd8ecba3dff234 Mon Sep 17 00:00:00 2001 From: KHYehor Date: Sun, 13 Oct 2024 14:33:55 +0300 Subject: [PATCH] feat: update readme description --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 34a6ebf..875d075 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@ - [License](#license) ## Description - -This repository demonstrates how to effectively set up and execute integration tests for a Node.js application without using mocks inside **node.app:** - +Typically, when it comes to setting up integration tests and working with external dependencies, an approach is used where components are simulated through mocks. This means that database responses or requests via `axios` are artificially replaced with pre-defined results directly in the code. However, this repository demonstrates an alternative approach, where the tests interact with real external services, allowing for more accurate and comprehensive end-to-end validation of the application's functionality. ```typescript const moduleRef: TestingModule = await Test.createTestingModule({ controllers: [UserController], @@ -27,8 +25,7 @@ const moduleRef: TestingModule = await Test.createTestingModule({ userController = moduleRef.get(UserController); ``` - -Instead of simulating components in code like mocking what database or axios returns, the approach focuses on testing real interactions between outside services, ensuring more accurate, end-to-end validation of your application’s behavior. If you think about how your app should interact with external client or provider api without mocks of axios **(example below)**: +Rather than simulating components in code by mocking responses from the database or axios, this approach focuses on testing real interactions with external services. This ensures more accurate, end-to-end validation of your application's behavior. If you want to test how your app interacts with external client or provider APIs without mocking tools like axios, consider the following example: ```typescript import axios from 'axios'; // Set up an interceptor to mock requests @@ -45,7 +42,7 @@ axios.get('https://api.example.com') .then(response => console.log(response.data)) // Logs 'mocked success' .catch(error => console.error(error)); ``` -The answer is [mockserver](https://www.mock-server.com). I hope you know all possible scenarios and responses the provider api can return. You define a schema with info of expected request and response for it, like return this response if you catch this request: +The solution for more realistic testing is using [mockserver](https://www.mock-server.com). This approach allows you to define expected request-response schemas, ensuring that your app reacts correctly to all possible scenarios from the provider API. For example, you can specify: ```json { "httpRequest": { @@ -57,7 +54,7 @@ The answer is [mockserver](https://www.mock-server.com). I hope you know all pos } } ``` -The schema can be more detailed, it depends on your needs. Mocking DB or publishing events to message brokers is easier and cause no problems. In general node.js code wasn't modified or changed (except environmental variables for api calls). Now your scenarios are tested and you can be confident about identical behavior on production. +The schema can be more detailed based on your needs. Mocking the database or handling events in message brokers is simpler and typically hassle-free. The core Node.js code remains unchanged (apart from adjusting environment variables for API calls). Now your scenarios are thoroughly tested, giving you confidence that the behavior will be consistent in production. ## Key Features - **No Code Mocking: Focuses on testing real integrations, without relying on mocks or stubs in node.js.** - **Production-like Testing: Verifies how the app interacts with external services in a more realistic, production-like environment.**